Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

c# - 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.

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.

Just try the sample code to reproduce the error.

Have anybody found how to use the library and not run into this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

Reference : here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...