【发布时间】:2013-12-23 05:24:42
【问题描述】:
我正在打开一个 xlsx 文件并将每张工作表保存到一个 csv 文件中。
这里是保存的相关代码:
int i=0;
foreach (Excel.Worksheet s in app.ActiveWorkbook.Sheets)
{
s.Select(true); // Error here
String outfile = outputpath + "("+i+")" + outputfilename + ".csv";
wkb.SaveAs(outfile, Excel.XlFileFormat.xlCSVMSDOS);
++i;
}
输出文件名或路径没有问题,输出文件不存在。它保存前两张纸然后崩溃。我尝试了一个包含 4 张纸的不同输入文件,它工作得很好,所以它与输入文件有关。
例外情况:
System.Runtime.InteropServices.COMException was unhandled
HResult=-2146777998
Message=Exception from HRESULT: 0x800AC472
Source=ExcelXlsx2Csv
ErrorCode=-2146777998
StackTrace:
at Microsoft.Office.Interop.Excel._Worksheet.Select(Object Replace)
at ExcelXlsx2Csv.Program.Main(String[] args) in c:\Users\Edward\Documents\Visual Studio 2013\Projects\ExcelXlsx2Csv\ExcelXlsx2Csv\Program.cs:line 109
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
感谢任何提示!
【问题讨论】:
-
你具体遇到了什么错误???
-
LOL 我刚刚运行了它,它把它们全部保存了下来。删除文件后再次运行它,它停在第二张纸上!错误是“'System.Runtime.InteropServices.COMException' 类型的未处理异常发生在...附加信息:来自 HRESULT 的异常:0x800AC472”
-
Google“excel 错误 50290”,点击率很高。