473,416 Members | 1,623 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,416 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 11935
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.