本文介绍了打开XML更改表的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);
}

我想更改表格单元格中的字体大小.你能帮我吗?我不知道为什么他们没有为单元字体大小添加属性.

I want to change fontsize in table cell. Can you help me with that? I don't know why they didn't add a property for cell fontsize.

推荐答案

要更改表单元格的字体大小,您需要在Run上添加RunProperties.在FontSize元素内指定字体大小. rel ="noreferrer">运行属性.

To change the fontsize of a table cell, you need to add a RunProperties to the Run. The fontsize is specified inside a FontSize element inside that RunProperties.

例如,将所有条目更改为fontsize 18,您的代码将如下所示:

For example to change all of your entries to fontsize 18, your code would look like:

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);
}

这篇关于打开XML更改表的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:49