我使用Microsoft Office Interop Excel在VS 2008 C#Project中创建饼图。
代码是:
Excel.Chart xlChart = (Excel.Chart)xlWorkBook
.Charts
.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Excel.Range xlDataRange = xlWorkSheet
.get_Range(xlWorkSheet.Cells[
nDataForDiagramRow - alToExcelInvestmentGroupNames.Count,
_nColumnsCount - 3
],
xlWorkSheet.Cells[
nDataForDiagramRow - 1,
_nColumnsCount - 2
]);
xlChart.ChartType = Excel.XlChartType.xl3DPieExploded;
xlChart.Elevation = 60;
xlChart.Rotation = 130;
xlChart.SetSourceData(xlDataRange, Type.Missing);
xlChart.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowLabelAndPercent,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing);
xlChart.Location(Excel.XlChartLocation.xlLocationAsObject, xlWorkSheet.Name);
使用方法xlChart.ApplyDataLabels
我可以看到标签和百分比,但百分比是圆的。
如何访问标签格式以显示百分比的小数部分?
答案 0 :(得分:0)
我自己创建了解决方案。
nLabel
是图表中标签集合中的标签的int号。
Excel.Series xlSeries = (Excel.Series)xlWorkBook.ActiveChart.SeriesCollection(1);
Excel.DataLabel dl = (Excel.DataLabel)xlSeries.DataLabels(nLabel);
dl.NumberFormat = "0.0%";