gpt4 book ai didi

c# - 使用 OpenXML SDK 2.0 在运行时累积 RunProperties

转载 作者:行者123 更新时间:2023-11-30 15:38:07 33 4
gpt4 key购买 nike

我想知道我是否可以在 Run 上累积 RunProperties

Run run = new Run(new Text("test"));
RunProperties runProperties = new RunProperties();
runProperties.AppendChild<Bold>(new Bold());
runProperties.AppendChild<Underline>(new Underline());
run.AppendChild<RunProperties>(runProperties);

在这种情况下,我只有粗体文本但没有下划线。

请帮忙

最佳答案

我试过你的例子,确实它对我来说只是粗体而不是下划线。我做了一些工作,结果是这样的:

using (WordprocessingDocument doc = WordprocessingDocument.Open(destFileName, true))
{

Run run = new Run();
RunProperties runProperties = new RunProperties();

runProperties.AppendChild<Underline>(new Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single });
runProperties.AppendChild<Bold>(new Bold());
run.AppendChild<RunProperties>(runProperties);
run.AppendChild(new Text("test"));

//Note: I had to create a paragraph element to place the run into.
Paragraph p = new Paragraph();
p.AppendChild(run);
doc.MainDocumentPart.Document.Body.AppendChild(p);
}

基本上,这改变了:

new Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single }

您必须指定所需的下划线类型,而不是将其留给下划线类的构造函数。我只是指定了 Single,它对我有用。

关于c# - 使用 OpenXML SDK 2.0 在运行时累积 RunProperties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11780353/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com