SheetJS / sheetjs

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs
https://sheetjs.com/
Apache License 2.0
35.17k stars 7.99k forks source link

Geography Data Type #1733

Open tao opened 4 years ago

tao commented 4 years ago

I'm trying to read a Geography Cell and I'm having trouble getting the value.

When I parse the excel to json, the cell is returned as {t: "e", v: 15, w: "#VALUE!"}.

How can I get the country from these linked data type cells?

SheetJSDev commented 4 years ago

Most likely the file actually stores an error in the cell and Excel recomputes the value when you open the file. Can you share a sample file?

tao commented 4 years ago

Sure, when you view the file in Excel it shows the country with a little map prefixed.

Screenshot 2020-02-05 at 22 16 16

Countries.xlsx

SheetJSDev commented 4 years ago

So to be clear, this library reads whatever data is stored in the file. It doesn't attempt to perform Excel calculations (we actually have a paid component to handle calculating formula expressions, but that's not the thrust of the issue here).

For example, "Cambodia" is cell B2. The raw xml stored in the file (after prettifying with xmllint --format) for row 2 is:

    <row r="2" spans="1:3" x14ac:dyDescent="0.2">
      <c r="A2" s="2" t="s">
        <v>4</v>
      </c>
      <c r="B2" s="2" t="e" vm="1">
        <v>#VALUE!</v>
      </c>
      <c r="C2" s="2">
        <v>2017</v>
      </c>
    </row>

Cell B2 is very clearly stored with the #VALUE! error, and t="e" notes that the cell is an error cell.

Note: By default, XLSX uses a shared string table, and the "4" in cell A2 is the string at index 4 from the table (which happens to be "Activity One"). C2 is of course the literal number 2017

There may be a way to grab the name "Cambodia" from the value metadata, so we'll keep the issue open, but for now it's behaving as expected.