Access defined names and assigned values #83
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#83
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
Congrats on your project.
I am trying to obtain all values and formulas of a file.
I have managed to get it to work, however some formulas use defined names instead of cells.
For example:
works well, A2=A1
doesn't work , A2=First_Value, where the name "First_Value" is assigned to A1
Is there a way to get all the defined names and assignations? Or each cell formula with the assigned value instead of the name?
Best Regards
João Bernardino
@developergdd thanks for reaching out! (It kinda sucks that github makes you register in order to submit issues -- we should find a better issue tracker).
Right now the defined names are not captured. If you want to hack on this, the data is contained in the definedNames section of the workbook xml. For example the relevant XML in https://github.com/SheetJS/test_files/blob/master/defined_names_simple.xlsx?raw=true is:
The relevant code segment is in the parse_ws_xml function https://github.com/SheetJS/js-xlsx/blob/master/bits/77_wbxml.js#L53-L57.
If you would prefer to wait, I will push a fix in the next update
Hi,
Since this functionality, to read XLSX's files, is part of a long project we will probably wait for that next update.
Thank you for the interest in the issue and for the fast reply
Hello developergdd,
Can you comment on how you grabbed your values from your excel sheet? I am working on a project where that is also functionality I need but am having some trouble.
Thanks
@casunley when you read the file you get back an object representing the workbook.
workbook.SheetNames is an ordered list of the sheets in the workbook
workbook.Sheets[sheetname] returns a data structure representing the sheet. Each key that does not start with ! corresponds to a cell (using A-1 notation).
If you want to get cell B2 from the first sheet in the workbook, you would use
If the cell is present, you get back a cell object. To get the raw value, use
To get the formatted text, use
There are other utility functions like sheet_to_csv and sheet_to_json that give you different views of the workbook. They take a worksheet object. For example, to generate a CSV of the first sheet:
Take a look at some of the examples to see how to use them in practice.
hi casunley,
In my case so far i just wanted to test the functions of the parser.
Basically i use the following:
//to get all data from all sheets
to_formulae(workbook);
//to get all data from one sheet
XLSX.utils.get_formulae(workbook.Sheets[0]);
//to get the formula from the cell
workbook.Sheets[0]["B2"].f;
//to get the value from the cell
workbook.Sheets[0]["B2"].v;
Everything is working as intended! Thanks for the help. Just needed a push to get through this roadblock for a very obvious answer.
Curtis Sunley Jr
Developer Intern
Varrow
e: csunley@varrow.commailto:csunley@varrow.com | p: 201-965-6528
w: www.varrow.comhttp://www.varrow.com
[cid:A5B955B7-203A-4DC4-9CF0-2EACA672BC7F]
[facebook_2]http://www.facebook.com/varrowinc[twitter_2]https://twitter.com/varrow_[linkedin_2]http://www.linkedin.com/company/varrow
From: developergdd [mailto:notifications@github.com]
Sent: Friday, July 11, 2014 1:34 PM
To: SheetJS/js-xlsx
Cc: Curtis Sunley
Subject: Re: [js-xlsx] Access defined names and assigned values (#83)
hi casunley,
In my case so far i just wanted to test the functions of the parser.
Basically i use the following:
//to get all data from all sheets
to_formulae(workbook);
//to get all data from one sheet
XLSX.utils.get_formulae(workbook.Sheets[0]);
//to get the formula from the cell
workbook.Sheets[0]["B2"].f;
//to get the value from the cell
workbook.Sheets[0]["B2"].v;
—
Reply to this email directly or view it on GitHubhttps://github.com/SheetJS/js-xlsx/issues/83#issuecomment-48759643.
Seeking an update on this. I have need for using Defined Names
So I'm feeling my way through this and trying to make a patch that will add DefinedNames and I am stuck on a fundamental problem. The parsing routine in 77_wbxml.js is oriented to only be concerned with parsing the contents of an XML tag as follows
<myTag myProp="value">
Which works for basically everything except for DefinedNames which routinely look more like the following:
<myTag>value</myTag>
Looks like another data.match().forEach will need to be added to focus on the internals of the tag and it needs to fuse itself into the data in an orderly fashion. I'll see what I can come up with.
I have a working draft of this in a fork. Need to do a little more testing but I hope to get a pull request out in the next week or so.
Defined names are captured in workbook object's
Workbook.Names
field. For the defined_names_simple.xlsx sample test file the object looks like this:The
!names
field is an ordered list of the defined names, while each name is its own key. The keys of the object includeName
for the name of the defined name,Comment
for the comment andRef
for the actual reference string. XLSB follows the same pattern. We will be filling out the other formats soon (issue #599 tracks progress for the other formats)Did this ever get worked out? Is there a way to use Workbook.Names to parse with xlsx-calc?
I'm not sure if this is a problem with xlsx-calc or with xlsx library but I'm not able to handle defined names for cells or ranges.
throws an error,
where NBHDJ is a defined name on the spreadsheet
@capndave did you ever find a solution to this?
No but I moved on and used another tool.
On Wed, Mar 4, 2020 at 9:40 AM James notifications@github.com wrote:
Thanks for letting me know - would you recommend the new tool you're using? What is it?
@jwhitmarsh If
wb
is your workbook, thenwb.Workbook.Names
is an array of the defined names as described in https://docs.sheetjs.com/#defined-names@capndave if https://github.com/fabiooshiro/xlsx-calc/issues/20 was your issue, the in-workbook names should have been addressed (at least the issue is marked closed). The names with square brackets reference external workbooks, which is something not supported in our open source build but we offer as part of our Pro formula calculator -- that build will inspect the external reference caches if they exist
I used the Python package pywin32, which ended up being pretty flexible and
easy!
On Wed, Mar 4, 2020 at 10:53 AM James notifications@github.com wrote: