2017-04-02 06:47:25 +00:00
|
|
|
RELS.CMNT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
|
2014-01-28 16:38:02 +00:00
|
|
|
|
2014-02-12 06:09:42 +00:00
|
|
|
function parse_comments(zip, dirComments, sheets, sheetRels, opts) {
|
2014-01-28 16:38:02 +00:00
|
|
|
for(var i = 0; i != dirComments.length; ++i) {
|
|
|
|
var canonicalpath=dirComments[i];
|
2014-03-29 02:05:50 +00:00
|
|
|
var comments=parse_cmnt(getzipdata(zip, canonicalpath.replace(/^\//,''), true), canonicalpath, opts);
|
2014-02-19 03:03:28 +00:00
|
|
|
if(!comments || !comments.length) continue;
|
2014-01-28 16:38:02 +00:00
|
|
|
// find the sheets targeted by these comments
|
2014-05-16 00:33:34 +00:00
|
|
|
var sheetNames = keys(sheets);
|
2014-01-28 16:38:02 +00:00
|
|
|
for(var j = 0; j != sheetNames.length; ++j) {
|
|
|
|
var sheetName = sheetNames[j];
|
|
|
|
var rels = sheetRels[sheetName];
|
2014-02-12 06:09:42 +00:00
|
|
|
if(rels) {
|
2014-01-28 16:38:02 +00:00
|
|
|
var rel = rels[canonicalpath];
|
2014-02-12 06:09:42 +00:00
|
|
|
if(rel) insertCommentsIntoSheet(sheetName, sheets[sheetName], comments);
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-29 06:00:09 +00:00
|
|
|
}
|
2014-01-28 16:38:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-30 05:40:35 +00:00
|
|
|
function insertCommentsIntoSheet(sheetName, sheet, comments/*:Array<RawComment>*/) {
|
2017-04-08 06:55:35 +00:00
|
|
|
var dense = Array.isArray(sheet);
|
2017-12-30 05:40:35 +00:00
|
|
|
var cell/*:Cell*/, r;
|
2014-01-28 16:38:02 +00:00
|
|
|
comments.forEach(function(comment) {
|
2017-04-08 06:55:35 +00:00
|
|
|
if(dense) {
|
|
|
|
r = decode_cell(comment.ref);
|
|
|
|
if(!sheet[r.r]) sheet[r.r] = [];
|
|
|
|
cell = sheet[r.r][r.c];
|
|
|
|
} else cell = sheet[comment.ref];
|
2014-01-28 16:38:02 +00:00
|
|
|
if (!cell) {
|
|
|
|
cell = {};
|
2017-04-08 06:55:35 +00:00
|
|
|
if(dense) sheet[r.r][r.c] = cell;
|
|
|
|
else sheet[comment.ref] = cell;
|
2014-06-29 18:29:45 +00:00
|
|
|
var range = safe_decode_range(sheet["!ref"]||"BDWGO1000001:A1");
|
2014-01-28 16:38:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-12 06:09:42 +00:00
|
|
|
if (!cell.c) cell.c = [];
|
2017-12-30 05:40:35 +00:00
|
|
|
var o/*:Comment*/ = ({a: comment.author, t: comment.t, r: comment.r});
|
2014-02-12 06:09:42 +00:00
|
|
|
if(comment.h) o.h = comment.h;
|
|
|
|
cell.c.push(o);
|
2014-01-28 16:38:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|