Saturday, 15 March 2014

c# - How to repair an excel file? -



c# - How to repair an excel file? -

i have excel file contains 4 worksheets. outer scheme sends excel files daily , programme reads stores info db. have 3 files may have been corrupted when programme tries read files gives error "external table not in expected format." when seek open files in office interface returns me excel found ureadable content in file.xlsx want recover contents of workbook? etc...

when start programme after repaired file office excel , save again, works. need repair files before programme starts read. there way repair excel files office does?

i using microsoft.ace.oledb.12.0;

you can utilize excel interop open file , repair excel does. can't utilize programme on machine without ms office. may seek 3rd party libraries like:

http://closedxml.codeplex.com/ http://code.google.com/p/excellibrary/ http://simpleooxml.codeplex.com/

the code excel interop follows:

missing missing = missing.value; application excel = new application(); workbook workbook = excel.workbooks.open(sourcefilepath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, xlcorruptload.xlrepairfile); workbook.saveas(savedfile, xlfileformat.xlworkbookdefault, missing, missing, missing, missing, xlsaveasaccessmode.xlexclusive, missing, missing, missing, missing, missing); workbook.close(true, missing, missing);

c# excel

No comments:

Post a Comment