Non removal of empty columns #592
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#592
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?
I'm currently using this library and empty columns/cells are removed when parsed, is there an option to keep them somehow?
This is what I'm doing more or less:
var sheet_name_list = workbook.SheetNames;
sheet_name_list.forEach(function(y) { /* iterate through sheets /
var worksheet = workbook.Sheets[y];
for (var z in worksheet) {
/ all keys that do not begin with "!" correspond to cell addresses */
if(z[0] === '!') continue;
console.log(y + "!" + z + "=" + JSON.stringify(worksheet[z].v));
}
});
It loops through every nonempty sheet. But my question is how can I maintain/keep the empty cells?
@rashthedude I assume you mean empty cell.
README: https://github.com/SheetJS/js-xlsx#worksheet-object
Each worksheet stores its range in a key
!ref
. Ifworksheet
is the your sheet, thenworksheet['!ref']
is the range. Using theXLSX.utils.decode_range
function, you can get the full extent of the worksheet. Then you can loop across the sheet by looping across all rows and columns in the range:The utilities functions skip the
encode_cell
calls by pre-computing the column names. For example,sheet_to_csv
essentially does:Hi there,
Thanks for the swift reply but I'm a little confused. To give you a clear idea of what I'm doing:
workbook - xlsx.readFile(file)
sheet_name_list = workbook.SheetNames
sheet_name_list.forEach( (y) ->
worksheet = workbook.Sheets[y]
for m, n of worksheet
// do something here
So where exactly do I make use of "decode_range"?
@rashthedude The worksheets are objects whose keys are cell addresses (like
B3
) and whose values are cell objects. The code you presented will iterate across the cells. In retrospect that's not a great pattern and we will remove it from the README.What exactly are you trying to do? For example, if you just want to get the content as an array of arrays, the
sheet_to_json
utility function will do that.@SheetJSDev Yes I'm trying to fetch the content as an array and iterate over it. Tried:
wb = xlsx.readFile(file)
stuff = xlsx.utils.sheet_to_json(wb)
But "stuff" seems to be empty at this point.
Managed to get it to work at last. Thanks again @SheetJSDev.
@rashthedude sheet_to_json, as the name indicates, takes a worksheet :D Feel free to raise another issue if you encounter more issues.
@rashthedude could you please share how did you resolve the issue, I am facing the same issue right now.
Make sure you are using the latest version of js from https://cdn.sheetjs.com/ (Read "how to use") and you can refer this https://github.com/SheetJS/sheetjs/issues/159#issuecomment-403228877