poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiva <mygr8hart....@gmail.com>
Subject how to write a text to doc file
Date Thu, 10 Feb 2011 16:42:32 GMT

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


Mime
View raw message