Get worksheet information from a package

Worksheet data lives in worksheet parts related from the workbook part. Use the workbook part to traverse worksheets, then read each worksheet's XML through the package.

Read worksheet XML

#![allow(unused)]
fn main() {
pub fn get_worksheet_xml(path: &Path) -> Result<Vec<String>, Box<dyn std::error::Error>> {
  let document = SpreadsheetDocument::new_from_file_with_settings(path, lazy_settings())?;
  let workbook_part = document.workbook_part()?;
  let mut worksheets = Vec::new();

  for worksheet_part in workbook_part.worksheet_parts(&document) {
    worksheets.push(
      worksheet_part
        .data_as_str(&document)?
        .unwrap_or_default()
        .to_string(),
    );
  }

  Ok(worksheets)
}
}

This returns one XML string per worksheet part. From there you can inspect <sheetData/>, dimensions, merged cells, column definitions, page setup, tables, drawings, or other worksheet-level markup.

If you need user-facing worksheet metadata, inspect the workbook sheets collection instead of only walking worksheet parts. Each sheet element carries the display name, workbook-local sheetId, relationship id, and optional visibility state. The relationship id points from the workbook part to the actual worksheet part.

#![allow(unused)]
fn main() {
pub fn list_worksheets(path: &Path) -> Result<Vec<String>, Box<dyn std::error::Error>> {
  let document = SpreadsheetDocument::new_from_file_with_settings(path, lazy_settings())?;
  let workbook_part = document.workbook_part()?;
  let workbook_xml = workbook_part.data_as_str(&document)?.unwrap_or_default();

  Ok(extract_sheet_names(workbook_xml))
}
}

Worksheet markup

<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <sheetData>
    <row r="1">
      <c r="A1" t="s"><v>0</v></c>
    </row>
  </sheetData>
</worksheet>

The order returned by worksheet_parts(&document) follows workbook relationships. If you need sheet display names or hidden state, read the workbook <sheets/> list as well.