Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms word WordProcessingML。如何为文本指定背景色?_Ms Word_Ms Office_Office Automation_Wordprocessingml - Fatal编程技术网

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,但原理是一样的