Sitemap

Amicuk Programming Answers

Possible to read/ write word files using Java?

-0001-11-30   Views:0

Advertisement

I'm planning to write a Java application that can read an MS word document, extract something (including mathematics equations created with the equation editor) from the document and write it to another word document. Is it possible to do this? Can a

I'm planning to write a Java application that can read an MS word document, extract something (including mathematics equations created with the equation editor) from the document and write it to another word document.
Is it possible to do this?
Can anyone give me some idea?
Any idea is much appreciated :)

The replay answer
Advertisement
I think I may have misunderstood your question, but in case I didn't and you find this helpful, following is the code to read a word doc, replace certain strings, then write it out as a new doc.
import java.io.*;
public class Copy {
     public static String endResult;
     public static void main(String[] args) {
          String oldAuthor = "Samuel Foote";
          String newAuthor = "New Author";
          String oldDate = "1720-1777";
          String newDate = "1975 -- ";
      try {
          File inputFile = new File("C:\\document.doc");
          BufferedReader input = null;
          input = new BufferedReader(new FileReader(inputFile));
          StringBuffer contents = new StringBuffer();
          String line = null;
          while ((line = input.readLine()) != null){
               contents.append(line);
               contents.append(System.getProperty("line.separator"));          
          String text = contents.toString();
//     Replace the author and the dates
          Copy y = new Copy();
          y.replace(text, oldAuthor, newAuthor);
          text = endResult;
          y.replace(text, oldDate, newDate);
//     Copy the new, improved text to another file     //
          Copy z = new Copy();
          z.finalReplace(text);
          input.close();
     catch (FileNotFoundException ex) {
          ex.printStackTrace();
     catch (IOException ex){
          ex.printStackTrace();
     String replace(String text, String oldSubstring, String newSubstring) {
//          Search the text for a string, then replace it //
          int fromIndex = 0;
          int e = 0;
          StringBuffer sb = new StringBuffer();
          while ((e = text.indexOf(oldSubstring, fromIndex)) >= 0) {
               sb.append(text.substring(fromIndex, e));
               sb.append(newSubstring);
               fromIndex = e + oldSubstring.length();
          sb.append(text.substring(fromIndex));
          endResult = sb.toString();
          System.out.println("final string = " + sb);
          return sb.toString();
     String finalReplace (String args) throws IOException {
//          Move the altered text to a new file  //
          File outputFile = new File("C:\\copied document.doc");
          FileWriter out = new FileWriter(outputFile);
          Writer output = null;
          try {
               output = new BufferedWriter(new FileWriter(outputFile));
               output.write(endResult);
          finally {
               if (output != null) output.close();
             return endResult;

Go to See the other 13 answers

Creation of .RTF file in java

Category:DefaultRelease time:2015-10-11Views:130

Hi, I want to create/edit .RTF file through java application. In my RTF file, I should be able to edit data(formatting), inserting tables. This is already done. Now I want to create chart (like pie-chart) using java. I searched the net for the last c[More]

Generation of XML file from Java objects using castor

Category:DefaultRelease time:2015-10-11Views:130

I have the following java file(Customer.java). public class Customer      private String ID;      private FirstName firstName;      private MiddleName middleName;      private LastName lastName;      private ArrayList address;      public ArrayList g[More]

Generation of xml file from java code

Category:DefaultRelease time:2015-10-11Views:130

hi, I want to manipulate data in a xml file with java code.I have read data from xml file and also changed it. But i am unable to covert it again in xml file from java code. Can you please tell me how i can do this?Let me know which parser are you us[More]

Error reading zip file in Java 6

Category:DefaultRelease time:2015-10-11Views:130

We have a bespoke installer program that fails, intermittently, in Java 6 on Windows. After installing some files, it then fails with a stack trace like this: java.util.zip.ZipException: error reading zip file      at java.util.zip.ZipFile.read(Nativ[More]

How to read Excel file in java

Category:DefaultRelease time:2015-10-11Views:130

Respected sir/madam I want to read the values from Excel file in Java program. How can I do that. When I searched over the net I came to know that you can treat Excel file as a Database and write the code as u write for making DB connections . I did[More]

Executing batch file from Java stored procedure hang

Category:DefaultRelease time:2015-10-11Views:130

Dears, I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4. public static String runFile(String drive) String result = ""; String content = "echo off\n"[More]

JNI Invocation: open file in Java, write file in CPP

Category:DefaultRelease time:2015-10-11Views:130

Hello, Warning: I am a dunce, bad CPP code ahead! Using JNI invocation, I am trying to read a binary file in Java and write it in CPP. Everything compiles and runs without error, but the input and output jpg files are of course different. TIA to any[More]

How to read pdf files using java.io package classes

Category:DefaultRelease time:2015-10-11Views:130

Dear All, I have a certain requirement that i should read and write PDF files at runtime. With normal java file IO reading is not working. Can any one suggest me how to proceed probably with sample code block Thanks in advance.hi I also have the pbm.[More]

Create crystal report file using JAVA

Category:DefaultRelease time:2015-10-11Views:130

Can someone tell me how to a Create crystal report file using JAVA Programming I want a very simple examplePlease help me. It's urgent.[http://catb.org/~esr/faqs/smart-questions.html#urgent] Be back in an hour or two...Read other 2 answers[More]

How to create and edit a .ini file using java

Category:DefaultRelease time:2015-10-11Views:130

Hi All... Pls help me in creating and editing an .ini file using java... thanks in advance Regards, sathyaLet's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up) import java.io.File; i[More]

How to compare and edit Resource bundle file using java programe

Category:DefaultRelease time:2015-10-11Views:130

Hi All I have two resource bundle with key, value and some comments. I need to write a java code to compare both of the values of the keys and if the values are different then i want to replace the second value with the first value. Its a programe wh[More]

Hot
Hello, Please any one can help to show excessive values in next page . For example i want to show 567 5678 789 23456 I want to show values 23456 in next page only. Can anyone please suggest me how to do so? Thanks and regards MaveHi Swetlin, I have t [More]
Hello, I am a long time user of Acrobat XI Pro. I purchased it on a disk from a bona fide software shop. It has worked perfectly for many months and now upon opening a PDF it is coming up with an error message saying that I have 32767 days remaining [More]
Hi all, Does someone know how to see the actual content of an attachment in sxmb_moni? If I look under Inbound Message (CENTRAL)/Payloads, I would see one node for MainDocument and another node with the name of the attachment. When I click on the att [More]
Apache ant log error message as follows: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Buildfile: C:\Documents and Settings\wb [More]
What is wrong whit this mega stick's. I saw that all with firmware of 2.xx have same problem when you put mega stick in Win XP it's "READING", what is reading ? When you install stupid driver no more working of mega stick, on same computer but w [More]
Hi, I hope someone can help me here. I have an HP probook 6565b. What happens to me is that after a few seconds of transmitting video, my webcam freezes and stops transmitting leaving a still image of me up there. I can turn off the video and turn it [More]
In Oracle EBS version 12.1.3, e-Commerce Gateway, what is the purpose of and how do you use the 9202 and 9203 records in the inbound purchase order (POI) document layout definition?  Is there, and where is, published documentation concerning this fun [More]
Is it possible to assign movement types to internal order in FI config? Please advice. Edited by: PS on Aug 7, 2009 7:25 PMPS, You can't assign movement types to internal order in FI. Instead you could configure movement type in MM and  assign a move [More]
I receive a variable only in seconds. I'm trying to convert it to minutes when greater than 60. i.e. 121 (seconds) to 2:01. Can anyone help with the code. I got this far:quote: Originally posted by: Kronin555 <cfset minutes = duration / 60> <cfse [More]
I posted earler and got the anwser. Create a custom ABAP program that calls the RSPC_API_CHAIN_START Function Module, with a selection for the Process Chain where your user can enter the Meta Chain name to start the process. To make it simpler for th [More]