Retrieve a list of the worksheets in a spreadsheet document
Worksheet names are stored in the workbook part, not inside the worksheet parts. The workbook <sheets/> collection maps each visible workbook entry to a relationship id.
Read worksheet names
#![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)) } }
When you need the relationship ids as well as the sheet names, use related_parts_of_type at the workbook part boundary and keep those ids aligned with the r:id values in workbook XML:
#![allow(unused)] fn main() { pub fn list_worksheet_relationship_ids( 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()?; Ok( workbook_part .related_parts_of_type::<_, WorksheetPart>(&document) .map(|related| related.relationship_id().to_string()) .collect(), ) } }
The helper opens the workbook part, reads xl/workbook.xml, and extracts each <sheet name="..."/> value. The same workbook XML also contains sheetId, r:id, and optional state attributes such as hidden.
The returned list can be empty only for an invalid or unusual workbook; a well-formed spreadsheet normally has at least one sheet entry.
Workbook markup
<sheets>
<sheet name="Summary" sheetId="1" r:id="rId1"/>
<sheet name="Hidden Data" sheetId="2" state="hidden" r:id="rId2"/>
</sheets>
Use WorkbookPart::worksheet_parts(&document) when you need the actual worksheet XML. Use workbook XML when you need workbook metadata such as names and visibility state.
The workbook sheet element is metadata, not the worksheet part itself. Resolve the r:id relationship when you need to move from a listed sheet to its worksheet XML.