473,394 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to write to the .doc file using apache POI

I am trying to edit the word document(.doc/.docx) content using apache poi jar, But i unable to edit the document.
Is there any possible way to edit word document using poi?
May 19 '10 #1
2 11930
Dheeraj Joshi
1,123 Expert 1GB
Read documents here

Regards
Dheeraj Joshi
May 20 '10 #2
Hi ,thanks for reply. Here i am posting the problem i faced while writing the .doc file.

public class Headers {

public void newWordDoc(String baseFilename, String outputFilename) {
POIFSFileSystem fs = null;
HWPFDocument doc = null;
try {
fs = new POIFSFileSystem(new FileInputStream(baseFilename));
doc = new HWPFDocument(fs);

// Get the Range object encapsulating the text for the entire document.
Range range = doc.getRange();
public class Headers {

public void newWordDoc(String baseFilename, String outputFilename) {
POIFSFileSystem fs = null;
HWPFDocument doc = null;
try {
fs = new POIFSFileSystem(new FileInputStream(baseFilename));
doc = new HWPFDocument(fs);

// Get the Range object encapsulating the text for the //entire document.
Range range = doc.getRange();
if((range.text()).contains("SASI"))
range.replaceText("SASI", "${56565656}");
doc.write(new FileOutputStream(outputFilename));
}
catch(Exception ex) {
System.out.println("Caught an: " + ex.getClass().getName());
System.out.println("Message: " + ex.getMessage());
System.out.println("Stacktrace follows.............");
ex.printStackTrace(System.out);
}
}

public static void main(String[] args) {
Headers wt = new Headers();
wt.newWordDoc("/home/bvritic/Desktop/docs/LatestResume.doc", "/home/bvritic/Desktop/docs/LatestResume.doc");
}
}

I am trying to replace the string SASI with "${56565656}". It is working fine for first time.But i run the same program second time
i got the following error:

05-20 19:07:20.197: WARN/System.err(4885): java.io.IOException: Invalid header signature; read 0x0D9D80E29C80E20D, expected 0xE11AB1A1E011CFD0
05-20 19:07:20.374: WARN/System.err(4885): at org.apache.poi.poifs.storage.HeaderBlockReader.<in it>(HeaderBlockReader.java:107)
05-20 19:07:20.374: WARN/System.err(4885): at org.apache.poi.poifs.filesystem.POIFSFileSystem.<i nit>(POIFSFileSystem.java:151)
05-20 19:07:20.374: WARN/System.err(4885): at org.apache.poi.hwpf.HWPFDocument.verifyAndBuildPOI FS(HWPFDocument.java:132)
05-20 19:07:20.374: WARN/System.err(4885): at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocume nt.java:145)

Please suggest any procedure to follow?
Thanks
Jetti.
May 20 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tobias Hesselmann | last post by:
Hi folks, i have a problem using a PHP script as a custom handler in Apache. What i wanna do is this: Whenever a .html file is requested by a browser, i want Apache to call a CGI that outputs...
1
by: neha | last post by:
hi, i m trying to integrate python with apache on linux.For this i m using mod_python. I dont see any problem with the versions of python,apache and mod_python i m using. the versions i m using...
3
by: jon free | last post by:
Hi, Is it possible to host ASP.NET web application using Apache as a web server? If so, what is the tool or steps? -Jon
2
by: kelly | last post by:
Hi, I don't have a code to show you, what I need are references or algorithms so that I'm in a right track. By the way, thanks for introducing me the array or arrays. Now I can continue my...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
1
by: Lastknight | last post by:
hello all, can some bidy suggest me how to code for this problem? how to write a perl program using Apache::Session::File module? regards lastknight..
6
by: dolittle | last post by:
Hi, I`m using Apache as a proxy using ProxyPass (I didn`t set ProxyTimeout), I have two test clients sending and receiving xml messages using xmlhttprequest to a jeti server through the Apache...
1
by: karthikpallavi | last post by:
Hi Everyone, I am battling an issue and I figured one of you guys on this forum may be able to help. I have a developed an application in java to access Microsoft Dynamics 10.0 through Web...
0
by: Arjun Sarankulu | last post by:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.