Results 1 to 5 of 5
  1. #1
    devday is offline Member
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Lightbulb writing word document using poi hwpf

    Hi friends,
    i need to write into word document from the java.For this am using the poi hwpf api.On executing the following sample code.am getting the error like:
    Exception in thread "main" java.io.IOException: Unable to read entire header; -1 bytes read; expected 512 bytes
    at org.apache.poi.poifs.storage.HeaderBlockReader.<in it>(HeaderBlockReader.java:78)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<i nit>(POIFSFileSystem.java:83).

    can anyone tell me how to set header to resolve this problem.

    <code>

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import org.apache.poi.hwpf.HWPFDocument;
    import org.apache.poi.hwpf.usermodel.CharacterRun;
    import org.apache.poi.hwpf.usermodel.Range;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;

    public class Main {

    public static void main(String[] args) throws IOException {
    File file = new File("sample1.doc");

    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
    HWPFDocument doc = new HWPFDocument(fs);
    Range range = doc.getRange();
    CharacterRun run = range.insertAfter("Hello World!!! HAHAHAHAHA I DID IT!!!");
    run.setBold(true);
    run.setItalic(true);
    run.setCapitalized(true);
    OutputStream out = new FileOutputStream(new File("sample2.doc"));
    doc.write(out);
    out.flush();
    out.close();
    }
    }
    </code>

  2. #2
    adnanakcan is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    selam millet bana javadaki tabloyu ms word programına yazan modül lazım her kim biliyorsa bu işi yazsın buraya kaç gündür bu işle uğraşıyom help me!

  3. #3
    adnanakcan is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    hi! how to wtite jtable to ms word program i try this but i didn't help me.

  4. #4
    nagaradjanev is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default You can try the following code

    import java.io.*;
    import org.apache.poi.hwpf.usermodel.*;
    import org.apache.poi.hwpf.*;
    import org.apache.poi.poifs.filesystem.*;

    public class WriteDoc {

    public static void main(String[] args) throws IOException {
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("test1.doc"));
    HWPFDocument doc = new HWPFDocument(fs);

    Range range = doc.getRange();

    CharacterRun run = range.insertBefore("1. Hello World!!! It works well!!!");
    run.setBold(true);
    run.setItalic(true);
    run.setCapitalized(true);
    OutputStream out = new FileOutputStream("sample2.doc");
    doc.write(out);
    out.flush();
    out.close();
    }
    }

    In the above code, test1.doc was an empty document.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The last post in this thread was close to 2 years ago. The original poster, and many others are long gone. Please don't resurrect old threads. Locking this one.

Similar Threads

  1. Reading Microsoft Word Document in JAVA
    By satheeshtech in forum Advanced Java
    Replies: 0
    Last Post: 07-18-2009, 08:21 AM
  2. Reading Writing to Microsoft Word -Urgent
    By Robert_85 in forum Advanced Java
    Replies: 5
    Last Post: 04-13-2009, 12:20 PM
  3. copying contents from word document to JTextPane
    By success21061985 in forum Advanced Java
    Replies: 1
    Last Post: 11-05-2008, 06:09 AM
  4. Saving word document from iframe
    By anil@netedgecomputing.com in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-15-2008, 11:49 AM
  5. add a xml document
    By Jack in forum XML
    Replies: 2
    Last Post: 07-04-2007, 09:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •