嗨,我是这个Microsoft.Office.Interop.Excel的新手
我有一个模板Excel文件,我想更新模板文件并用其他名称保存。 编码有效,但保留模板文件为打开状态。而且,如果我重复此过程5次,则可以看到内存中有5个templ文件保持打开状态。我可以在保存后关闭临时文件吗?
_Application excel = new _Excel.Application();
Workbook wb;
Worksheet ws;
Range range;
public Excel(string path, int sheet)
{
this.path = path;
wb = excel.Workbooks.Open(path);
ws = wb.Worksheets[sheet];
}
// Save
FileDialog saveFileDialoge = new SaveFileDialog
{
FileName = selectedPAM.PamRefNo,
DefaultExt = "xls"
};
if(saveFileDialoge.ShowDialog() == DialogResult.OK)
{
wb.SaveAs(saveFileDialoge.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
this.wb.Close(true, saveFileDialoge.FileName, Type.Missing);
this.excel.Quit();
MessageBox.Show("Saved");
}