Novis\Spreadsheet\Reader::SheetKind
Whether a sheet of a workbook has cells or only a chart.
Worksheetis a sheet with rows and cells.Chartsheetis a sheet that is one big chart. It has no cells.
Reader::sheets gives the kind of each sheet in a file. A workbook that you write has only worksheets. A file made in Excel can also have chart sheets.
Reader::rows on a chart sheet throws an error, because it has no rows. Check the kind first when your program reads every sheet of an upload.
Examples
Read only the sheets with cells
<?nvs// Shows how to read the rows of each sheet that has cells, and skip a sheet with only a chart.use Novis\Spreadsheet\Reader;use Novis\Spreadsheet\Workbook;
var $book = Workbook::createInMemory();$book->addSheet('North')->addRows([['Shop', 'Sales'], ['North 1', 120]]);$book->addSheet('South')->addRows([['Shop', 'Sales'], ['South 1', 200]]);var $reader = Reader::open($book->finish()->bytes ?? Core\Bytes::fill(0, 0));
// A `Chartsheet` has no rows to read. A file from Excel can have one.// This file has two worksheets, so this prints the first cell of both.foreach ($reader->sheets() as var $info) { if ($info->kind == Reader::SheetKind::Worksheet) { foreach ($reader->rows($info->position as int, { limit: 1 }) as var $row) { echo $info->name, ': ', $row->values['A'] as string, "\n"; } } else { echo $info->name, ": a chart\n"; }}North: ShopSouth: Shop