DocX を使ってみる - ひっそりと生きるプログラマのブログ
先日に続き面白がって、他にも色々と試してみました。
※といってもあまり多くは出来ていませんがorz
以下のようなコードでヘッダーやフッター、
グラフに表形式の出力などができます。
using (var document = DocX.Create(file.FullName)) { // ヘッダーの追加 document.AddHeaders(); var headerParagraph = document.Headers.odd.InsertParagraph(); headerParagraph.Append("Header text"); headerParagraph.Alignment = Alignment.center; // フッターの追加 document.AddFooters(); var footerParagraph = document.Footers.odd.InsertParagraph(); footerParagraph.Alignment = Alignment.center; footerParagraph.Append("Footer text"); // テキストの出力 document.InsertParagraph("文字列を出力します。"); // 3 * 3 の表形式を生成 Table table = document.AddTable(3, 3); table.Rows[0].Cells[0].Paragraphs.First().Append("左上"); table.Rows[2].Cells[2].Paragraphs.First().Append("右下"); document.InsertTable(table); // チャートの作成 PieChart chart = new PieChart(); chart.AddLegend(ChartLegendPosition.Bottom, false); // Mounth と Money という名前のプロパティを持つクラスのリスト List<ChartData> company2 = ChartData.CreateCompanyList2(); // Create and add series Series s = new Series("Apple"); s.Bind(company2, "Mounth", "Money"); chart.AddSeries(s); // Insert chart into document document.InsertParagraph("Diagram").FontSize(20); document.InsertChart(chart); document.Save(); } Console.ReadKey(); }