2017-01-08 23 views
0

我用下面的代碼來改變Excel圖表的datalabels在C#變化DataLabels在C#中一次

using Xl = Microsoft.Office.Interop.Excel; 
using officeState = Microsoft.Office.Core.MsoTriState; 
.... 


for (int i = 0; i < rows.Count; i++) 
{ 
    series1 = (Xl.Series)xlChart.SeriesCollection(i + 1); 
    for (int k = 0; k < cols.Count; k++) 
    { 
     Xl.DataLabel dl = series1.DataLabels(k + 1) as Xl.DataLabel; 
     dl.Font.Bold = officeState.msoTrue; 
     dl.Font.Size = 11; 
     dl.Font.Name = "Times New Roman"; 
    } 

} 

是否有可能同時更改所有datalabel字體? 謝謝

回答

0

這就是我如何得到一個系列中的數據標籤。我已經用條形圖和餅圖測試了它,它運行良好。

var series = chartObject.Chart.SeriesCollection() as Microsoft.Office.Interop.Excel.SeriesCollection; 
foreach (var ser in series) 
{ 
    var DataLabels = ((Microsoft.Office.Interop.Excel.Series)ser).DataLabels(); 
    DataLabels.Format.TextFrame2.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoTrue; 
}