sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

Geography Data Type

Open tao opened this issue 5 years ago • 3 comments

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?

tao avatar Feb 05 '20 16:02 tao

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?

SheetJSDev avatar Feb 05 '20 20:02 SheetJSDev

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

tao avatar Feb 05 '20 22:02 tao

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.

SheetJSDev avatar Feb 05 '20 22:02 SheetJSDev