Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support label cells for XLS #359

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ impl<RS: Read + Seek> Xls<RS> {
}
//0x0201 => cells.push(parse_blank(r.data)?), // 513: Blank
0x0203 => cells.push(parse_number(r.data, &self.formats, self.is_1904)?), // 515: Number
0x0205 => cells.push(parse_bool_err(r.data)?), // 517: BoolErr
0x0204 => cells.extend(parse_label(r.data, &encoding)?), // 516: Label [MS-XLS 2.4.148]
0x0205 => cells.push(parse_bool_err(r.data)?), // 517: BoolErr
0x0207 => {
// 519 String (formula value)
let val = DataType::String(parse_string(r.data, &encoding)?);
Expand Down Expand Up @@ -468,7 +469,7 @@ fn parse_sheet_metadata(
return Err(XlsError::Unrecognized {
typ: "BoundSheet8:hsState",
val: e,
})
});
}
};
let typ = match r.data[5] {
Expand All @@ -480,7 +481,7 @@ fn parse_sheet_metadata(
return Err(XlsError::Unrecognized {
typ: "BoundSheet8:dt",
val: e,
})
});
}
};
r.data = &r.data[6..];
Expand Down Expand Up @@ -645,10 +646,10 @@ fn parse_short_string(r: &mut Record<'_>, encoding: &XlsEncoding) -> Result<Stri

/// XLUnicodeString [MS-XLS 2.5.294]
fn parse_string(r: &[u8], encoding: &XlsEncoding) -> Result<String, XlsError> {
if r.len() < 2 {
if r.len() < 4 {
return Err(XlsError::Len {
typ: "short string",
expected: 2,
typ: "string",
expected: 4,
found: r.len(),
});
}
Expand All @@ -659,6 +660,23 @@ fn parse_string(r: &[u8], encoding: &XlsEncoding) -> Result<String, XlsError> {
Ok(s)
}

fn parse_label(r: &[u8], encoding: &XlsEncoding) -> Result<Option<Cell<DataType>>, XlsError> {
if r.len() < 6 {
return Err(XlsError::Len {
typ: "label",
expected: 6,
found: r.len(),
});
}
let row = read_u16(r);
let col = read_u16(&r[2..]);
let _ixfe = read_u16(&r[4..]);
return Ok(Some(Cell::new(
(row as u32, col as u32),
DataType::String(parse_string(&r[6..], encoding)?),
)));
}

fn parse_label_sst(r: &[u8], strings: &[String]) -> Result<Option<Cell<DataType>>, XlsError> {
if r.len() < 10 {
return Err(XlsError::Len {
Expand Down Expand Up @@ -786,7 +804,7 @@ fn read_rich_extended_string(
) -> Result<String, XlsError> {
if r.data.is_empty() && !r.continue_record() || r.data.len() < 3 {
return Err(XlsError::Len {
typ: "rick extended string",
typ: "rich extended string",
expected: 3,
found: r.data.len(),
});
Expand Down Expand Up @@ -1146,7 +1164,7 @@ fn parse_formula(
return Err(XlsError::Unrecognized {
typ: "PtgAttrSpaceType",
val,
})
});
}
};
let cch = rgce[1];
Expand Down