473,499 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace string in ms word file

1 New Member
Salue,

I need to add a functionality to my Java app by allowing the replacement of strings in ms word files.

Basically I need to use an original MS Word file as template and then populate it with data,
replacing some keywords. And I need to do this with Java.

I know MS Word is binary and not text file, so I was wondering if there is any Java API to let me do this?

Merci, Irene
May 7 '09 #1
3 7662
cmdr
3 New Member
Yes Irene, it is possible to use ms word templates and populate them with data.

Example:
Expand|Select|Wrap|Line Numbers
  1. import officetools.OfficeFile; // officetools.jar from this website http://www.dancrintea.ro/doc-to-pdf/ 
  2.  
  3. FileInputStream fis = new FileInputStream(new File("irene_template.doc"));
  4. FileOutputStream fos = new FileOutputStream(new File("irene_final_result.doc"));
  5.  
  6. OfficeFile f = new OfficeFile(fis,"localhost","8100", true);
  7.  
  8. f.replaceAll("Hello","Salue Irene");
  9.  
  10. f.write(fos);
  11.  
  12.  
Bonne chance :)
May 7 '09 #2
sgilberta
7 New Member
Thanks both for these messages, they really helped me and now OfficeTools is my default library when working with ms office files.

A bunch of nice operations are possible:
- replace strings in DOC files as in your example
- convert DOC, XLS or PPT to PDF
- read/write Excel files using simplified API like getCell and setCell
- show/hide Excel sheets(like secondary calculations)

The only downside is that it needs OpenOffice,
but the good part is that I can do all the above stuff on ms office files.
Jul 2 '09 #3
rextyler
1 New Member
I was looking especially for convertion to pdf, but replacing is really great, I did not know it was possible. Good stuff. Thx for sharing.
Dec 8 '09 #4

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

Similar topics

3
17788
by: - ions | last post by:
Hi, i would like to know how to replace every char in a string with a certin given char using the String.replace(char oldChar,char newChar). I would like to replace all letters with an underscore...
2
14881
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
1
5298
by: adam lital | last post by:
Hi, I have word document and i want to replace a specific text with a bookmark using code. Example: in the document i have the text and i want to replace this to a bookmark called ClientName....
0
5685
by: Balakrsihna | last post by:
Hi All, Can anyone tell me how to replace an image in MS Word 2003 using c#.net. I am converting an html file to word doc and sending this as attachment using System.Web.Mail; the...
4
4820
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
3
1205
by: Craig | last post by:
Hi I'm having some troubles getting my regex to work. I have a string as follows The "quick and brown" fox "jumped over the" lazy dog. The output should be as follows: The "quick and brown"...
0
3066
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
1
9025
by: Michael Yanowitz | last post by:
Hello: I am hoping someone knows if there is an easier way to do this or someone already implemented something that does this, rather than reinventing the wheel: I have been using the...
2
5049
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
12
2054
by: implement | last post by:
Hi all! I try to code my own version of replace but it doesn't work. I hope somebody can help me out. It only replaces the first char!. Why I don't use the public string.replace function?...
0
7009
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
7178
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
7223
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...
1
6899
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
7390
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...
1
4919
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...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.