Possible bug in sheet.getUsedRange()

Posted by: peter on 15 September 2025, 1:07 pm EST

  • Posted 15 September 2025, 1:07 pm EST

    We noticed that getUsedRange is returning rowCount -1 for a sheet with data. Is this a bug? Sample code below:

    const URT = (GC.Spread.Sheets as any).UsedRangeType;
    const usedData = sheet.getUsedRange(URT?.all ?? URT?.data); // URT.all
    console.log("sheet data", sheet.getCsv(0, 0, 10, 10, "\n", ","), usedData.rowCount, usedData.colCount); // data for the sheet exists. rowCount is -1, colCount is 15
  • Posted 16 September 2025, 1:44 am EST

    Hi,

    This is by design and is the expected behavior.

    In SpreadJS, if you set any column width, then calling sheet.getUsedRange(GC.Spread.Sheets.UsedRangeType.all) includes GC.Spread.Sheets.UsedRangeType.axis. In this case, the returned rowCount will be -1, meaning all rows have been modified. Similarly, if you set any row height, the returned colCount will be -1, meaning all columns have been modified.

    In PivotTable, when you call myPivotTable.autoFitColumn();, it adjusts the column width, which results in the rowCount being -1 in the usedRange.

    To avoid this, you can exclude the GC.Spread.Sheets.UsedRangeType.axis from GC.Spread.Sheets.UsedRangeType.all, so that the result does not return -1:

    sheet.getUsedRange(GC.Spread.Sheets.UsedRangeType.all ^ GC.Spread.Sheets.UsedRangeType.axis);

    Regards,

    Priyam

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels