sheetjs/bits/57_cmntxml.js
SheetJS 009946339c version bump 0.7.5: more performance
- eliminated functional constructs in hot functions
- format try-catch block extracted into new function
- cpexcel + codepage updated to 1.2.0
- more efficient (and correct) clean implementation of RGB/HSL/tint algorithms
- xlsx binary --all option enables every extra formatting and saving option
- column widths parsed and saved (requires cellStyles:true)
2014-06-02 01:19:07 -04:00

28 lines
1.2 KiB
JavaScript

/* 18.7.3 CT_Comment */
function parse_comments_xml(data, opts) {
if(data.match(/<(?:\w+:)?comments *\/>/)) return [];
var authors = [];
var commentList = [];
data.match(/<(?:\w+:)?authors>([^\u2603]*)<\/(?:\w+:)?authors>/m)[1].split(/<\/(?:\w+:)?author>/).forEach(function(x) {
if(x === "" || x.trim() === "") return;
authors.push(x.match(/<(?:\w+:)?author[^>]*>(.*)/)[1]);
});
(data.match(/<(?:\w+:)?commentList>([^\u2603]*)<\/(?:\w+:)?commentList>/m)||["",""])[1].split(/<\/(?:\w+:)?comment>/).forEach(function(x, index) {
if(x === "" || x.trim() === "") return;
var y = parsexmltag(x.match(/<(?:\w+:)?comment[^>]*>/)[0]);
var comment = { author: y.authorId && authors[y.authorId] ? authors[y.authorId] : undefined, ref: y.ref, guid: y.guid };
var cell = decode_cell(y.ref);
if(opts.sheetRows && opts.sheetRows <= cell.r) return;
var textMatch = x.match(/<text>([^\u2603]*)<\/text>/m);
if (!textMatch || !textMatch[1]) return; // a comment may contain an empty text tag.
var rt = parse_si(textMatch[1]);
comment.r = rt.r;
comment.t = rt.t;
if(opts.cellHTML) comment.h = rt.h;
commentList.push(comment);
});
return commentList;
}
function write_comments_xml(data, opts) { }