The following code uses an existing statistical graph Excel file, loads the file, sets the value of an item and the representation of the chart, and then saves it to another Excel file. If you are vs2005+office2003, you can also choose to use Visual Studio Tools for office.
Excel.Application m_objexcel = null;
Excel._workbook m_objbook = null;
Excel._chart m_objchart = null;
Excel.chartgroup m_objchartgroup = null;
Excel.series m_objseries = null;
Object m_objopt = System.Reflection.Missing.Value;
Try
{
M_objexcel = new Excel.Application ();
M_objbook = M_objExcel.Workbooks.Open ("Z:\\book11.xls", m_ Objopt, m_objopt, m_objopt, m_objopt, m_objopt, m_objopt, m_objopt, m_objopt, m_objopt, m_objopt, m_objOpt, m_objOpt); > M_objchart = (Excel._chart) m_objExcel.Charts.get_Item (1);
M_objchart.barshape = Excel.XlBarShape.xlCylinder;
M_objchartgroup = (excel.chartgroup) m_objchart.chartgroups (1);
M_objseries = (excel.series) m_objchartgroup.seriescollection (1);
M_objseries.values = 456;
M_objexcel.displayalerts = false;
m_objBook.SaveAs ("Z:\\book2.xls", m_objopt, m_objopt,
m_objopt, m_objopt, m_objopt, Excel.XlSaveAsAccessMode.xlNoChange,
m_objopt, m_objopt, m_objopt, m_objopt); }
CATCH (Exception ex)
{
MessageBox.Show (ex. message);
}
Finally
{
M_objbook.close (m_objopt, m_objopt, m_objopt);
M_objExcel.Workbooks.Close ();
M_objexcel.quit ();
System.Runtime.InteropServices.Marshal.ReleaseComObject (m_objbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject (m_objexcel);
M_objbook = null;
M_objexcel = null;
GC. Collect ();
this. Close ();
}