Parsing Excel file fails with spsheet

Hey there, everyone. I'm working on a project that I would like to have file support for both ODs and Excel, and while I found a candidate in spsheet, it has had some problems.

Seeing as it has been dormant for so long, it might be understandable that you guys would wonder why I don't use calamine, and I have looked it into it, but file access is not as convenient, since I don't see a way to just grab the first sheet and the files I expect to have will only be one sheet.

Recently, I have created a fork of spsheet to resolve some of things, like Excel file reading and writing not working, and got it fixed, as well as updated the version of nom used to the 8.x version, but I'm having issues with parsing a spreadsheet.

The format of the spreadsheet is as follows:

Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9
id1 a b c d e f g h i

In this scenario, I'm grabbing data from the point of id1 to h on every row.

When I run the code to import an ODS file, it parses it as it should, but when I run the code to import it from an XLSX file, I get an error saying that it received an unexpected None at this point in the code:

let index = string_value.parse::<usize>().unwrap();
let val = shared_strings.get(index).unwrap();
Cell::str((*val).clone(), String::from(""))

However, when I changed it to the below, nothing would import at at all:

let index = string_value.parse::<usize>().unwrap();
if let Some(val) = shared_strings.get(index) {
      Cell::str((*val).clone(), String::from(""))
} else {
      Cell::str("", "")
}

Does anybody know how to deal with this?

Do you remember that shared strings are in a separate file in the XLSX archive, not in the sheet file?

I think I remember seeing something like that in the tree and thought of taking a look. I’ll give that a glance when I can.

Alright, I looked in the shared string stuff and even changing optionals there doesn’t fix it, and my changes do succeed in unit testing, which means either the data being written is not correct or something.

The Exact data I’m try to parse is something like this

FF04C3DC-F0FE-472E-8737-0F4034C049F0	2021-07-08	1260	Y	Opening Balance	Sam Hill Credit Union	Open Account	500.00  500.00	
1422CBC6-7B0B-4584-B7AB-35167CC5647B	2021-07-08		N	Gifts	Fake Street Electronics	Head set		200 300.00
BB22187E-0BD3-41E8-B3D8-8136BD700865	2021-07-08		N		Velociraptor Entertainment	Pay Day	50000 50300.00

When putting this into the matching format I mentioned about, where i is the balance field (which features the numbers 500, 300, and 50300) and having the XLSX parser run, it will not retrieve the three values, whereas, like I said before, the ODS parser functions fine.

As for how things work from what I could gather, shared strings is pulled in via a temporary file.

If you guys want to see the code being passed to the spsheet crate, it can be viewed here. I would have shared it earlier, but I hit the link limit.

Any other ideas where to look? I would have thought of doing breakpoints, but I don’t have easy way of figuring out how to do that VS Code, so that I could analyze what is going on better.

What's wrong with reader.worksheet_range_at(0) ?

I’ll give that a try on a different branch. I just didn’t think of it because the examples using that were named sheets.

Reader.sheet_names also can be used to determine the name for the range. It is ordered.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.