Ms word WordProcessingML。如何为文本指定背景色?
我有一些代码,可以创建文档,其中包含几个段落,其中一些单词的文本颜色不同。比如:Ms word WordProcessingML。如何为文本指定背景色?,ms-word,ms-office,office-automation,wordprocessingml,Ms Word,Ms Office,Office Automation,Wordprocessingml,我有一些代码,可以创建文档,其中包含几个段落,其中一些单词的文本颜色不同。比如: using (var doc = WordprocessingDocument.Create("some-file-name", WordprocessingDocumentType.Document)) { // Add a new main document part. var mainPart = doc.AddMainDocumentPart();
using (var doc = WordprocessingDocument.Create("some-file-name", WordprocessingDocumentType.Document))
{
// Add a new main document part.
var mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document();
var body = new Body();
var paragraph = new Paragraph();
var run = new Run();
...
// append bold text
run.AppendChild(new RunProperties {Bold = new Bold(), });
run.AppendChild(new Text("some-text"));
...
// append red text
run.AppendChild(new RunProperties
{ Color = new Color {Val = "FF0000"}});
run.AppendChild(new Text("some-text"));
但是我还没有找到一种方法来添加带有彩色背景的文本。我该怎么做 让我回答自己:
背景为突出显示属性:
// yellow background sample
run.AppendChild(new RunProperties { Highlight = new Highlight { Val = HighlightColorValues.Yellow } });
run.AppendChild(new Text("some-text"));
我发现我需要在运行属性中设置。我使用的是docx4j,但原理是一样的