|
java.lang.Object
Node
CompositeNode
com.aspose.words.Document
- All Implemented Interfaces:
- java.lang.Iterable, java.lang.Cloneable, java.lang.Iterable
public class Document - extends CompositeNode
Represents a Word document.
The Document is a central object in the Aspose.Words library. To load an existing document in any of the LoadFormat formats, pass a file name
or a stream into one of the Document constructors. To create a blank document, call the
constructor without parameters. Use one of the Save method overloads to save the document in any of the
SaveFormatformats.
MailMerge is the Aspose.Words's reporting engine that allows to populate
reports designed in Microsoft Word with data from various data sources quickly and easily.
The data can be from a java.sql.ResultSet or an array of values.
MailMerge will go through the records found in the data source and insert them into
mail merge fields in the document growing it as necessary. Document stores document-wide information such as Styles,
BuiltInDocumentProperties, CustomDocumentProperties, lists and macros.
Most of these objects are accessible via the corresponding properties of the Document. The Document is a root node of a tree that contains all other nodes of the document.
The tree is a Composite design pattern and in many ways similar to XmlDocument.
The content of the document can be manipulated freely programmatically: Consider using DocumentBuilder that simplifies the task of programmatically creating
or populating the document tree. The Document can contain only Section objects. In Microsoft Word, a valid document needs to have at least one section. Example: Executes mail merge from a java.sql.ResultSet.
// Open the template document
Document doc = new Document(getMyDir() + "MailingLabelsDemo.doc");
// Open a DSN-less connection.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connString = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};" +
"DBQ=" + getDatabaseDir() + "Northwind.mdb;UID=Admin";
Connection conn = DriverManager.getConnection(connString);
// Get the data.
Statement statement = conn.createStatement();
ResultSet table = statement.executeQuery("SELECT TOP 50 * FROM Customers ORDER BY Country, CompanyName");
// Perform mail merge.
doc.getMailMerge().execute(table);
// Close the database.
conn.close();
doc.save(getMyDir() + "MailMerge.ExecuteResultSet Out.doc");
|
Constructor Summary |
Document()
Creates a blank Word document.
|
Document(java.lang.String fileName)
Opens an existing document from a file. Automatically detects the file format.
|
Document(java.lang.String fileName, int loadFormat, java.lang.String password)
Opens an existing document from a file.
|
Document(java.io.InputStream stream)
Opens an existing document from a stream. Automatically detects the file format.
|
Document(java.io.InputStream stream, java.lang.String baseUri)
Opens an existing document from a stream. Automatically detects the file format.
|
Document(java.io.InputStream stream, java.lang.String baseUri, int loadFormat, java.lang.String password)
Opens an existing document from a stream.
|
|