Hi,
Is there any solution to get the last row index used in a Excel worksheet. This is to append some rows in an existing worksheet.
Many thanks
Best regards
Florent.
Hi Florent,
Just handle the EndExport event on the UltraGridExcelExport. The event args will give you the e.CurrentRowIndex.
Hi Mike,
In fact i want to load an existing workseet using Workbook.Load and find the last row used on it.
if (File.Exists(xlsFile)) workBook = Workbook.Load(xlsFile);else workBook = new Workbook();
if (workBook.Worksheets.Exists(worksheetName))worksheet = workBook.Worksheets[worksheetName];
Now i just want to append some rows at the end of the worksheet
i don't know how to find the last row index used in the worksheet.
.
Have you tried worksheet.Rows.Count?
I may be wrong and there might not be a Count property on the Rows collection.
If that's the case, then I think you would have to loop through the Rows collection and count them.I'm pretty sure this will work.
int rowCount = 0;
foreach (WorksheetRow row in worksheet.Rows) { rowCount++; }
There is a worksheet.rows.count property but it is private. It is possible to get the count value using reflection like that :
WorksheetRowCollection wk = (WorksheetRowCollection)worksheet.Rows; PropertyInfo propInfox = wk.GetType().BaseType.GetProperty("Count", BindingFlags.NonPublic | BindingFlags.Instance);int rowIndex = (int)propInfox.GetValue(wk, null);
I hoped that there was a better solution to get this value like a count public property.