1

OpenXML WordProcessing を使用して表を作成したいと考えています。セル内のフォントをフォーマットしたい。これは私のコードです

MainDocumentPart mainDocumentPart = doc.AddMainDocumentPart();
mainDocumentPart.Document = new Document();
Body body = mainDocumentPart.Document.AppendChild(new Body());

RunProperties runHeader = new RunProperties();
RunFonts runFont = new RunFonts();
runFont.Ascii = "Lucida Sans";
runHeader.Append(runFont);                    
runHeader.Append(new Bold());
runHeader.Append(new FontSize() { Val = "16" }); 

//// Create a new table
Table tbl = new Table();

tr = new TableRow();
tc = new TableCell();

Paragraph paraHeader = new Paragraph();
Text heading_text = new Text("Company Name");
runHeader.Append(heading_text);
paraHeader.Append(runHeader);
tc.Append(paraHeader);
tr.Append(tc);
tbl.Append(tr);

body.AppendChild(tbl);

しかし、Microsoft Word を開くと、エラーが発生しました。ファイルの内容に問題があると言われています

4

2 に答える 2

2

テキストを実行プロパティに追加しています。実行に追加する必要があります。試す:

Text heading_text = new Text("Company Name");

////create the run
Run runHeaderRun = new Run();

////append the run properties and text to the run
runHeaderRun.Append(runHeader);
runHeaderRun.Append(heading_text);

////append the run to the paragraph
paraHeader.Append(runHeaderRun);

tc.Append(paraHeader);
于 2013-03-01T17:31:19.813 に答える