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. I've also tried Open Office and still can't open the generated file. I haven't tried to open them in Office 97-2003.
我使用Office 2010,我可以打开任何其他的.xls(97-2003文件格式),但是使用excelLibrary生成的文件。我也尝试过Open 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?
有人找到如何使用图书馆而不遇到这个问题吗?
3 个解决方案
#1
39
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 "". That way it gets it's 100 cell count in and then it works just fine.
我的工作是让它在一个for循环中填满100个单元格。这样它就能得到100个细胞计数然后它就能正常工作了。
Reference : here
参考:
#2
5
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了。
#3
-1
Since the sheet name is not given properly, it was throwing that error.
由于没有正确地给出表单名称,所以它抛出了这个错误。
Once we give the sheet a name, it will work properly.
一旦我们给纸起个名字,它就会正常工作。
#1
39
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 "". That way it gets it's 100 cell count in and then it works just fine.
我的工作是让它在一个for循环中填满100个单元格。这样它就能得到100个细胞计数然后它就能正常工作了。
Reference : here
参考:
#2
5
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了。
#3
-1
Since the sheet name is not given properly, it was throwing that error.
由于没有正确地给出表单名称,所以它抛出了这个错误。
Once we give the sheet a name, it will work properly.
一旦我们给纸起个名字,它就会正常工作。