Results 1 to 5 of 5
- 07-18-2009, 08:32 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 5
- Rep Power
- 0
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>
- 02-25-2010, 06:26 PM #2
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
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!
- 02-25-2010, 06:28 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
hi! how to wtite jtable to ms word program i try this but i didn't help me.
- 08-07-2011, 11:14 AM #4
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
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.
- 08-07-2011, 11:15 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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
-
Reading Microsoft Word Document in JAVA
By satheeshtech in forum Advanced JavaReplies: 0Last Post: 07-18-2009, 08:21 AM -
Reading Writing to Microsoft Word -Urgent
By Robert_85 in forum Advanced JavaReplies: 5Last Post: 04-13-2009, 12:20 PM -
copying contents from word document to JTextPane
By success21061985 in forum Advanced JavaReplies: 1Last Post: 11-05-2008, 06:09 AM -
Saving word document from iframe
By anil@netedgecomputing.com in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 05-15-2008, 11:49 AM -
add a xml document
By Jack in forum XMLReplies: 2Last Post: 07-04-2007, 09:21 AM


LinkBack URL
About LinkBacks

Bookmarks