C#如何保存对Execl文件的修改?如何用浏览器显示Excel文件
问题如上,我写的代码如下:
string odbc= "dsn=report;uid=sa;pwd=123;database=master ";
string str = "select *from ft_report ";
string filepath = @ "D:\Visual Studio 2005\WebSite3\DataTest.xls ";
Excel.Application myExcel = new Excel.ApplicationClass();
myExcel.Workbooks.Open(filepath,0, false, 5,
" ", " ", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, " ",
true, false, 0, true, false, false);
Excel.Worksheet mySheet = (Excel.Worksheet)myExcel.Worksheets[1];
mySheet.Cells[2, 3] = "修改数据 ";
mySheet.SaveAs(filepath, false, false, false, false, false, false, false, false, false);
mySheet = null;
myExcel.Workbooks.Close();
myExcel = null;
当执行到mySheet.SaveAs(filepath, false, false, false, false, false, false, false, false, false);时报错,但编译通过,请高手指点。另外如何用网页方式打开Execl文件,请指教
------解决方案--------------------在save时加上Try{} Catch{}看看出错信息。ie直接就可以打开Excel
------解决方案--------------------object MissValue = System.Reflection.Missing.Value;
Book.SaveAs(strSavePath, MissValue, MissValue, MissValue, MissValue, MissValue, XlSaveAsAccessMode.xlNoChange, MissValue, MissValue, MissValue, MissValue);