for (var i = 0; i <= data.GetUpperBound(0); i++)
{
var tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
for (var j = 0; j <= data.GetUpperBound(1); j++)
{
var tc = new DocumentFormat.OpenXml.Wordprocessing.TableCell();
tc.Append(new DocumentFormat.OpenXml.Wordprocessing.Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data[i, j]))));
tr.Append(tc);
}
table.Append(tr);
}
我想更改表格单元格中的字体大小。你能帮我吗?我不知道他们为什么不添加单元格字体大小的属性。
要更改表格单元格的字体大小,您需要添加RunProperties
到Run
。字体大小在 a 内指定FontSize
里面的元素运行属性 https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.runproperties(v=office.15).aspx.
例如,要将所有条目更改为字体大小 18,您的代码将如下所示:
for (var i = 0; i <= data.GetUpperBound(0); i++)
{
var tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
for (var j = 0; j <= data.GetUpperBound(1); j++)
{
var tc = new DocumentFormat.OpenXml.Wordprocessing.TableCell();
var paragraph = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
var run = new DocumentFormat.OpenXml.Wordprocessing.Run();
var text = new DocumentFormat.OpenXml.Wordprocessing.Text(data[i, j]);
// your old code for reference: tc.Append(new DocumentFormat.OpenXml.Wordprocessing.Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data[i, j]))));
RunProperties runProperties1 = new RunProperties();
FontSize fontSize1 = new FontSize(){ Val = "36" };
runProperties1.Append(fontSize1);
run.Append(runProperties1);
run.Append(text);
paragraph.Append(run);
tc.Append(paragraph);
tr.Append(tc);
}
table.Append(tr);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)