Access microsoft word doc using java

how can i access microsoft word using java .
I want to select text from the word in the same format as it is.
if possible can u all help me

By using an appropriate library. JText, whatever.
Google, man.I think Rene meant iText!Whatever. :) Never used it, I just remembered there was something named like that. Thanks.

Similar Messages

  • Printing a microsoft word doc using Java Print API

    Hi,
    I have to print a microsoft word doc.I am using Java Print API, but the code is printing only Hashcodes instead of the actual document.
    Here is the code. Please let me know whats wrong in it.
    CODE:::
    public String print() throws Exception {
    String realPath = getRealPath("/images/formLibrary/csaAddressContactRequestForm100.doc");
    PrintRequestAttributeSet pras1 = new HashPrintRequestAttributeSet();
    DocFlavor flavor1 = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = defaultService.createPrintJob();
    FileInputStream fis1 = new FileInputStream(realPath);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc1 = new SimpleDoc(fis1, flavor1, das);
    job.print(doc1, pras1);
    Thread.sleep(10000);
    System.exit(0);
    return "";
    }

    By using an appropriate library. JText, whatever.
    Google, man.I think Rene meant iText!Whatever. :) Never used it, I just remembered there was something named like that. Thanks.

  • Can Java be used to parse Microsoft Word(.doc) files?

    Hi guys ,
    I want to know whether Java can be used to parse Microsoft Word(.doc) files for searching a string or for checking for grammatical errors, etc
    Thanks in advance.
    Avichal

    Hey man, anything and every thing can be done these days.
    About ur question doc is like all other normal text files with some extra features and extra character supports and other stuffs.
    If u neglect those parts and if u consider it to be a normal text file then its a much simpler job.
    Here is a code that searches for the key word in all the doc files, txt files, pdf files and html files
    in the mentioned folder and sub folders. Any way its a servlet u can change it to a normal program.
    It first check the file to know whether they are doc, pdf, html or txt files if yes then it will read the file and
    store the contents in the vector and parse the vector for the search string and display the result.
    Along with the result the below code will also display the time taken and the number of search string found in the document
    import java.io.*;
    import java.util.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class search_local extends HttpServlet
         public void service( HttpServletRequest _req, HttpServletResponse _res ) throws ServletException, IOException
              long startTime = System.currentTimeMillis();          
              File RootDir     = new File( _req.getRealPath( "/docs/" ) );
              if ( RootDir.isDirectory() == false )
                   System.out.println( "Invalid directory" );
                   _res.setStatus( HttpServletResponse.SC_NO_CONTENT );
                   return;
              Vector kList = new Vector( 3 );
              StringTokenizer st = new StringTokenizer( _req.getParameter( "search_text" ), "+" );
              while ( st.hasMoreTokens() )
                   kList.addElement( st.nextToken().trim() );
              //- Run through list
              Vector toBeDone     = new Vector( 10 );
              Vector found     = new Vector( 10 );
              String dir[] = RootDir.list( new htmlFilter() );
              cDirInfo tX = new cDirInfo( RootDir, dir );
              toBeDone.addElement( tX );
              while (  toBeDone.isEmpty() == false )
                   tX = (cDirInfo)toBeDone.firstElement();
                   try
                        int x = 0;
                        for ( ;; )
                             File newFile = new File( tX.rootDir, tX.dirList[x] );
                             if ( newFile.isDirectory() )
                                  File t = new File( tX.rootDir, tX.dirList[x] );
                                  String a[] = newFile.list( new htmlFilter() );
                                  toBeDone.addElement( new cDirInfo( t, a ) );
                             else
                                  int freq = searchFile( kList, newFile );
                                  if ( freq != 0 )
                                       found.addElement( new cPage( freq, newFile ) );                              
                             x++;
                   catch( ArrayIndexOutOfBoundsException E ){}
                   toBeDone.removeElementAt(0);
                   dir     = null;
              long totalTime = System.currentTimeMillis()     - startTime;
              formatResults( found, kList, totalTime, _req.getRealPath( "/docs" ), _res );
         private void formatResults( Vector _fList, Vector _kList, long time, String _root, HttpServletResponse _res ) throws IOException
                 _res.setContentType("text/html");
              PrintWriter Out = new PrintWriter( _res.getOutputStream() );
              Out.println( "<HTML><HEAD><TITLE>Search results</TITLE></HEAD>" );
              Out.println( "<BODY><H3>Search Results</H3><BR>" );
              Out.println( "Keywords:<B> " );
              Enumeration E = _kList.elements();
              while ( E.hasMoreElements() )
                   Out.println( (String)E.nextElement() + " : " );
              Out.println( "</B><BR><BR><CENTER><HR WIDTH=100%></CENTER><BR>" );
              E = _fList.elements();
              cPage sPage;
              String link;
              while ( E.hasMoreElements() )
                   sPage = (cPage)E.nextElement();
                   link  = sPage.cFile.toString();
                   link  = "http://localhost/BugFix/docs/" + link.substring( link.indexOf( _root )+_root.length(), link.length() );
                   Out.println( "<FONT SIZE=+1><A HREF=" + link + ">" + sPage.cFile.getName() + "</A></FONT>" );
                   Out.println( "<FONT SIZE=-2>(" + sPage.freq + ")</FONT><BR>" );
              if ( _fList.size() == 0 )
                   Out.println( "<I><B>No sites found!</I></B><BR>");
              Out.println( "<BR><CENTER><HR WIDTH=100%></CENTER>" );
              Out.println( "<BR><FONT SIZE=-1>Time to complete: " + ((double)time/1000) + " seconds</FONT>" );
              Out.println( "</BODY></HTML>" );
              Out.flush();
         private int searchFile( Vector _klist, File _filename )
              //- Links the file
              int     frequency=0;
              try
                   DataInputStream In     = new DataInputStream( new FileInputStream( _filename ) );
                   String LineIn, token;
                   boolean bValid = true;
                   Enumeration E;
                   cLineParse lp;
                   while ( (LineIn = In.readLine()) != null )
                        lp = new cLineParse( LineIn.toUpperCase() );
                        while ( (token=lp.nextToken()) != "" )
                             if ( token.indexOf( "<" ) != -1 && (
                                   token.indexOf( "<A" ) != -1 ||
                                   token.indexOf( "<HE" ) != -1 ||
                                   token.indexOf( "<APP" ) != -1 ||
                                   token.indexOf( "<SER" ) != -1 ||
                                   token.indexOf( "<TEX" ) != -1  ))
                                  bValid  = false;
                             else if (     token.indexOf( "<" ) != -1 && (
                                            token.indexOf( "</A" ) != -1 ||
                                            token.indexOf( "</HE" ) != -1 ||
                                            token.indexOf( "</APP" ) != -1 ||
                                            token.indexOf( "</SER" ) != -1 ||
                                            token.indexOf( "</TEX" ) != -1  ))
                                  bValid  = true;
                             else if ( bValid )
                                  E = _klist.elements();
                                  String key;
                                  while ( E.hasMoreElements() )
                                       key     = ((String)E.nextElement()).toUpperCase();
                                       if ( token.indexOf( key ) != -1 )
                                            frequency++;
                   In.close();
              catch( IOException E ){}
              return frequency;
    class cPage extends Object
         public int     freq;
         public File cFile;
         public cPage( int _freq, File _cFile )
              freq = _freq;
              cFile = _cFile;
    //- End of file
    //----- Supporting classes
    class htmlFilter implements FilenameFilter
         public boolean accept(File dir, String name)
              File tF     = new File( dir, name );
              if ( tF.isDirectory() )
                   return true;
              int indx = name.lastIndexOf( "." );
              if ( indx == -1 )
                   return false;
              String Ext = name.substring( indx+1, name.length() ).toLowerCase();
              if ( Ext.equals( "html" ) ||
                    Ext.equals( "pdf" ) ||
                    Ext.equals( "txt" ) ||
                    Ext.equals( "doc" ) )
                    return true;
              return false;
    class cDirInfo
         public File     rootDir;
         public String[] dirList;
         public cDirInfo( File _r, String[] _d )
              rootDir     = _r;
              dirList = _d;
    class cLineParse
         String L;
         public cLineParse( String _s )
              L = _s;
         public String nextToken()
              String ns="";
              boolean bStart = false;
              for ( int x=0; x < L.length(); x++ )
                   if ( L.charAt(x) == '<' && ns.length() != 0 )
                        L = L.substring( x, L.length() );
                        return ns;
                   else if ( L.charAt(x) == '<' )
                        ns     = ns + L.charAt( x );
                        bStart = true;
                   else if ( L.charAt(x) == '>' ||
                               L.charAt(x) == '\r' ||
                         ( L.charAt(x) == ' ' && bStart == false ) )
                        ns     = ns + L.charAt( x );
                        L = L.substring( x+1, L.length() );
                        return ns;
                   else
                        ns     = ns + L.charAt( x );
              L = "";
              return ns;
    }

  • Writing to word document using java

    hi,
    i want to retrieve the values from database and then write to .doc file. how can i write to a word document using java?
    thanks in advance

    Google for "java write to word file"
    and behold the magic results

  • HT204394 how do i put microsoft word docs onto icloud

    how do i put microsoft word docs onto icloud so that i can transfer to my mac book

    Not really.
    You can sign into iCloud.com from a web browser on your PC.
    Open Pages and drag the Word document in or click the Gear on the top right and upload.
    This will convert it to a Pages document. It will be accessible to you through iCloud and the Pages app on your iOS devices. You can always redownload the file from iCloud as a Word document.
    As with any document conversion, this may alter the formatting.

  • Unable to convert Microsoft Word doc. to PDF in Words (there is no response)

    Unable to convert Microsoft Word doc to PDF in Words (Does not respond) or Create PDF from a Word doc. in Adobe Acrobat X Standard 10.1.1 with all updates installed. I receive apop-up saying "Missing PDF Maker Files: Dou you want to run the installer in Repair Mode"  I have done this several times. I have un-installrd and re installed the program twice. Still does not work. I'm running Windows 7 Home version and Microsoft Office XP 2002. This is a brabd new Acrobat program right out of the box. Suggestions Please.

    In WORD 2002, I believe you can only print to the Adobe PDF printer. I think that WORD 2003 is the first compatible with AA X. Check out http://kb2.adobe.com/cps/333/333504.html.

  • PDF/X-1a from a Word doc. using Acrobat 9.5.2 Standard?

    Can I create a PDF/X-1a file from a Microsoft Word document using my copy of Acrobat 9.5.2 Standard?

    You say the setting does not work. What happens?

  • Convert Microsoft Word docs to Pages?

    I love Pages and want to convert a bunch of Microsoft Word docs into Pages documents. The action would open the .doc file in Pages, then save it as a Pages document with the same title.
    Is there anything that would let me do this? Thanks.

    I've tried that myself, to no avail.
    Here's what I've tried - if anyone can twiddle with this to make it actually work, I too would be grateful!
    1 find finder items
    2 get specified finder items
    3 copy finder items (to save originals)
    4 launch app (pages)
    but then there's no action for creating a new file or saving-as or anything...
    thanks and peace-
    DW

  • Hello, is there a way to redact a word or item from a pdf using adobe pro X the same way you can if you convert a word doc using pro X on a pc?

    hello, is there a way to redact a word or item from a pdf using adobe pro X the same way you can if you convert a word doc using pro X on a pc?

    If the document is not a scanned image or protected from editing then you should be able to edit it. I would have to guess you have a scan and when you converted to Word, you ran OCR (Optical Character Recognition) on it converting the scanned image to live text.
    This is the forum for the free Adobe Reader which can not edit or redact.

  • How to do exact word search using Java API

    Hi,
    Can someone tell me how can I write a search query using Ultra Search Java API to return data containing a full word that is sent as a search
    parameter. e.g. If I want to search for a word 'Dictionary' I need to get all the results conatining full word Dictionary for example if I
    have following 4 records
    1. Dictionary
    2. English Dictionary
    3. French Dictionary
    4. AllDictionary
    How can I write a query that returns me first 3 records only as they contain the word 'Dictionary' and not the fourth record as it's not a word.
    Here is what I need to get back and ordered in that way as the 'Dictionary' needs to be first record because the search is on Dictionary.
    1. Dictionary
    2. English Dictionary
    3. French Dictionary
    Any help is appreciated.
    Thanks

    Looks like we can not do an exact word search using Java API.

  • How do I open a microsoft word file using Teststand 2010?

    Hi All,
    I am currently using Teststand 2010. I need to do a simple task, at least I thought it was simple. I want to open a microsoft word file using Teststand 2010. I thought the using the "Call Executable" would be the first step, but I am not sure how to set it up. Any help would be greatly appreciated.
    Thanks,
    WJ

    Hello,
    You will actually need to use an ActiveX step to use Microsoft Word. I found this forum post with a similar question and an example. I opened the example and saved it to TestStand 2010 to reattach here.
    Note: you will probably need to modify the "Open Document" step to make sure the FileName of the Word document matches the real file location.
    Taylor B.
    National Instruments
    Attachments:
    TestStand MS Word.zip ‏13 KB

  • How to get the page numbers of a word/mpp/execl doc using Java?

    Hi,
    I meet a problem in Java programming. I want to get the page numbers of a Word/MPP/EXECL/PDF document. For exmaple, if a PDF docment have 10 pages, I need get the 10 . How to get it using Java?
    Please advise me as soon as possible if you have any good suggestions! Thanks!
    Yin

    There are several good tools that allow you to access COM objects from Java. Here are two of the better ones:
    Bridge2Java
    http://www.alphaworks.ibm.com/tech/bridge2java
    J-Integra
    http://www.linar.com/
    Both of these tools will allow you to access MS Office products (including Word and Excel) via COM interfaces.

  • Generating reports in .doc format (Word Document) using Java POI - HWPF

    Hi
    Can anybody help me how to generate the report in .doc format using POI API?
    Please share the sample code, if you have.
    Thanks in Advance
    Dhilip

    Hi,
    I dont think that your requirement has to do with ADF capabilities.
    You want to edit a word document with JAVA. For that reason, you will need an API, as the suggestions above.
    You can do it without ADF and by using standard JAVA and the API of your choice. a static void main will do for that matter.
    ADF comes into the game when you want to handle the document with your ADF application.
    This means that you either want to get your new data to be placed on your doc from BC or any other DataControl or you want to do something else with ADF..
    My guess is that you want to get data from ADF into your Doc.
    You could create an API on handling your Doc and then use it into your ADF application.
    Regards,
    Dimitris.

  • How to Store word doc in java using oracle

    hi my name is jagapathi raju i am working in Niit LTD
    can any one tell me how to store A word doc in oracle using java

    Hi Jagapathi
    You can store text/doc files in Database using CLOB/BLOB columns. Let me check if there are any samples...
    Thanks
    Srinivas

  • Save as Microsoft Word doc not using initial OCR process

    I used Acrobat X's OCR feature wich seems to work quite well... It does all the normal stuff like giving you the option to fix up and suspect conversion issues. After correcting any suspects I then went to save the file as a document that I could then forward to sombody to edit... Say Microsoft Word.
    When I went File->Save->Microsft Word->Word Document and selected the location, I could see in the little status bar down the bottom that Acrobat X went through what looked like another OCR process. And sure enough when I opened up the file the Word document contained all the un-fixed suspects in it.
    Can anybody else confirm this behaviour, tell me if I am missing something or tell me a possible work around?

    Please note that this is a known limitation with the current version of Acrobat (Acrobat X). We might fix this issue in our future releases.

Maybe you are looking for