What can make UsedCellRange to give bad values?

1 Answer 66 Views
Spreadsheet
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Ian asked on 03 May 2023, 02:46 PM

I'm doing lots of updates and deletes in my Spreadsheet, but the UseCellRange parameter doen't seem to get updated.

How is it calculated?

I don't really want to create my own version of it, but I can't seem to make it accurate.

Even when I can see that rows are empty, it thinks they have some content, then those blank rows get processed when they should not.

Any ideas?

1 Answer, 1 is accepted

Sort by
0
Aleks
Telerik team
answered on 04 May 2023, 02:38 PM

Hello Ian,

I have tried replicating your case with a basic approach and from my understanding, it seems like the formatting could be the reason UsedCellRange is not updated correctly.

The UsedCallRange takes into account all the formatting and value set in the cell. By setting a value and formatting a cell, then deleting only the cell's value, the formatting still exists. So, in order to be sure that the CellSelection is empty you can use the clear method by passing ClearType.All - selection.Clear(ClearType.All);

Please have a look at the example code:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets.Add();

CellSelection selection = worksheet.Cells[1, 1];
selection.SetValue("Hello RadSpreadProcessing");
selection.SetIsBold(true);
CellRange usedCellRange = worksheet.UsedCellRange;
selection.Clear(ClearType.All);

// Assert is false
bool isBold = selection.GetIsBold().Value;
// Assert is empty
CellRange newCellRange = worksheet.UsedCellRange;

I hope this solution helps but if this is not the case, please provide us with more information so we can further investigate.

Regards,
Aleks
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Spreadsheet
Asked by
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Aleks
Telerik team
Share this question
or