Retrieve shared formulas #67

Closed
Y-- wants to merge 0 commits from master into master
Y-- commented 2014-05-29 09:40:19 +00:00 (Migrated from github.com)

Implement 18.3.1.40

Implement 18.3.1.40
coveralls commented 2014-05-29 09:50:24 +00:00 (Migrated from github.com)

Coverage Status

Coverage increased (+0.05%) when pulling 131fa7d034 on Y--:master into c91e94dbbb on SheetJS:master.

[![Coverage Status](https://coveralls.io/builds/814365/badge)](https://coveralls.io/builds/814365) Coverage increased (+0.05%) when pulling **131fa7d0342f838d78e0941a1a78f717d5a2b3b2 on Y--:master** into **c91e94dbbbb5dfd9d5bc5db902479eebcd942a53 on SheetJS:master**.
SheetJSDev commented 2014-05-29 17:07:37 +00:00 (Migrated from github.com)

@Y-- apologies for the belated reply -- busy day :/

I just added some test files. Take a look at https://github.com/SheetJS/test_files/raw/master/formulae_test_simple.xlsx -- something looks off:

> var ws = require('./').readFile('formulae_test.xlsx').Sheets.Sheet1; Object.keys(ws).filter(function(x) { return x[0] == "C" || x[0] == "D";}).forEach(function(x) { console.log(x, ws[x].f); })
C1 A1
D1 A1
C2 A2
D2 A2
C3 A2
D3 A2 
C4 A2
D4 A2
C5 A2
D5 A2
C6 A2
D6 B6
@Y-- apologies for the belated reply -- busy day :/ I just added some test files. Take a look at https://github.com/SheetJS/test_files/raw/master/formulae_test_simple.xlsx -- something looks off: ``` > var ws = require('./').readFile('formulae_test.xlsx').Sheets.Sheet1; Object.keys(ws).filter(function(x) { return x[0] == "C" || x[0] == "D";}).forEach(function(x) { console.log(x, ws[x].f); }) C1 A1 D1 A1 C2 A2 D2 A2 C3 A2 D3 A2 C4 A2 D4 A2 C5 A2 D5 A2 C6 A2 D6 B6 ```
Y-- commented 2014-05-30 07:23:17 +00:00 (Migrated from github.com)

@SheetJSDev thanks for taking a look at my PR.
You're right the current code give only the "master" formula according to specs.
We would need to "recompute" it based on it's relative position inside the shared group.
Is there any code for that in js-xlsx already?

@SheetJSDev thanks for taking a look at my PR. You're right the current code give only the "master" formula according to specs. We would need to "recompute" it based on it's relative position inside the shared group. Is there any code for that in `js-xlsx` already?
SheetJSDev commented 2014-05-30 07:31:16 +00:00 (Migrated from github.com)

It looks like we'd need a bona-fide Excel formula parser to do this right, ideally something that converts to the parsed things format that XLS and XLSB use. The grammar for the tokens is laid out in MS-XLSB 2.5.97.88 (http://msdn.microsoft.com/en-us/library/dd946774.aspx) and MS-XLS 2.5.198.104 (http://msdn.microsoft.com/en-us/library/dd908135.aspx). I can look into this later

It looks like we'd need a bona-fide Excel formula parser to do this right, ideally something that converts to the parsed things format that XLS and XLSB use. The grammar for the tokens is laid out in MS-XLSB 2.5.97.88 (http://msdn.microsoft.com/en-us/library/dd946774.aspx) and MS-XLS 2.5.198.104 (http://msdn.microsoft.com/en-us/library/dd908135.aspx). I can look into this later
Y-- commented 2014-05-30 07:34:23 +00:00 (Migrated from github.com)

Ok great. Should we put the master formula in a other field in the meantime ?

Ok great. Should we put the master formula in a other field in the meantime ?
SheetJSDev commented 2014-05-30 07:44:59 +00:00 (Migrated from github.com)

@Y-- For now, it might make sense to add an array !shrfmla to the workbook (just like how merges are currently held) which holds the master formula as well as other relevant information.

For example, in the example, the first shared formula is:

  <c r="C2">
    <f t="shared" ref="C2:C6" si="0">A2</f>
    <v>2</v>
  </c>

In this case, we'd need to store the actual formula A2 as well as the ref C2:C6 and the original cell (the index would match the position in the shared formula array)

@Y-- For now, it might make sense to add an array `!shrfmla` to the workbook (just like how merges are currently held) which holds the master formula as well as other relevant information. For example, in the example, the first shared formula is: ``` <c r="C2"> <f t="shared" ref="C2:C6" si="0">A2</f> <v>2</v> </c> ``` In this case, we'd need to store the actual formula `A2` as well as the ref `C2:C6` and the original cell (the index would match the position in the shared formula array)
coveralls commented 2014-06-12 09:24:58 +00:00 (Migrated from github.com)

Coverage Status

Coverage increased (+4.69%) when pulling 30b976932e on Y--:master into c91e94dbbb on SheetJS:master.

[![Coverage Status](https://coveralls.io/builds/859956/badge)](https://coveralls.io/builds/859956) Coverage increased (+4.69%) when pulling **30b976932e908c5e65af7992445a836a14fa97d5 on Y--:master** into **c91e94dbbbb5dfd9d5bc5db902479eebcd942a53 on SheetJS:master**.
coveralls commented 2014-08-26 16:50:31 +00:00 (Migrated from github.com)

Coverage Status

Coverage increased (+4.93%) when pulling be824970e6 on Y--:master into c91e94dbbb on SheetJS:master.

[![Coverage Status](https://coveralls.io/builds/1131461/badge)](https://coveralls.io/builds/1131461) Coverage increased (+4.93%) when pulling **be824970e6e1039a2a647d0faafe44935af0a460 on Y--:master** into **c91e94dbbbb5dfd9d5bc5db902479eebcd942a53 on SheetJS:master**.
matthewmueller commented 2015-05-04 03:17:00 +00:00 (Migrated from github.com)

What ended up happening with this PR?

What ended up happening with this PR?
jasconius commented 2015-09-15 21:06:19 +00:00 (Migrated from github.com)

Hi, bumping this. I've made a private fork of XLSX JS and have created a true blue formula parser and resolver... and I'm just now running into this little issue... the shared formula thing is a big issue and I am wondering if anyone has any documentation about the rules that govern shared formulas and how I can make inferences from the data in the XML and generate the appropriate formulas. I'm pretty much ready to build this, I just need more data to pursue it.

Doing the corporate dance to try and get my work on parsing/resolving into your repo, not easy, but I think you guys would be quite happy with what I've created.

If I could make a request of the group, one of the most immediate barriers is the shared attribute is currently not even being parsed and added to the dictionary. If that could be done then I could do a merge and start cranking...

Hi, bumping this. I've made a private fork of XLSX JS and have created a true blue formula parser and resolver... and I'm just now running into this little issue... the shared formula thing is a big issue and I am wondering if anyone has any documentation about the rules that govern shared formulas and how I can make inferences from the data in the XML and generate the appropriate formulas. I'm pretty much ready to build this, I just need more data to pursue it. Doing the corporate dance to try and get my work on parsing/resolving into your repo, not easy, but I think you guys would be quite happy with what I've created. If I could make a request of the group, one of the most immediate barriers is the shared attribute is currently not even being parsed and added to the dictionary. If that could be done then I could do a merge and start cranking...
SheetJSDev commented 2017-02-28 11:00:50 +00:00 (Migrated from github.com)

This was addressed in 0.8.4. XLSX XLSB XLS and SpreadsheetML now parse shared and array formulae.

In XLSX, the raw shared formula is stored in the upper left cell along with a shared id si attribute. Cells referencing the formula include that si attribute. The parser calculates a delta and applies it to the relative references in the formula.

The current iteration uses a very simple regex which only fail on some special cases that can be refined with a more precise regular expression. @jasconius I originally thought a proper parser was needed but in retrospect a fine tuned regular expression can work (Excel itself prohibits defined names that potentially collide with a valid cell address).

This was addressed in 0.8.4. XLSX XLSB XLS and SpreadsheetML now parse shared and array formulae. In XLSX, the raw shared formula is stored in the upper left cell along with a shared id `si` attribute. Cells referencing the formula include that `si` attribute. The parser calculates a delta and applies it to the relative references in the formula. The current iteration uses a very simple regex which only fail on some special cases that can be refined with a more precise regular expression. @jasconius I originally thought a proper parser was needed but in retrospect a fine tuned regular expression can work (Excel itself prohibits defined names that potentially collide with a valid cell address).

Pull request closed

Sign in to join this conversation.
No description provided.