Pages

Tuesday 22 March 2011

Java2word Templates

Now you can use Templates with Java2word!

Take a look at the wiki page: https://code.google.com/p/java2word/wiki/TemplatesWithJava2word

It is not the most advanced solution but gets the job done!



https://code.google.com/p/java2word/



Leonardo Correa
coding for fun...

8 comments:

  1. Hi, i've been trying to find a simple solution to merge word docs in java for some time.
    So i was happy to find your project.
    Tested it, merging works fine but the original text form my Word document gets corrupted ...
    Accents, punctuation etc are all transformed into ugly characters.
    Is there a way to solve this ?

    ReplyDelete
  2. Lets get it done!
    If you don't mind, pls open an issue in the project paga in google, attach your template (if you have no issues about being public) and I 'll have a look at your problem.

    If your template is private, the other option would be send to my email address and we keep this conversation offline.

    The other option is you change some private values of your template (or create a dummy one) and attach it to the issue.

    if you open the issue, pls inform your OS, if you use MS Word or Open Office...

    cheers

    Leonardo

    ReplyDelete
  3. New issue added !

    ReplyDelete
  4. Hi Leonardo.

    I want to use your java2doc. But it has a problem with cyrillic text.

    ReplyDelete
  5. Are you having problems with templates or the actual java2word?

    can you pls create an issue in the project page, adding your code example and we have a look.
    Write the encoding that best suits cyrillic text.


    thanks
    Leonardo

    ReplyDelete
  6. without templates. just


    Code works fine:
    IDocument myDoc = new Document2004();
    myDoc.addEle(Paragraph.with("english text").create());

    Code prodeces a file that could not be opened:
    IDocument myDoc = new Document2004();
    myDoc.addEle(Paragraph.with("русский текст").create());

    ReplyDelete
  7. also when i tried:

    myDoc.addEle(new word.w2004.elements.Image("1.png",ImageLocation.FULL_LOCAL_PATH));

    It insert image but with 133% scale in properties of image object in word. I want 100%.

    ReplyDelete
  8. Hi Leo,

    I'm trying to add data to word document in my automation using JavatoWord API and word is getting corrupted when i append the data.

    Any help on it is highly appreciated!!!!!!!!!!!!!!!!!

    import java.io.*;
    import java.text.*;
    import java.util.*;
    import word.api.interfaces.IDocument;
    import word.w2004.Document2004;
    import word.w2004.Document2004.Encoding;
    import word.w2004.elements.BreakLine;
    import word.w2004.elements.Image;
    import word.w2004.elements.ImageLocation;
    import word.w2004.elements.Paragraph;
    import word.w2004.elements.ParagraphPiece;

    public void AppendtoWord() throws Exception

    {
    String strScrShotsFile = "C:/Test.doc/";

    String strScrShotsFile = "C:/test.png";

    boolean exists = (fileScrShotsFile).exists();

    PrintWriter writer = null;

    myDoc = new Document2004();

    if (!exists)

    {

    try {

    writer = new PrintWriter(fileScrShotsFile);
    myDoc.encoding(Encoding.UTF_8);
    myDoc.company("Comp Inc");
    myDoc.author("Test Automation Teams");
    myDoc.title("Application Automation Test Results");
    myDoc.subject("Screen Shots");
    myDoc.setPageOrientationLandscape();
    myDoc.addEle(BreakLine.times(2).create());// Document Header and Footer
    myDoc.addEle(BreakLine.times(2).create());
    myDoc.getHeader().addEle(Paragraph.withPieces(ParagraphPiece.with("Screenshots for test case: "), ParagraphPiece.with( "Test" ).withStyle().bold().create()).create());
    myDoc.getFooter().addEle(Paragraph.with(strScrShotsFile).create()); // Images
    myDoc.addEle(BreakLine.times(1).create());
    myDoc.addEle(Paragraph.with("Test").withStyle().bgColor("RED").create());

    writer.println(myDoc.getContent());

    }
    catch (FileNotFoundException e) {

    e.printStackTrace();

    }
    finally
    {
    writer.close();

    }
    }

    else
    {
    PrintWriter writer1= null;

    try {

    writer1 = new PrintWriter(new FileWriter(fileScrShotsFile,true)); }
    catch (FileNotFoundException e) {

    e.printStackTrace();

    } myDoc.addEle(Paragraph.with("This is Important").withStyle().bgColor("RED").create());
    writer1.println(myDoc.getContent
    ());

    finally {
    writer1.close();
    }

    }

    8 June 2011 4:57 PM

    ReplyDelete