Pledgie



if you think this library has been useful, feel free to give any help. Don't be shy.


Click here to lend your support to: Java2word, coding for fun! and make a donation at www.pledgie.com !

All-in-one example

project moved to: https://github.com/leonardoanalista/java2word

27 comments:

  1. does not work for me. word can't open it. i am using the latest version.

    ReplyDelete
    Replies
    1. couldn't add image into doc ,am using xstream jar file also

      Delete
  2. All look nice in MS Office 2007 (but LibreOffice can't read document), You've made the great work. thanks!!!!

    ReplyDelete
    Replies
    1. thanks mate.
      LibreOffice has got some issues to open it. Someone has found out that if you rename the file to .xml Open/Libre office can open the file.

      cheers
      Leonardo Correa

      Delete
  3. Hi Leonardo

    Great work...
    I tried to work with various API's but this one is Awesome.
    Some Doubts:
    1. While trying to run this sample the word file which got generated failed to open due to presence of some characters like '&', 'é'. Is there any escape sequence I could use.
    2. Is there any way to create templates and then replace placeholders in template using JAVA.

    Thanks

    ReplyDelete
  4. Hi Leonardo!

    Is there anyway to add page numbering to the header?

    Thanks,

    Nick

    ReplyDelete
    Replies
    1. page number is displayed on footer by default. It is not currently possible to specify the location between header and footer. If you really need it on the header instead of footer, this would require some sort of work around or new implementation. Remember it is all XML and you can inspect it, change it and generate the doc again.

      Delete
  5. Can't get TestUtils.createLocalDoc(myDoc.getContent()); to work
    FileNotFound Exception

    Also I can't read any of your methods in your classes it just says compiled code.
    Is this to protect your work or am I missing something?

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Hello Leonardo,

    Is there any way to read .doc & .docx files as im trying it with POI its getting the text for me it also gets me special characters.Is there any chance to read the .doc files completely and clearly without any special characters

    ReplyDelete
    Replies
    1. can't read docx at all. The only way to read doc is by using the java2word template solution described here: http://java2word.blogspot.com.au/p/ms-word-templates-with-java2word.html

      cheers Leonardo Correa

      Delete
  8. I am getting the below error when I am trying to insert an image from my local drive.

    Exception in thread "main" java.lang.NoClassDefFoundError: com/thoughtworks/xstream/core/util/Base64Encoder
    at word.utils.ImageUtils.getImageHexaBase64(ImageUtils.java:26)
    at word.w2004.elements.Image.getContent(Image.java:104)
    at word.w2004.Body2004.addEle(Body2004.java:16)
    at word.w2004.Document2004.addEle(Document2004.java:110)
    at javatoword.JavaToWord.main(JavaToWord.java:87)
    Java Result: 1

    ReplyDelete
    Replies
    1. http://java2word.blogspot.com.au/p/documentation.html#Dependencies
      missing xtream.jar. Get it from the downloads page
      cheers Leo

      Delete
  9. Thanks for this. It's working now.

    But I seem to have run into another problem. Is there any way to auto fit the images to table cell? The problem is that the images that are being inserted are of different sizes and sometimes the images are completely shown in the cells. Also, I don't want the user to resize each image on its own.

    If I set a common height and width to all the image through the code, then some images are not even visible then.

    Is there a solution to this?

    Thanks,

    ReplyDelete
  10. Hi,

    This is the best API i have seen for creating Word document easily from Java program. 1. is there any possibility of adjusting table cells like alignment to left, center, right.
    2. can i hide the border in a table where there is no data in a cell. example if a row has got 5 columns. if i fill data only for 2 columns. the rest of the 3 columns should not display borders.

    thanks
    david

    ReplyDelete
  11. How to i add multiple tables, reading data from xml file?
    Do we have to insert multiple placeholders?

    ReplyDelete
  12. Thank you for the code but I have 1 doubt
    I added an Image and it added fine but now I want to attach a String which contains a whole HTML template and whenever I try to add it my word DOC doesn't open.
    Can you please help me with it.

    ReplyDelete
  13. Thank you for the code and the library ;-)

    I have problem with images : they don't displayed correctly !?
    Instead of that, I had caracters like :
    Uklv3JkcUK1B8PIFxQABWAQMGNOjaIEMDCRkcjM1gdkOGD2pjwNixQ ...

    Remark to nick.broadhurst : the footer and the header are well displayed for me
    when I rename the extension to ".docx".

    The table is well displayed; but I don't know if we can resize (width, heigth) of
    the columns, table ?
    can we set invisible the borders ?

    Other questions :
    * can we add a bullet list of lines ?
    * can we add a table in a cell of another table ?
    * can we add a document in a celle of a table ?
    ....

    Thanks again :)

    Mourad

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Thank you for the code and the library :-)


    I have problem when working with tables,
    The table is well displayed; but can we resize (width, heigth) of
    the table columns and can set the table fits in one page i.e. not split into two pages.

    Thanks :)

    Ravi

    ReplyDelete
  16. Thank you for the Library. Your work was awesome.

    ReplyDelete
  17. Hi,
    it is very helpful . I have one issue with heading alignment.I got error as :' No such property: Align for class'

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Guys please help me.

    I am getting this error.
    java.io.FileNotFoundException: build.properties (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.(Unknown Source)
    at java.io.FileInputStream.(Unknown Source)
    at word.utils.TestUtils.createLocalDocument(TestUtils.java:45)
    at word.utils.TestUtils.createLocalDoc(TestUtils.java:30)
    at Demo_package.Java2WordTest.main(Java2WordTest.java:45)
    java.io.FileNotFoundException: null\Java2word_allInOne.doc (The system cannot find the path specified)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.(Unknown Source)
    at java.io.FileOutputStream.(Unknown Source)
    at java.io.PrintWriter.(Unknown Source)
    at word.utils.TestUtils.createLocalDocument(TestUtils.java:58)
    at word.utils.TestUtils.createLocalDoc(TestUtils.java:30)
    at Demo_package.Java2WordTest.main(Java2WordTest.java:45)
    Exception in thread "main" java.lang.NullPointerException
    at word.utils.TestUtils.createLocalDocument(TestUtils.java:64)
    at word.utils.TestUtils.createLocalDoc(TestUtils.java:30)
    at Demo_package.Java2WordTest.main(Java2WordTest.java:45)

    And I am unable to find the document.

    ReplyDelete
    Replies
    1. create your own build.properties file including line: tmp.docs.dir=

      Delete
  20. Please help me.
    I want to change the table location, but I don't know how.
    In addition, I want to know whether there is a method to be generated from the right side when you create tables.

    ReplyDelete
  21. Hi Leonardo. I am using this library java2word-3.3.jar on Android Project and return this error:

    java.io.FileNotFoundException: /build.properties: open failed: ENOENT (No such file or directory)

    Can you help me please?

    Thanks

    ReplyDelete