简体   繁体   English

无法打开使用excelLibrary生成的excel文件

[英]Can't open excel file generated with excelLibrary

I'm using excelLibrary to programatically create excel files but I get a file format error when I try to open the generated files in Microsoft Office Excel. 我正在使用excelLibrary以编程方式创建excel文件,但是当我尝试在Microsoft Office Excel中打开生成的文件时出现文件格式错误。

I've seen this has been reported but there's still no answer about it. 我已经看到这已被报道,但仍然没有答案。

I use Office 2010 and I'm able to open any other .xls (97-2003 file format) but the ones generated with excelLibrary. 我使用Office 2010,我可以打开任何其他.xls(97-2003文件格式),但使用excelLibrary生成。 I've also tried Open Office and still can't open the generated file. 我也尝试过Open Office,但仍无法打开生成的文件。 I haven't tried to open them in Office 97-2003. 我没有尝试在Office 97-2003中打开它们。

Just try the sample code to reproduce the error. 只需尝试示例代码即可重现错误。

Have anybody found how to use the library and not run into this problem? 有没有人找到如何使用该库而不是遇到这个问题?

Found a solution : 找到了解决方案:

string filename = "c:\Test.xls";
Workbook workbook = new Workbook();
Worksheet sheet = new Worksheet("Test")
workbook.Worksheets.Add(sheet)

for(int i = 0;i < 100; i++)
      sheet.Cells[i,0] = new Cell("");

workbook.save(filename);

The problem is that Office 2010 doesn't support it unless there are 100 or more Cells Filled. 问题是Office 2010不支持它,除非有100个或更多单元格填充。

My work around was to have it fill 100 cells in a for loop with "". 我的工作是让它用“”填充for循环中的100个单元格。 That way it gets it's 100 cell count in and then it works just fine. 这样它就可以获得100个细胞计数,然后就可以了。

Reference : here 参考: 这里

Unfortunately excel file exported with excelLibrary are not compatible with office 2010 Excel, this is an already reported issue but seems that the library development is no longer active . 不幸的是,使用excelLibrary导出的excel文件与office 2010 Excel不兼容,这是一个已报告的问题,但似乎库开发不再有效。

I've switched to NPOI . 我已切换到NPOI

Since the sheet name is not given properly, it was throwing that error. 由于没有正确给出工作表名称,因此抛出了该错误。

Once we give the sheet a name, it will work properly. 一旦我们给表单一个名字,它就会正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM