0

我使用 Microsoft Office Interop Excel 在 VS 2008 C# 项目中创建饼图。

代码是:

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我使标签和百分比可见,但百分比是四舍五入的。

如何访问标签的格式以显示百分比的小数部分?

4

1 回答 1

0

我自己建立了解决方案。 nLabel是图表中标签集合中标签的整数。

Excel.Series xlSeries = (Excel.Series)xlWorkBook.ActiveChart.SeriesCollection(1);

Excel.DataLabel dl = (Excel.DataLabel)xlSeries.DataLabels(nLabel);

dl.NumberFormat = "0.0%";
于 2012-06-25T09:10:24.370 回答