2012-08-02 63 views
2

我在想,如果我能在Run堆积的RunProperties与OpenXML的SDK 2.0

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

累积RunProperties在这种情况下,我只得到了粗体字,但不是下划线。

请帮

回答

3

我想你的例子,实际上它只是做了大胆的我,而不是强调。我的工作有点,并结束了与此:

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 }

你必须指定要下划线的类型,而不是仅仅把它留给下划线类的构造函数。我只是指定“单一”,它为我工作。

享受,

+0

感谢您的帮助! – Aelios 2012-08-27 07:14:20