When I try to open a text file to a xlsx format from Aspose.Cells with this code:
Excel.Workbook workbook = new Excel.Workbook(filePath, new Excel.TxtLoadOptions(Excel.LoadFormat.Xlsx) { SeparatorString = " " });
it crashes with the exception being The file is corrupted . This is only happening since yesterday.
I feel like nothing changed that could possibly affect the Aspose.Cells library from functionning correctly.
I have searched quite a bit online, but nothing really relates to a file being corrupted when opening it.
I thought at first that the text files were the issue, but I tried creating a new text file with the text: "test test1 test2"
Even with this new file it is still telling me it is corrupted.
Any ideas what the issue could be?
Thank you for your help.
EDIT : After further review and testing, by removing the parameter new Excel.TxtLoadOptions(Excel.LoadFormat.Xlsx) { SeparatorString = " " }
It works, but the text only gets put into one cell instead of splitting it between multiple cells. Any ideas of a workaround? Thanks.
Answering my own question...
In my case I was loading the text file into a .xlsx extension due to me wanting to save the file back to xlsx after applying formatting.
Turns out that the Aspose.cells API is not able to load a .txt as xlsx. However, you can load it as a CSV than save it as an xlsx after like so:
Excel.Workbook workbook = new Excel.Workbook(filePath, new Excel.TxtLoadOptions(Excel.LoadFormat.CSV) { SeparatorString = " " });
Hope this helps someone in the future.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.