Message-ID: <63400302.8371.1711643428597.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8370_734316173.1711643428597" ------=_Part_8370_734316173.1711643428597 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Table of Contents |
---|
=20
|
Hello World with ExcelApplication
WordWriter's WordApplication approach provides you with full programmati= c control over the binary Word file formats (DOC, DOT). This includes the a= bility to create and modify: paragraphs, tables, lists, hyperlinks, bookmar= ks, images and more! This tutorial will show you how to create a new docume= nt and write some text to that document.
Include the SoftArtisans.OfficeWriter.WordWriter names= pace in the code behind.
using SoftArtisans.OfficeWriter.WordWriter;=20
Imports SoftArtisans.OfficeWriter.WordWriter=20
Instantiate the WordApplic= ation object
WordApplication WAPP =3D new WordApplication();=20
Dim WAPP As WordApplication =3D new WordApplication()=20
Create a new document with WordApplication.Create()
Document DOC =3D WAPP.Create();=20
Dim DOC As Document =3D WAPP.Create()=20
Unlike the WordTemplate object, which represents a si= ngle file, WordApplication works as a file generation engine. The WordAppli= cation object can be used to create, open, and save multiple documents at o= nce.
=20 =20For this example, we'll pull a value from a text box in a web form. = Get the value.
string value =3D DataValueBox.Text.Trim();=20
Dim value As string =3D DataValueBox.Text.Trim()=20
Insert the text into the document with Element.InsertTextAfter.
DOC.InsertTextAfter(value, true);=20
DOC.InsertTextAfter(value, true)=20
Text strings need to be inserted into a paragraph, table cell, or = list entry elements in a document. In this case, when the text is inserted = into the document, it's actually inserted into the last paragraph in the do= cument. Documents created by WordApplication come with a paragraph, so we d= o not need to create that paragraph.
Save the output file with WordApplication.Save
WAPP.Save(DOC, Response, "Output.doc", false);=20
WAPP.Save(DOC, Response, "Output.doc", false)=20
WordApplication.Save has the same output options as WordTemplate: = save to disk, save to memory stream, stream back to the client inline, and = stream back to the client as an attachment. In this case, we're streaming t= he document back to the client as an attachment.
Here is an example o=
f what the output should look like:
Congratulations, you have completed Hello World using WordApplicatio= n!
using SoftArtisans.OfficeWriter.WordWriter; ... WordApplication WAPP =3D new WordApplication(); Document DOC =3D WAPP.Create(); string value =3D DataValueBox.Text.Trim(); DOC.InsertTextAfter(value, true); WAPP.Save(DOC, Response, "Output.doc", false);=20
Imports SoftArtisans.OfficeWriter.WordWriter ... Dim WAPP As WordApplication =3D new WordApplication() Dim DOC As Document=3D WAPP.Create() Dim value As string =3D DataValueBox.Text.Trim() DOC.InsertTextAfter(value, true) WAPP.Save(DOC, Response, "Output.doc", false)=20
You can download the code for the Hello World tutorial as a Visual Studi= o solution.