2012-08-02 61 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