You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by shiva <my...@gmail.com> on 2011/02/10 17:42:32 UTC

how to write a text to doc file

hello sir,
i know how to write one .doc file content into another .doc file using poi
in jsp but i want to write some text into a .doc file using poi,
so please can anyone help me in doing that 
code for writing to one file to another file using jsp is below!!!

<%@ page
import="java.io.File,java.io.FileInputStream,java.io.FileOutputStream,java.io.IOException,java.io.OutputStream,org.apache.poi.hwpf.HWPFDocument,org.apache.poi.hwpf.usermodel.CharacterRun,org.apache.poi.hwpf.usermodel.Range,org.apache.poi.poifs.filesystem.POIFSFileSystem"%>


<%
File file = new File("xyz.doc");

try {

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
HWPFDocument doc = new HWPFDocument(fs);
Range range = doc.getRange();
CharacterRun run = range.insertAfter("Hello World!!!");
run.setBold(true);
run.setItalic(true);
run.setCapitalized(true);
OutputStream outa = new FileOutputStream(new File("D:/sample.doc"));
doc.write(outa);
out.println(outa);
out.flush();
out.close();
}
catch(Exception e)
{
out.println(e.getMessage());
}



%>


the above code is used to save file contents of xyz.doc to sample.doc but i
need to write a string in that page and i have to store it in sample.jsp
,please help me in doing that!!!
thanking u!!!



-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/how-to-write-a-text-to-doc-file-tp3379638p3379638.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org