I am processing some Excel files in C# using Microsoft.Office.Interop.Excel.
The files may vary in size (Rows/Columns), but the cannot and should not be too big. Sometimes I get sheets malformed by users that contain text or formatting in a Row > 1.000.000. (So content from e.g. Row 1 - 150, then loooong nothing and then one formatting in Row 1.004.504.)
You can notice these errors by looking at the tiny scroll bar indicating the very long file. When I look at the page preview on the printing dialogue, I can see it wants to print thousands of pages instead of maybe 5.
If it would only be text causing this, I could just use "Sheet.UsedRange.Rows.Count" to get the size.
This does however not work if it is caused by formatting. (To reproduce, open an emty excel file, scroll down to Row 1.000.000 and resize the row to be 1px high or add a border to one of the cells.)
Therefore instead I want to try and identify these errors by simply checking if the pages to print are above a certain number. For this I am trying to use "Sheet.PageSetup.Pages.Count" but this value does not show the same high page number as the printing dialog.
Is there any other way to reliably identify the last row/column where the user has either
Thanks for any suggestions.
Edit: As an alternative, is it a better approach to maybe read this directly from the Worksheet XML?
<row r="1045860" spans="40:40" x14ac:dyDescent="0.2">
<c r="AN1045860" s="48"/>
</row>