This post covers a very simple program for creating an Office Open XML word-processing document. The source code for this program is included in the attachment, or you can download it here.
The syntax for using the CreateDOCX program is shown to the right. It's a command-line program that takes two arguments: a filename to be created, and some text to put in the file. That's all there is to it -- the program then creates the output file using the .NET packaging API. The resulting document can be opened with Microsoft Office, but Office is not required in order to create the document.
Let's look at what's going on under the hood. The first thing to note is the namespace used for the document markup:
This is the namespace for the WordprocessingML markup that is used in the main body part ("start part") of the document. Next, we create an XML document with the structure of a WordprocessingML document (document, body, paragraph, run, etc.), and the text (the BodyText variable) embedded inside it:
Now that we've created the XML "start part" for the document, we just need to create a package (with the packaging API), add the start part to it, and create a relationship. (All parts must have a relationship.)
That's all there is to it -- this code will generate a DOCX that loads in Word 2007 or any other valid Open XML consumer. You can copy the code from the SaveDOCX method of the attached solution, and use that as a starting point for a document-creation or document-assembly solution. Note that there is no need for the Office clients in this scenario: your code can create the DOCX without any of the complexity and scalability issues of automating Word, through use of the .NET packaging API.
The next post in this series will cover CreateXLSX, the SpreadsheetML version of this sample.
A while back, the OpenXmlDeveloper.org website offered an example of how to create a WordProcessingML
Here at the Open XML workshop in Paris this week, Jerome Berthaud pointed out to me that my CreateXlsx
Ich hatte versprochen, die Ressourcen für meine beiden Vorträge auf der Office, Vista und Exchange Launch
This post covers a very simple program for creating an Office Open XML word-processing document. The source code for this program is included in the attachment, or you can download it here . The syntax for using the CreateDOCX program is shown to the
PingBack from http://outdoorceilingfansite.info/story.php?id=56519
PingBack from http://quickdietsite.info/story.php?id=9418