473,394 Members | 1,693 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.

Replace string in ms word file

1
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 7657
cmdr
3
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
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
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
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
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
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
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
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
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
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
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
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
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
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:
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.