我有以下函数将csv文件转换为xls文件。
…
Application objExcel = new Application();
Workbooks objBooks = (Workbooks)objExcel.Workbooks;
object objOpt = System.Reflection.Missing.Value;
try
{
objBooks.OpenText(inputPathNFileName, XlPlatform.xlWindows, 1, XlTextParsingType.xlDelimited, XlTextQualifier.xlTextQualifierDoubleQuote,
false, false, false, true, false, false, objOpt, objOpt, objOpt, objOpt, objOpt, objOpt, objOpt);
Workbook objBook = objExcel.ActiveWorkbook;
objBook.SaveAs(outPathNFileName, XlFileFormat.xlWorkbookNormal, objOpt, objOpt, objOpt, objOpt, XlSaveAsAccessMode.xlNoChange, objOpt, objOpt, objOpt, objOpt, objOpt);
objBook.Close(false, objOpt, objOpt);
objExcel.Quit();
releaseObject(objBook);
releaseObject(objBooks);
releaseObject(objExcel);
}
catch (Exception e)
{
…
}
现在我的问题是如果我的csv文件有超过65,536行,我会在SaveAs步骤收到一条警告信息,65,536之后的所有行都将被删除。警告消息是“此工作簿包含所选格式的行和列限制之外的单元格中的数据。超过256(IV)列65,536行的数据将不会被保存。"
如何解决这个问题,以便对我的csv文件的行/列没有限制?
答案 0 :(得分:1)
我在这里找到了这个帮助, Excel Interop Save as is giving compatibility checker in excel 2007 我尝试了解决它解决问题的解决方案。
if (Convert.ToDouble(objExcel.Version) > 11.0)
{
objBook.SaveAs(outPathNFileName, 51, objOpt, objOpt, objOpt, objOpt, XlSaveAsAccessMode.xlNoChange, objOpt, objOpt, objOpt, objOpt, objOpt);
}
else
{
objBook.SaveAs(outPathNFileName, 56, objOpt, objOpt, objOpt, objOpt, XlSaveAsAccessMode.xlNoChange, objOpt, objOpt, objOpt, objOpt, objOpt);
}