C# 在excel中插入数据

来源:百度知道 编辑:UC知道 时间:2024/07/04 01:59:04
object missing = Missing.Value;
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Application.Workbooks._Open("D:\\入库车辆配置信息.xls", 3, false, missing, missing, missing, missing, missing, missing, missing, missing, missing, true);
excel.Visible = true; ; ;
excel.Cells[n, 1] = n;
excel.Cells[n, 2] = "" + rkrq + "";
excel.Cells[n, 3] = "" + ccbh + "";
excel.Cells[n, 4] = "" + clxh + "";
excel.Cells[n, 112] = "" + zjh + "";
excel.Cells[n, 113] = "" + tsy + "";
excel.Application.Workbooks.Close();
用如上语句在excel中插入数据后,系统自动打开了excel表格,并提示是否保存,但点击保存时始终保存不上,不知道为什么?怎样才能让保存成功呢

wb.SaveCopyAs(outputFile);outputFile为文件名
try
{
wb.Saved = true;

excelapp.UserControl = false;
}
catch (System.Exception ex)
{
throw new Exception(ex.ToString());
}

excel.Application.Workbooks.Close(true);应该有个参数控制。true是保存。false不保存

你在度一下吧,我试了可以保存。