none
C#调用Excel 11.0组件包时ChartWizard() RRS feed

  • 常规讨论

  •     如下代码:当下划线的参数为Excel.XlChartType.xlPie 时,代码正常执行,且能画出饼图,当参数换为Excel.XlChartType.xlColumnClustered 时,就会抛出异常,无法画图。换句话说,通过Excel 11.0组件包只能在Excel中画出饼图,而画不出其他类型的图表。请问有人遇到过这个问题吗?怎样解决,或者我忽略了哪个地方?Excel2003
    具体的异常信息:
    异常来自 HRESULT:0x800A03EC

    Microsoft.Office.Interop.Excel

       在 Microsoft.Office.Interop.Excel._Chart.ChartWizard(Object Source, Object Gallery, Object Format, Object PlotBy, Object CategoryLabels, Object SeriesLabels, Object HasLegend, Object Title, Object CategoryTitle, Object ValueTitle, Object ExtraTitle)

    public void ChartAdd(System.Data.DataTable dataTable, int left, int top, int chartWidth, int chartHeight, string  chartType, string startPoint)
    
            {
    
                Excel.Worksheet workSheet = (Excel.Worksheet)myWorkBook.ActiveSheet;
    
                Excel.Range range = workSheet.get_Range(startPoint ,workSheet.get_Range(startPoint,startPoint).get_Offset(dataTable.Rows.Count,dataTable.Columns.Count-1));
    
                Excel.ChartObjects chartObjects = (Excel.ChartObjects)workSheet.ChartObjects(Type.Missing);
    
                Excel.ChartObject chartObject = chartObjects.Add(left, top, chartWidth, chartHeight);
    
                try
    
                {
    
                    chartObject.Chart.ChartWizard(range, Excel.XlChartType.xlColumnClustered,Type.Missing, Excel.XlRowCol.xlColumns, 1, 1, true, "", "", "", "");        
    
                }
    
                catch (Exception e)
    
                {
    
                    throw new Exception(e.Message);
    
                }
    
            }
    
    
    2009年4月15日 10:42