I'm using SpreadProcessing in conjunction with a TelerikSpreadsheet in a Blazor app where the user can modify a spreadsheet and click a submit button. In my submit handler I'm using the result of Worksheet.UsedCellRange to set up my loops for the purpose of validation. When the user clicks submit, I get the expected result from Worksheet.UsedCellRange and then I spin the used rows and columns and apply validation. If there are validation errors I make the cell red and then export the workbook back to a memory stream and assign the byte array back to the variable to which the spreadsheet is bound. That works fine.
The issue I'm having is that if the user clicks submit, gets validation errors, makes a change and then clicks the submit button a second time, the result I get from Worksheet.UsedCellRange includes all rows, even if only one or two rows actually have data. To narrow down the issue I removed all my validation logic so I am not making any changes to the cells before I assign the byte array, but the second time through the result of UsedCellRange still reports all rows. Am I not assigning the byte array correctly at the end of my submit method? See code:
private async Task OnSubmitAsync()
{
byte[] sheet = await _spreadsheetRef.ExportToExcelAsync();
using MemoryStream ms = new(sheet);
XlsxFormatProvider formatProvider = new();
Workbook workbook = formatProvider.Import(ms, new TimeSpan(0, 0, 5));
Worksheet worksheet = workbook.Worksheets.First();
// The first time through this is correct, second time through it reports all 200 rows are in use. Why?
CellRange cellRange = worksheet.UsedCellRange;
// Validation logic would normally go here
// Set the byte array back to the bound variable
// Should I be doing this differently?
ms.SetLength(0);
formatProvider.Export(workbook, ms, new TimeSpan(0, 0, 30));
_fileData = ms.ToArray(); // _fileData is bound to the TelerikSpreadsheet component
}