473,624 Members | 2,374 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 7676
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
17808
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 ie. "hello world" will be come... "_ _ _ _ _ _ _ _ _ _" (ive added xtra spaces so it dosnt look like one line!) with the method i have written only the last char is replaced, loop problem i guess! public String hideWord(String word) {
2
14904
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 in the format that I need it in order to create the reports that we use. So far this has proven to be successful for the reports that I am doing and the data that I am pulling into it. I just have one challenge that may require a lot of work and I...
1
5318
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. Thanks, Adam.
0
5706
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 recipient could not see the image in attachment. I am using Inlinepicture.Addpicture but still not working
4
4824
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 way mean to secrife lots of time in asp.net. can any one give me such a expression in which i pass a data string and search word string and replace word string? if so plz help me out. i'm in badly need.
3
1213
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" fox "jumped and over and the" lazy dog. So the expression needs to insert 'and' between the groups of words enclosed in double quotes, ignoring the insert if the 'and' word exists bewteen the
0
3074
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 want to replace all of them. You need to look at it in a case-by-case basis. What can you do? Answer: emacs.
1
9051
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 string.replace(from_string, to_string, len(string)) to replace names in a file with their IP address. For example, I have definitions file, that looks something like: 10.1.3.4 LANDING_GEAR 20.11.222.4 ALTIMETER_100
2
5081
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, the string at the beginning explains what it does: '''A script for MS Word which does the following: 1) Assigns all Hebrew italic characters "Italic" character style. 2) Assigns all Hebrew bold characters "Bold" character style. 2) Assign all...
12
2068
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? Well I love implementing string functions :-). I coded another function for replacing chars in a word and this
0
8246
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8631
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
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 we have to send another system
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.