forked from sheetjs/sheetjs
SheetJS
d462e18846
- SSF updated to 0.6.1 (h/t @notatestuser) - more tests and related XLSB records - XLSB plaintext comment and author - preliminary work for XLSB formats
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
|
|
function parse_comments(zip, dirComments, sheets, sheetRels, opts) {
|
|
for(var i = 0; i != dirComments.length; ++i) {
|
|
var canonicalpath=dirComments[i];
|
|
var comments=parse_cmnt(getzipdata(zip, canonicalpath.replace(/^\//,''), true), canonicalpath, opts);
|
|
if(!comments || !comments.length) continue;
|
|
// find the sheets targeted by these comments
|
|
var sheetNames = Object.keys(sheets);
|
|
for(var j = 0; j != sheetNames.length; ++j) {
|
|
var sheetName = sheetNames[j];
|
|
var rels = sheetRels[sheetName];
|
|
if(rels) {
|
|
var rel = rels[canonicalpath];
|
|
if(rel) insertCommentsIntoSheet(sheetName, sheets[sheetName], comments);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function insertCommentsIntoSheet(sheetName, sheet, comments) {
|
|
comments.forEach(function(comment) {
|
|
var cell = sheet[comment.ref];
|
|
if (!cell) {
|
|
cell = {};
|
|
sheet[comment.ref] = cell;
|
|
var range = decode_range(sheet["!ref"]);
|
|
var thisCell = decode_cell(comment.ref);
|
|
if(range.s.r > thisCell.r) range.s.r = thisCell.r;
|
|
if(range.e.r < thisCell.r) range.e.r = thisCell.r;
|
|
if(range.s.c > thisCell.c) range.s.c = thisCell.c;
|
|
if(range.e.c < thisCell.c) range.e.c = thisCell.c;
|
|
var encoded = encode_range(range);
|
|
if (encoded !== sheet["!ref"]) sheet["!ref"] = encoded;
|
|
}
|
|
|
|
if (!cell.c) cell.c = [];
|
|
var o = {a: comment.author, t: comment.t, r: comment.r};
|
|
if(comment.h) o.h = comment.h;
|
|
cell.c.push(o);
|
|
});
|
|
}
|
|
|