复制了部分代码,供你参考:
Excel.Application excelApp = null;
Excel.Workbook excelWorkbook = null;
string workbookPath=‘’;//excel文件名字
excelApp = new Excel.ApplicationClass();
excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,
false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); string currentSheet = "";//sheet页名字
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelWorkbook.Sheets.get_Item(currentSheet);
Excel.Range excelCell1 = (Excel.Range)excelWorksheet.get_Range("A3", "A3");
excelCell1.Cells[1, 1] ="testString"; Marshal.ReleaseComObject(excelCell1); excelCell1 = null; GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
if (excelWorkbook != null)
{
excelWorkbook.Close(true, Type.Missing, Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
excelWorkbook = null;
} if (excelWorkbook != null)
{
excelWorkbook.Close(false, Type.Missing, Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
excelWorkbook = null;
}
if (excelApp != null && excelApp.Workbooks.Count < 1)
{
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
excelApp = null;
}
GC.WaitForPendingFinalizers();
GC.Collect();
Excel.Application excelApp = null;
Excel.Workbook excelWorkbook = null;
string workbookPath=‘’;//excel文件名字
excelApp = new Excel.ApplicationClass();
excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,
false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); string currentSheet = "";//sheet页名字
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelWorkbook.Sheets.get_Item(currentSheet);
Excel.Range excelCell1 = (Excel.Range)excelWorksheet.get_Range("A3", "A3");
excelCell1.Cells[1, 1] ="testString"; Marshal.ReleaseComObject(excelCell1); excelCell1 = null; GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
if (excelWorkbook != null)
{
excelWorkbook.Close(true, Type.Missing, Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
excelWorkbook = null;
} if (excelWorkbook != null)
{
excelWorkbook.Close(false, Type.Missing, Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
excelWorkbook = null;
}
if (excelApp != null && excelApp.Workbooks.Count < 1)
{
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
excelApp = null;
}
GC.WaitForPendingFinalizers();
GC.Collect();
解决方案 »
- 【非C#高手不能解决!!!】
- 如何用C#接收所有UDP广播的信息,并列出发出者的IP地址?
- socket编程
- Wince下ListView添加CheckBox以后,选中CheckBox,如何得到该行的索引号?
- 在C#中, OleDbDataReader dr运行时不读,求解!!!
- C#的函数能返回一个数组吗?
- Webform中TreeView的节点从XML中去数据的问题?
- 在c#中如何将1024*768环境下的全屏图片,在800*600环境下显示出现问题,急!!在线等
- 在IE11 下面 js window.showModalDialog返回值为undefined
- 我刚学C#,有问题要问!大家帮忙!
- DATASET转换成XML的问题
- 请教一个Double.ToString()的问题,求解答 速结分
图表数据的来源的EXCEL中的数据,用数组对数据进行处理,图表自动跟着变化
有这个方法:SetSourceData(range)
我通过 WorkSheet.ChartObject(0).Chart.SetSourceData(range) ;
调用失败?系统包 com异常。
谁用过啊?