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

use nested crate to store xlsx shared strings #369

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
toolchain:
- "1.63" # MSRV
- "1.65" # MSRV
- stable
- beta
- nightly
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["excel", "ods", "xls", "xlsx", "xlsb"]
categories = ["encoding", "parsing", "text-processing"]
exclude = ["tests/**/*"]
edition = "2021"
rust-version = "1.63"
rust-version = "1.65"

[dependencies]
byteorder = "1.4"
Expand All @@ -25,6 +25,7 @@ zip = { version = "0.6", default-features = false, features = ["deflate"] }
chrono = { version = "0.4", features = [
"serde",
], optional = true, default-features = false }
nested = "0.1.1"

[dev-dependencies]
glob = "0.3"
Expand Down
15 changes: 8 additions & 7 deletions src/xlsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::io::{Read, Seek};
use std::str::FromStr;

use log::warn;
use nested::Nested;
use quick_xml::events::attributes::{Attribute, Attributes};
use quick_xml::events::{BytesStart, Event};
use quick_xml::name::QName;
Expand Down Expand Up @@ -169,7 +170,7 @@ type Tables = Option<Vec<(String, String, Vec<String>, Dimensions)>>;
pub struct Xlsx<RS> {
zip: ZipArchive<RS>,
/// Shared strings
strings: Vec<String>,
strings: Nested<String>,
/// Sheets paths
sheets: Vec<(String, String)>,
/// Tables: Name, Sheet, Columns, Data dimensions
Expand Down Expand Up @@ -718,15 +719,15 @@ impl InnerTableMetadata {
}

fn worksheet<T, F>(
strings: &[String],
strings: &Nested<String>,
formats: &[CellFormat],
mut xml: XlsReader<'_>,
read_data: &mut F,
) -> Result<Range<T>, XlsxError>
where
T: CellType,
F: FnMut(
&[String],
&Nested<String>,
&[CellFormat],
&mut XlsReader<'_>,
&mut Vec<Cell<T>>,
Expand Down Expand Up @@ -778,7 +779,7 @@ impl<RS: Read + Seek> Reader<RS> for Xlsx<RS> {
fn new(reader: RS) -> Result<Self, XlsxError> {
let mut xlsx = Xlsx {
zip: ZipArchive::new(reader)?,
strings: Vec::new(),
strings: Nested::new(),
formats: Vec::new(),
is_1904: false,
sheets: Vec::new(),
Expand Down Expand Up @@ -991,15 +992,15 @@ where
/// read sheetData node
fn read_sheet_data(
xml: &mut XlsReader<'_>,
strings: &[String],
strings: &Nested<String>,
formats: &[CellFormat],
cells: &mut Vec<Cell<DataType>>,
is_1904: bool,
) -> Result<(), XlsxError> {
/// read the contents of a <v> cell
fn read_value(
v: String,
strings: &[String],
strings: &Nested<String>,
formats: &[CellFormat],
c_element: &BytesStart<'_>,
is_1904: bool,
Expand All @@ -1016,7 +1017,7 @@ fn read_sheet_data(
Some(b"s") => {
// shared string
let idx: usize = v.parse()?;
Ok(DataType::String(strings[idx].clone()))
Ok(DataType::String(strings[idx].to_owned()))
}
Some(b"b") => {
// boolean
Expand Down