Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 5 additions & 12 deletions src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,8 @@ impl<RS: Read + Seek> Xls<RS> {
// FilePass (MS-XLS 2.4.117)
0x002F if read_u16(r.data) != 0 => return Err(XlsError::Password),
// CodePage (MS-XLS 2.4.52)
0x0042 => {
if self.options.force_codepage.is_none() {
encoding = XlsEncoding::from_codepage(read_u16(r.data))?;
}
0x0042 if self.options.force_codepage.is_none() => {
encoding = XlsEncoding::from_codepage(read_u16(r.data))?;
}
// RRTabId (MS-XLS 2.4.241)
0x013D => {
Expand All @@ -355,10 +353,8 @@ impl<RS: Read + Seek> Xls<RS> {
self.metadata.sheets.reserve(sheet_len);
}
// DateMode (MS-XLS 2.4.77)
0x0022 => {
if read_u16(r.data) == 1 {
self.is_1904 = true;
}
0x0022 if read_u16(r.data) == 1 => {
self.is_1904 = true;
}
// Format (MS-XLS 2.4.126)
0x041E => match parse_format(&mut r, &encoding, biff) {
Expand Down Expand Up @@ -778,11 +774,8 @@ fn parse_mul_rk(
});
}

let mut col = col_first as u32;

for rk in r[4..r.len() - 2].chunks(6) {
for (col, rk) in (col_first as u32..).zip(r[4..r.len() - 2].chunks(6)) {
cells.push(Cell::new((row as u32, col), rk_num(rk, formats, is_1904)));
col += 1;
}
Ok(())
}
Expand Down
19 changes: 10 additions & 9 deletions src/xlsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,11 +1903,9 @@ where
loop {
xml_buf.clear();
match xml.read_event_into(xml_buf) {
Ok(Event::Start(e)) if e.local_name().as_ref() == b"r" => {
if rich_buffer.is_none() {
// use a buffer since richtext has multiples <r> and <t> for the same cell
rich_buffer = Some(String::new());
}
Ok(Event::Start(e)) if e.local_name().as_ref() == b"r" && rich_buffer.is_none() => {
// use a buffer since richtext has multiples <r> and <t> for the same cell
rich_buffer = Some(String::new());
}
Ok(Event::Start(e)) if e.local_name().as_ref() == b"rPh" => {
is_phonetic_text = true;
Expand Down Expand Up @@ -2255,10 +2253,13 @@ fn replace_cell_names(s: &str, offset: (i64, i64)) -> Result<String, XlsxError>
if !in_quote && (c.is_ascii_alphanumeric() || c == b'$' || c == b':') {
token_end = i + 1;
} else {
if token_start < token_end
&& offset_range(&bytes[token_start..token_end], offset, &mut res).is_err()
{
res.extend(&bytes[token_start..token_end]);
if token_start < token_end {
let next_is_paren = c == b'(';
if next_is_paren
|| offset_range(&bytes[token_start..token_end], offset, &mut res).is_err()
{
res.extend(&bytes[token_start..token_end]);
}
}
res.push(c);
token_start = i + 1;
Expand Down
Binary file added tests/issue644.xlsx
Binary file not shown.
Binary file added tests/issue_644.xlsx
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,15 @@ fn issue_553_non_ascii_shared_formula() {
.all(|(_, _, x)| x == r#"IF(ROW()>5,"한글","영어")"#))
}

#[test]
fn issue_644_shared_formula_function_names() {
let mut excel: Xlsx<_> = wb("issue644.xlsx");
let formula = excel.worksheet_formula("Sheet1").unwrap();
for (row, _, f) in formula.cells() {
assert_eq!(f, &format!("LOG10(ABS(A{})+1)", row + 1));
}
}

#[test]
fn non_monotonic_si_shared_formula() {
// This excel has been manually edited so that the si numbers do not monotonically increase (si
Expand Down
Loading