我需要从视图列表中导出excel,我使用了这段代码
Excel.Application app = new Excel.Application();
//app.Visible = true;
Excel.Workbook wb = app.Workbooks.Add(1);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
int i = 1;
int i2 = 1;
foreach (ListViewItem lvi in lvLogs.Items)
{
i = 1;
foreach (ListViewItem.ListViewSubItem lvs in lvi.SubItems)
{
ws.Cells[i2, i] = lvs.Text;
i++;
}
i2++;
}
wb.SaveAs(@"C:\1\myExcel.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
wb.Close(false, Type.Missing, Type.Missing);
app.Quit();
}
现在我需要在没有任何消息的情况下覆盖excel文件,我需要每10分钟执行一次此操作。
答案 0 :(得分:26)
尝试这个。
app.DisplayAlerts = false;
wb.SaveAs(@"C:\1\myExcel.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
workbook.Close();
app.Quit();