|
|
||||||||||||||||||||||||||||||||||||||||
Step 3: Create a Document
|
|||||||||||||||||||||||||||||||||||||||||
Document |
A Document object represents the whole Word document. |
|---|---|
Section |
A Section object represents a major section in a document,
like a chapter in a book. Many documents will only contain one section.
In more complex documents, content can be divided into multiple sections. |
Paragraph |
A Paragraph object represents a paragraph in the Word document -
a block of text that ends with a carriage return. |
CharacterRun |
A CharacterRun object represents a contiguous run of characters in
the document, all of which have the same formatting. |
Table |
A Table object represents a table in the document. |
TableCell |
Each cell in a table is represented by a TableCell object. |
List |
A List object represents a numbered or bulleted list. |
ListEntry |
Each entry in a list is represented by a ListEntry object. |
To insert a run of characters at the beginning of your document, call
Document.InsertTextBefore:
// [C#]
CharacterRun charRun =
doc.InsertTextBefore("This file was created with OfficeWriter", true);
' [VB.NET]
Dim charRun As CharacterRun = _
doc.InsertTextBefore("This file was created with OfficeWriter", True)
The second parameter of InsertTextBefore specifies whether
the inserted text is its own character run with default formatting (true), or
if it should assume the formatting of the first character in the Element
(in this case, the Document) and become a part of it (false).
You can use the formatting properties of the CharacterRun class
to format the text you inserted:
// [C#]
charRun.Font.Bold = true;
charRun.Font.FontName = "Times New Roman";
' [VB.NET]
charRun.Font.Bold = True
charRun.Font.FontName = "Times New Roman"

When the document is complete, you can save it to the server's hard disk, return it
in memory, stream it to the browser, or pass it to WordTemplate (for more
information, see Output Options). For example, to stream
the document to the browser, use:
// [C#]
bool bPreserve = true;
bool bOpenInBrowser = false;
wordApp.Save(doc, // Document object to save
bPreserve,
Page.Response,
"OfficeWriter.doc",
bOpenInBrowser);
' [VB.NET]
Dim bPreserve As Boolean = True
Dim bOpenInBrowser As Boolean = False
wordApp.Save(doc, _
bPreserve, _
"OfficeWriter.doc", _
bOpenInBrowser)
When you pass an HttpResponse object to Save, OfficeWriter will stream the
generated Word file to the client. The browser will display a download
dialog asking the user to open or save the file. The method's fourth parameter
specifies a file name to display in the download dialog. If the method's fifth parameter -
openInBrowser - is true, the browser is Internet Explorer,
and the user chooses to open the Word file, the file will open in the browser window.
Note: Word files cannot be embedded in browsers other than IE.

Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.