Java Word, Excel, Access, IE, OutLook, PDF, etc.

Source: Internet
Author: User
Recently, I found that many questions have been raised in this regard. It took me some time to find some materials and work out a simple example for java to operate www. lowagie. comJava operation Word, Excel, access Reference: danadler. comjacbjakarta. apache. orgpoiwww. onjava. compubaonjava2003

Recently found to ask this question extraordinary many, took some time to find some information, and sorted out a simple example java operation PDF http://www.lowagie.com/Java operation Word, Excel, access Reference: http://danadler.com/jacob/ http://jakarta.apache.org/poi/ http://www.onjava.com/pub/a/onjava/2003


I recently found that many questions have been raised in this regard. It took me some time to find some materials and work out a simple example.
Java operations PDF http://www.lowagie.com/
Java operation Word, Excel, access
Refer:
Http://danadler.com/jacob/
Http://jakarta.apache.org/poi/
Http://www.onjava.com/pub/a/onjava/2003/01/22/poi.Html
Http://www.csdn.net/develop/article/15/15311.shtm
Http://forum.java.sun.com/thread.jsp? Forum = 40 & thread = 382666 & tstart = 0 & trange = 15
  
An example of jacob's Word operations, Excel, Access, and Outlook operations, is in the jacob's sample directory.
Import java. io. File;
Import com.jacb.com .*;
Import com. jacob. activeX .*;
Public class WordTest {
  
Public static void main (String [] args ){
WordBean word = new WordBean ();
Word. openWord (true );
Word. createNewDocument ();
Word. insertText ("Hello word .");
}
}
  
  
Import com. jacob. activeX .*;
Import com.jacb.com .*;
Public class WordBean extends java. awt. Panel
{
PRivate ActiveXComponent MsWordApp = null;
Private Dispatch document = null;
Public WordBean ()
{
Super ();
}
Public void openWord (boolean makeVisible)
{
// Open Word if we 've not done it already
If (MsWordApp = null)
{
MsWordApp = new ActiveXComponent ("Word. application ");
}
// Set the visible property as required.
Dispatch. put (MsWordApp, "Visible ",
New Variant (makeVisible ));
}
Public void createNewDocument ()
{
// Find the Documents collection object maintained by Word
Dispatch documents =
Dispatch. get (MsWordApp, "Documents"). toDispatch ();
// Call the Add method of the Documents collection to create
// A new document to edit
Document = Dispatch. call (events, "Add"). toDispatch ();
}
Public void insertText (String textToInsert)
{
// Get the current selection within Word at the moment. If
// A new document has just been created then this will be
// The top of the new doc
Dispatch selection =
Dispatch. get (MsWordApp, "Selection"). toDispatch ();
// Put the specified text at the insertion point
Dispatch. put (selection, "Text", textToInsert );
}
Public void saveFileAs (String filename)
{
Dispatch. call (document, "SaveAs", filename );
}
Public void printFile ()
{
// Just print the current document to the default printer
Dispatch. call (document, "PrintOut ");
}
Public void closeDocument ()
{
// Close the document without saving changes
// 0 = wdDoNotSaveChanges
//-1 = wdSaveChanges
//-2 = wdPromptToSaveChanges
Dispatch. call (document, "Close", new Variant (0 ));
Document = null;
}
Public void closeWord ()
{
Dispatch. call (MsWordApp, "Quit ");
MsWordApp = null;
Document = null;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.