<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="https://www.schweda.net/style_feed.css" ?>
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:atom="http://www.w3.org/2005/Atom"	
	xmlns:dc="http://purl.org/dc/elements/1.1/" > 
<channel>
    <title>schweda.net - Blog</title>
    <link>https://www.schweda.net/</link>
    <description>schweda.net - Blog - Blog-Beitraege</description>
    <language>de-at</language>
    <copyright>Copyright 2006-2026</copyright>
    <generator>schweda.net</generator>
    <managingEditor>heinz.schweda@schweda.net (Heinz Schweda)</managingEditor>
    <webMaster>heinz.schweda@schweda.net (Heinz Schweda)</webMaster>
    <category>Blog</category>
	<atom:link href="https://schweda.net/blog_rss.php?bid=490" rel="self" type="application/rss+xml" />
<item>
<title><![CDATA[Word-Dokument mit Tabelle per Code erstellen]]></title>
<description><![CDATA[
<p><img alt="Microsoft Word" src="http://www.schweda.net/pictures/blogpics/microsoft_word_logo_2013.jpg" style="float:right; padding-left:10px" title="Microsoft Word" />Anbei ein einfach gehaltener Job, der ein Word-Dokument mit einer Tabelle per Code erstellt. Das Beispiel legt auch den Rahmen und dessen Farbe der Tabelle fest.<br />
Voraussetzung ist ein lokal installiertes Microsoft Word.
</p>


<pre class="pre_blog_axcode">
static void CreateWordFileWithTable(Args _args)
{
    COM wordApplication;
    COM wordTables;
    COM wordTable;
    COM wordSelection;
    COM wordTableRows;
    COM wordRange;
    COM wordTableCell;
    COM wordTableCellRange;
    COM wordDocuments;
    COM wordDocument;
    COM wordTableBorders;
    ;
 
    // Initialize Word object and document
    wordApplication = new COM(&quot;Word.Application&quot;);
    wordDocuments = wordApplication.documents();
    wordDocuments.add();
    wordDocument = wordDocuments.item(1);
 
    wordSelection = wordApplication.selection();
    wordRange = wordSelection.range();
 
    // Get table collection
    wordTables = wordSelection.tables();
 
    // Create table with 3 rows and 5 columns
    wordTable = wordTables.add(wordRange, 3, 5);
 
    // Fill cell: First line, second column
    wordTableCell = wordTable.Cell(1, 2);
    wordTableCellRange = wordTableCell.range();
    wordTableCellRange.text(&quot;Hello&quot;);

    // Fill cell: Second line, third column
    wordTableCell = wordTable.Cell(2, 3);
    wordTableCellRange = wordTableCell.range();
    wordTableCellRange.text(&quot;World&quot;);
 
    // Enable table borders
    wordTableBorders = wordTable.borders();
    wordTableBorders.enable(true);

    // Add colored borders
    wordTableBorders.InsideLineStyle(3);
    wordTableBorders.OutsideLineStyle(5);
    wordTableBorders.OutsideColorIndex(2);
 
    // Get table row collection and add a new row
    wordTableRows = wordTable.rows();
    wordTableRows.add();
 
    // Open word
    wordApplication.visible(true);
    wordApplication.finalize();
}
</pre>




<p>Das per obigem Code erstellte Word-Dokument sieht wie folgt aus:
</p>


<p><a href="http://www.schweda.net/pictures/blogpics/ax_createwordwithtable.jpg" target="_blank"><img alt="Screenshot" height="64" src="http://www.schweda.net/pictures/blogpics/tb_ax_createwordwithtable.jpg" title="Screenshot" width="465" /></a>
</p>]]></description>
<category>Microsoft Dynamics AX (Axapta)</category>
<pubDate>Sat, 21 Dec 2013 17:32:00 +0100</pubDate>
<link>https://www.schweda.net/blog_ax.php?bid=490</link>
<comments>https://www.schweda.net/blog_ax.php?bid=490</comments>
<guid isPermaLink="true">https://www.schweda.net/blog_ax.php?bid=490</guid>
<author>heinz.schweda@schweda.net (Heinz Schweda)</author>
<wfw:commentRss>https://www.schweda.net/blog_ax.php?bid=490</wfw:commentRss>
</item>
</channel>
</rss>	
