insert some cell comments when we write a XLSX file #605
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#605
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?
Is it possible to insert some cell comments when we write a XLSX file with js-xlsx ? When I read a file containing some cell comments, they appear when I read the file:
Now, when I write this JSON workbook to a XLSX file:
XLSX.writeFile(wb, "Book1comments_rewritten.xlsx")
then there are no comments anymore in the created file.
@ylbweb You can read comments from XLSX but currently cannot write comments. Comment write support is in the roadmap. The main hurdle is settling on the representation of the comments -- the individual formats (XLS, XLSX, XLSB, XLML, ODS) store comments in different ways and we do not yet convert the comments to the same form.
If you just need XLSX write support and you have some time, you can add it in. There are 5 changes you need to make:
collect all of the comments when writing the worksheet.
write_ws_xml_cell
function gets called on every cell. In that call, check if the cell has a comment and push it to some array (I recommend creating an arrayws["!comments"]=[]
and keep pushing into it).generate the comments xml. You have to write a new function for this but it is not too hard to do. The XML is pretty simple here. take a look at
comments_stress_test.xlsx
-- this is what we use in the read tests. The function should be called in the sheets loop inthe main write_zip function
generate a worksheet relationships file that references the comment. You need to define a rels object
{}
and add a link to the comments file. The workbook relationships file is built up inwbrels
-- repeat similar logic for the worksheet, adding the comments file. Feel free to use a relationship id of1
(second argument to theadd_rels
function).add the comments file name to the content types list. it will be something like
ct.comments.push(...)
right after committing the comments xml.ensure the comments are written to file. That will be in
write_ct
function Since comments are binary in XLSB, add the linef1("comments")
directly after the themes line.Like I said, we will be addressing comments at some point, but until that happens if you need write support it isn't too hard to add.
@ylbweb turns out that merely writing the comment xml/bin isn't enough for XLSX/XLSB! In XLML you can just write the comment and Excel will give a default comment rendering, but in XLSX/XLSB you actually need to set up a VML drawing as well.
We pushed the relevant fix to master and hope to have the next release in the next 48 hours or so
Hi, we are using xlsx@v0.12.1 plugin (https://www.npmjs.com/package/xlsx) for writing data in exported excel file also try to add cell comment. After export the data the cell comment added for applicable cells and when we hover on cell the comment window open/close working fine with Read Only mode. When we edit the download excel file from internet/my server. The comment window failed to close when away from cell.
Please let me know if we need to add any new configuration properties in write_comments_vml() method to avoiding comment window close issue and its get works as expected. Also attached screen shot and download file for reference.
Note: Please not down the excel comment working as expected in Read Only mode.
Excel-cell-comment-window-not-close.xlsx