2012-01-24 38 views

回答

3

是的,這是可能的。一種方法是格式化將要插入到SharedStringTable中的值。這個片段將創建你上面的例子:

 // Creates an SharedStringItem instance and adds its children. 
     public SharedStringItem GenerateSharedStringItem() 
     { 
      SharedStringItem sharedStringItem1 = new SharedStringItem(); 

      Run run1 = new Run(); 

      RunProperties runProperties1 = new RunProperties(); 
      Bold bold1 = new Bold(); 
      Underline underline1 = new Underline(); 
      FontSize fontSize1 = new FontSize(){ Val = 11D }; 
      Color color1 = new Color(){ Theme = (UInt32Value)1U }; 
      RunFont runFont1 = new RunFont(){ Val = "Calibri" }; 
      FontFamily fontFamily1 = new FontFamily(){ Val = 2 }; 
      FontScheme fontScheme1 = new FontScheme(){ Val = FontSchemeValues.Minor }; 

      runProperties1.Append(bold1); 
      runProperties1.Append(underline1); 
      runProperties1.Append(fontSize1); 
      runProperties1.Append(color1); 
      runProperties1.Append(runFont1); 
      runProperties1.Append(fontFamily1); 
      runProperties1.Append(fontScheme1); 
      Text text1 = new Text(); 
      text1.Text = "Project Name:"; 

      run1.Append(runProperties1); 
      run1.Append(text1); 

      Run run2 = new Run(); 

      RunProperties runProperties2 = new RunProperties(); 
      FontSize fontSize2 = new FontSize(){ Val = 11D }; 
      Color color2 = new Color(){ Theme = (UInt32Value)1U }; 
      RunFont runFont2 = new RunFont(){ Val = "Calibri" }; 
      FontFamily fontFamily2 = new FontFamily(){ Val = 2 }; 
      FontScheme fontScheme2 = new FontScheme(){ Val = FontSchemeValues.Minor }; 

      runProperties2.Append(fontSize2); 
      runProperties2.Append(color2); 
      runProperties2.Append(runFont2); 
      runProperties2.Append(fontFamily2); 
      runProperties2.Append(fontScheme2); 
      Text text2 = new Text(){ Space = SpaceProcessingModeValues.Preserve }; 
      text2.Text = " ALLAN"; 

      run2.Append(runProperties2); 
      run2.Append(text2); 

      sharedStringItem1.Append(run1); 
      sharedStringItem1.Append(run2); 
      return sharedStringItem1; 
     } 

您可以插入到SharedStringTable,然後設置單元格的值是在這個插入的SharedStringTable索引。

可能還有一些其他的參考資料,我忘了包括可能在StylesPart中定義的參考。我建議在空白的Excel文檔中創建此示例,然後使用Open XML Productivity Tool來查看XML。該工具還將爲您提供上述我提供的代碼。它應該給你一個下一步走向的大方向。

相關問題