Get a column heading in a spreadsheet
Column headings are ordinary cells. In many workbooks, the first row contains headings such as Region or Sales; tables can also store column names in table definition parts.
Read heading cells
The cell value helper reads the first worksheet and resolves shared string indexes:
#![allow(unused)] fn main() { pub fn get_cell_values(path: &Path) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { let document = SpreadsheetDocument::new_from_file_with_settings(path, lazy_settings())?; let workbook_part = document.workbook_part()?; let shared_strings = workbook_part .shared_string_table_part(&document) .and_then(|part| { part .data_as_str(&document) .ok() .flatten() .map(extract_shared_strings) }) .unwrap_or_default(); let Some(first_sheet) = workbook_part.worksheet_parts(&document).next() else { return Ok(Vec::new()); }; let worksheet_xml = first_sheet.data_as_str(&document)?.unwrap_or_default(); Ok(extract_cell_values(worksheet_xml, &shared_strings)) } }
For a simple worksheet where row 1 contains headings, filter the returned (cell_reference, value) pairs to references ending in row 1, such as A1 or B1.
The upstream algorithm takes a target cell reference, splits it into column letters and row digits, then finds the first cell in that column by ordering cells by row index. In Rust, keep that parsing explicit: BC17 has column BC and row 17.
When a heading cell uses the shared string table (t="s"), resolve the numeric cell value through the workbook's shared string table before returning the heading text.
Table headings
SpreadsheetML tables store table column names in the table definition part:
<tableColumns count="2">
<tableColumn id="1" name="Region"/>
<tableColumn id="2" name="Sales"/>
</tableColumns>
Use worksheet cell values for visible grid headings; use table definition parts when you specifically need structured table column names.