0
我写了一个方法,它从DataGridView获取所有单元格并将它们复制到Excel工作簿中。保存excel文件时抛出异常
这一切工作正常和丹迪,直到我到达我实际保存它的部分。
这里是保存它的代码:
//Saves the Workbook to the specified path
excelWorkbook.ActiveWorkbook.SaveCopyAs(pathToSave);
excelWorkbook.ActiveWorkbook.Saved = true;
//Close the workbook
excelWorkbook.Quit();
和异常被抛出:
Microsoft Office Excel cannot access the file 'C:\Users\TheGateKeeper\Desktop\New folder'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
这是我第一次使用这个类的工作,所以我可能会搞乱的东西向上。
另外,作为一个旁注有哪些呢:
excelWorkbook.ActiveWorkbook.Saved = true;
吗?
谢谢。
'C:\用户\ TheGateKeeper \桌面\新建文件夹' 是目录。你如何设置excel文件名? – 2012-03-06 18:24:53
Doh!该interlop类保存为什么扩展? – TheGateKeeper 2012-03-06 18:28:56
1.什么是变量pathToSave的值? 2.目录是否存在“C:\ Users \ TheGateKeeper \ Desktop \ New文件夹”? – 2012-03-06 18:45:42