使用ooxml C#在word表中填充数据

时间:2018-07-04 11:34:26

标签: c# openxml

我们有一个单词模板,其中有一张桌子。 我们想阅读此表并使用开放XML填写其中的一些值。 我们正在使用C#。

MainDocumentPart mainPart = wordDocument.MainDocumentPart;

// Set the font to Arial to the first Run.
// Use an object initializer for RunProperties and rPr.
RunProperties rPr = new RunProperties(new RunFonts() { Ascii = "Arial" }, new FontSize() { Val = "16" }, new Justification() { Val = JustificationValues.Right });

//Run r1 = wordOpendoc.MainDocumentPart.Document.Descendants<Run>().First();
//r1.PrependChild<RunProperties>(rPr);

// Save changes to the MainDocumentPart part.
//wordOpendoc.MainDocumentPart.Document.Save();

//======== I know in our HEADER.DOCX second header has a table ======== //
Table headerTable = (Table)mainPart.HeaderParts.ElementAt(2).Header.FirstChild;
headerTable.Append();
// Find the first row in the table.
TableRow row = headerTable.Elements<TableRow>().ElementAt(0);

// Find the second cell in the row.
TableCell cell = row.Elements<TableCell>().ElementAt(1);


Paragraph p = cell.Elements<Paragraph>().FirstOrDefault();
//RunProperties runProp = new RunProperties(new RunFonts() {Ascii = "Arial" },new FontSize() {Val = "16" });

Run r2 = p.AppendChild(new Run());
r2.Append(rPr);
r2.AppendChild(new Text(iDocxHeaderData.Rows[0]["OfficeAddress"] .ToString()));

0 个答案:

没有答案