We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problems with reading xlsx file into aspose cells

Hello,


we have updated Aspose to new version some weeks ago, before we have version 8.9. Now we have 17.4.

With the upgrade we can´t read one special file, our customer download automatically from SAP system. Have you any idea, why aspose cannot get the excel content from file.
-> cells.MaxRow is 35
-> cells.MaxColumn is 232
In reality the file have 5 columns and 10 rows.

Here is the code:
public List<string[]> ReadExcelWorksheetInArray(byte[] excelFile, int worksheetNumber)
{
Workbook workbook = new Workbook();
List<string[]> result = new List<string[]>();

using (MemoryStream ms1 = new MemoryStream())
{
ms1.Write(excelFile, 0, excelFile.Length);
ms1.Position = 0;
workbook = new Workbook(ms1);
}

Worksheet sheet = workbook.Worksheets[worksheetNumber - 1];
if (sheet != null)
{
Cells cells = sheet.Cells;
int maxRow = cells.MaxRow;
int maxColumn = cells.MaxColumn;
object[,] cellinput = cells.ExportArray(0, 0, maxRow + 1, maxColumn + 1);

for (int rowNumber = 0; rowNumber <= maxRow; rowNumber++)
{
string[] row = new string[maxColumn + 1];
for (int columnNumber = 0; columnNumber <= maxColumn; columnNumber++)
{
if (cellinput[rowNumber, columnNumber] != null)
{
row[columnNumber] = cellinput[rowNumber, columnNumber].ToString();
}
}
result.Add(row);
}
}

return result;
}

Thanks for your support

best regards
Jens

Hi,


Thanks for the template file and sample code.

I have evaluated your template file “Test.xlsx” a bit. I found (via using Visual Basic Editor) there is another worksheet named “SAPBEXqueriesDefunct” at 0 indexed position, this worksheet is set as very hidden (so you cannot see it or make it unhide using MS Excel standard interface). Since you are accessing the worksheet using its index in your code, so you are actually accessing this worksheet rather than the worksheet named “APO Download für Prisma”. Moreover, it would be better if you could use MaxDataRow and MaxDataColumn attributes instead. Please see the following updated sample code segment which you should use and it works as expected:
e.g
Sample code:

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Worksheet<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> sheet =
workbook.Worksheets[“APO Download für
Prisma”
];
<o:p></o:p>

if (sheet != null)

{

Cells cells = sheet.Cells;

int maxRow = cells.MaxDataRow;//9 - zero based - Ok

<span style=“font-size:
10.0pt;font-family:“Courier New”;mso-no-proof:yes”> int
maxColumn = cells.MaxDataColumn;<o:p></o:p><span style=“font-family: “Courier New”; font-size: 13.3333px;”>//4 - zero based - Ok

object[,] cellinput = cells.ExportArray(0, 0, maxRow + 1, maxColumn + 1);

for (int rowNumber = 0; rowNumber <= maxRow; rowNumber++)

{

string[] row = new string[maxColumn + 1];

for (int columnNumber = 0; columnNumber <= maxColumn; columnNumber++)

{

if (cellinput[rowNumber, columnNumber] != null)

{

row[columnNumber] = cellinput[rowNumber, columnNumber].ToString();

}

}

result.Add(row);

}

}

……….


Thank you.

Thnaks for your sample, it works fine.


best regards
Jens

Hi,


Good to know that your issue is sorted out by the suggested code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.