c# 导出数据到Excel程序关闭后 进程中有个EXCEL进程怎么自动关闭
程序如下[code=csharp]privatevoidbutton3_Click(objectsender,EventArgse){Microsoft.Office.I...
程序如下
[code=csharp]
private void button3_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Application.Workbooks.Add(true);
Microsoft.Office.Interop.Excel.Workbooks books = (Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook book = (Microsoft.Office.Interop.Excel.Workbook)(books.Add(Type.Missing));
Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.ActiveSheet;
sheet.Name = "订单信息";
for (int i = 0; i <= 5; i++)
{
excel.Cells[1, i + 1] = dataGridView1.Columns[i].HeaderText;
}
for (int i = 0; i <= allrows; i++)
{
for (int j = 0; j <= 5; j++)
{
excel.Cells[i + 2, j + 1] = alldingdan[i, j];
}
}
[/code]
Range allColumn = excel.Columns;
allColumn.AutoFit();
string morenlujing = AppDomain.CurrentDomain.BaseDirectory;
MessageBox.Show(morenlujing + "");
System.IO.File.Delete(morenlujing + "订单信息.xls");
sheet.SaveAs(morenlujing + "订单信息.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing);
book.Close(false, Type.Missing, Type.Missing);
books.Close();
excel.Quit();
} 展开
[code=csharp]
private void button3_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Application.Workbooks.Add(true);
Microsoft.Office.Interop.Excel.Workbooks books = (Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook book = (Microsoft.Office.Interop.Excel.Workbook)(books.Add(Type.Missing));
Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.ActiveSheet;
sheet.Name = "订单信息";
for (int i = 0; i <= 5; i++)
{
excel.Cells[1, i + 1] = dataGridView1.Columns[i].HeaderText;
}
for (int i = 0; i <= allrows; i++)
{
for (int j = 0; j <= 5; j++)
{
excel.Cells[i + 2, j + 1] = alldingdan[i, j];
}
}
[/code]
Range allColumn = excel.Columns;
allColumn.AutoFit();
string morenlujing = AppDomain.CurrentDomain.BaseDirectory;
MessageBox.Show(morenlujing + "");
System.IO.File.Delete(morenlujing + "订单信息.xls");
sheet.SaveAs(morenlujing + "订单信息.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing);
book.Close(false, Type.Missing, Type.Missing);
books.Close();
excel.Quit();
} 展开
2个回答
展开全部
1、应该有个application实例,请销毁
2、如果实在不行,就用进程杀一下
2、如果实在不行,就用进程杀一下
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询