我用以下代码创建一图表,但创建后图表却存放在一新建的SHEET中,如何将它与源数据放在同一SHEET中并为其指定位置及设置大小呢?是否参数设置得不对?
Excel.Application tempExcel=new Excel.ApplicationClass();
Excel.Workbook xBook=tempExcel.Workbooks._Open(FilePath,Type.Missing ,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
Excel.Chart exlChart=new Excel.ChartClass();exlChart=(Excel.Chart)tempExcel.Charts.Add(Type.Missing,Type.Missing,1,Type.Missing);
Excel.Application tempExcel=new Excel.ApplicationClass();
Excel.Workbook xBook=tempExcel.Workbooks._Open(FilePath,Type.Missing ,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
Excel.Chart exlChart=new Excel.ChartClass();exlChart=(Excel.Chart)tempExcel.Charts.Add(Type.Missing,Type.Missing,1,Type.Missing);
sheet = (Excel.Worksheet)workBook.Sheets.get_Item(sheetIndex);
public enum SheetIndex
{
Sheet1 = 1,
Sheet2 = 2,
Sheet3 = 3,
Sheet4 = 4,
}
/// <summary>
/// 激活Sheet表
/// </summary>
public void ActiveSheet(EnumType.SheetIndex sheetindex)
{
if(((Excel.Sheets)(((Excel.ApplicationClass)(app)).Worksheets)).Count < (int) sheetindex)
{
this.Dispose();
throw new Exception("Sheet表不存在,请检查!");
}
try
{
ws = (excel.Worksheet)wb.Worksheets[sheetindex];
ws.Activate();
}
catch
{
this.Dispose();
throw new Exception("Sheet表激活错误,请检查!");
}
其中:ws,wb,为相关book及Sheet对象!