I’m trying to process some Excel files (.xlsx) using Aspose Cell 6.0.0 for .NET.
The Workbook constructor throws an exception with the file I’m using. I cannot figure out what’s wrong with that file. Excel 2007 opens it
Could someone help me?
Thank in advance!
public static void OpenWorkbook(String file)
// Open Excel workbook
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
Aspose.Cells.Workbook wb = new Workbook(file, loadOptions);
Unhandled Exception: Aspose.Cells.CellsException: Invalid cell name
at Aspose.Cells.CellsHelper.CellNameToIndex(String cellName, Int32& row, Int3
at ?.?.?(XmlTextReader ?, Row ?, Int32 ?, Int32 ?)
at ?.?.?(XmlTextReader ?, Int32 ?)
at ?.?.?(XmlTextReader ?)
at ?.?.?(XmlTextReader ?)
at ?.?.?(? ?, String ?)
at Aspose.Cells.Workbook.?(Stream ?, LoadOptions ?)
at Aspose.Cells.Workbook.?(String ?, LoadOptions ?)
at Aspose.Cells.Workbook…ctor(String file, LoadOptions loadOptions)
Thanks for the sample file and code.
After an initial test, I am able to reproduce the issue as you have mentioned. I have logged a ticket with an id: CELLSNET-28521 for your issue. We will fix it soon.
We tested the new version, and effectively when we rewrite the file in 2003 format, we can read the file. But when we rewrite the file in 2010 format, the file is not well formatted against the OpenXML rules, there is still a problem with some cell names.
But for us this solutions suites.
Thanks for your support.
We (Elia) really appreciate the responsiveness of your support. Thanks to your fix, we now have a workaround for processing those damned Excel files. As mentioned by Christ, the OLE DB diver still complains when we save using the XSLX format. But using XLS will do the job.
Bruno Biebuyck (for Elia).
I have tested your file with the latest version Aspose.Cells for .NET v126.96.36.199. My approach was to load your source xlsx file and convert it into the xls file then load the xls file again to see if there any exception occurs. I found, no exception occurs. Below is my code.
string path = @“F:\Shak-Data-RW\Downloads\auction_spot_france_2011.xlsx”;
//Load the workbook xlsx file
Workbook workbook = new Workbook(path);
//But save it in xls format
workbook.Save(path + “.out.xls”, SaveFormat.Excel97To2003);
//Now load the xls file again to see if converted excel loads fine.
workbook = new Workbook(path + “.out.xls”);
I Will give you additional information, so that you understand our way of working. We receive files from third party's. We need to import those excel files into a datawarehouse. This import happens through SSIS/DTS packages, and the download of those files happens through an automated process.
We stated two problems, the first one is, when we opened a file (@ the time before the patch), we received an exception. We implemented your patch and we are able to read the file "xlsx" and write it back without any action on it as a xls file. This is fine by us. When we open the file and we rewrite the file as an xslx, the file is not readeable within our SSIS/DTS.
Some times we receive also xls files (not xlsx files) who have the same issues as the xlsx. And a rewrite of that file didn't function. To solve our issue, we implemented the following code.
Console.WriteLine("Reading Excel file : " + xlsFromFile);
var fileStream = new FileStream(xlsFromFile, FileMode.Open, FileAccess.Read);
var asposeCells = new Aspose.Cells.Workbook(xlsFromFile);
var asposeCpy = new Aspose.Cells.Workbook();
foreach (Aspose.Cells.Worksheet ws in asposeCells.Worksheets)
Console.WriteLine("Write file to : " + xlsToFile);
fileStream = new FileStream(xlsToFile, FileMode.Create, FileAccess.Write);
By copying the file into a new workbook we are able to read the file with the following T-SQL line:
select * from openrowset('Microsoft.ACE.OLEDB.12.0',
* 'Excel 12.0;HDR=YES;Database=C:\_dev\ITeam\XlsRewrite\XlsRewrite\Data\auction_spot_germany_austria_2009.xlsxaspose.xls.Copy.xls',
'select * from [Prices$]')
Hoping that this helps you to find out what happens, and how we can use this without this work arround.
When you save your workbook into xlsx format, then please follow this approach. You need to set ExportCellName property to true.
string path = @“d:\test\issue\yourFile.xlsx”;
Workbook wb = new Workbook(path);
OoxmlSaveOptions xlsxSaveOptions = new OoxmlSaveOptions(SaveFormat.Xlsx);
xlsxSaveOptions.ExportCellName = true; //Set export cell name to true to get rid of your problem
wb.Save(path + “.out.xlsx”, xlsxSaveOptions);