| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | /* [MS-XLSB] 2.4.28 BrtBeginComment */ | 
					
						
							| 
									
										
										
										
											2018-01-23 09:07:51 +00:00
										 |  |  | function parse_BrtBeginComment(data) { | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 	var out = {}; | 
					
						
							|  |  |  | 	out.iauthor = data.read_shift(4); | 
					
						
							|  |  |  | 	var rfx = parse_UncheckedRfX(data, 16); | 
					
						
							|  |  |  | 	out.rfx = rfx.s; | 
					
						
							|  |  |  | 	out.ref = encode_cell(rfx.s); | 
					
						
							|  |  |  | 	data.l += 16; /*var guid = parse_GUID(data); */ | 
					
						
							|  |  |  | 	return out; | 
					
						
							| 
									
										
										
										
											2014-06-29 18:29:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | function write_BrtBeginComment(data, o) { | 
					
						
							|  |  |  | 	if(o == null) o = new_buf(36); | 
					
						
							|  |  |  | 	o.write_shift(4, data[1].iauthor); | 
					
						
							| 
									
										
										
										
											2017-04-03 00:16:03 +00:00
										 |  |  | 	write_UncheckedRfX((data[0]/*:any*/), o); | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 	o.write_shift(4, 0); | 
					
						
							|  |  |  | 	o.write_shift(4, 0); | 
					
						
							|  |  |  | 	o.write_shift(4, 0); | 
					
						
							|  |  |  | 	o.write_shift(4, 0); | 
					
						
							|  |  |  | 	return o; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 20:06:35 +00:00
										 |  |  | /* [MS-XLSB] 2.4.327 BrtCommentAuthor */ | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | var parse_BrtCommentAuthor = parse_XLWideString; | 
					
						
							| 
									
										
										
										
											2017-09-22 22:18:51 +00:00
										 |  |  | function write_BrtCommentAuthor(data) { return write_XLWideString(data.slice(0, 54)); } | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* [MS-XLSB] 2.1.7.8 Comments */ | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | function parse_comments_bin(data, opts)/*:Array<RawComment>*/ { | 
					
						
							|  |  |  | 	var out/*:Array<RawComment>*/ = []; | 
					
						
							|  |  |  | 	var authors/*:Array<string>*/ = []; | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 	var c = {}; | 
					
						
							|  |  |  | 	var pass = false; | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 	recordhopper(data, function hopper_cmnt(val, R, RT) { | 
					
						
							| 
									
										
										
										
											2017-04-09 04:03:19 +00:00
										 |  |  | 		switch(RT) { | 
					
						
							|  |  |  | 			case 0x0278: /* 'BrtCommentAuthor' */ | 
					
						
							|  |  |  | 				authors.push(val); break; | 
					
						
							|  |  |  | 			case 0x027B: /* 'BrtBeginComment' */ | 
					
						
							|  |  |  | 				c = val; break; | 
					
						
							|  |  |  | 			case 0x027D: /* 'BrtCommentText' */ | 
					
						
							|  |  |  | 				c.t = val.t; c.h = val.h; c.r = val.r; break; | 
					
						
							|  |  |  | 			case 0x027C: /* 'BrtEndComment' */ | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 				c.author = authors[c.iauthor]; | 
					
						
							| 
									
										
										
										
											2019-11-01 03:09:14 +00:00
										 |  |  | 				delete (c/*:any*/).iauthor; | 
					
						
							|  |  |  | 				if(opts.sheetRows && c.rfx && opts.sheetRows <= c.rfx.r) break; | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 				if(!c.t) c.t = ""; | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 				delete c.rfx; out.push(c); break; | 
					
						
							| 
									
										
										
										
											2017-04-08 06:55:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 21:42:55 +00:00
										 |  |  | 			case 0x0C00: /* 'BrtUid' */ | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2017-04-09 04:03:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			case 0x0023: /* 'BrtFRTBegin' */ | 
					
						
							|  |  |  | 				pass = true; break; | 
					
						
							|  |  |  | 			case 0x0024: /* 'BrtFRTEnd' */ | 
					
						
							|  |  |  | 				pass = false; break; | 
					
						
							|  |  |  | 			case 0x0025: /* 'BrtACBegin' */ break; | 
					
						
							|  |  |  | 			case 0x0026: /* 'BrtACEnd' */ break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-08 06:55:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 				if(R.T){/* empty */} | 
					
						
							|  |  |  | 				else if(!pass || opts.WTF) throw new Error("Unexpected record 0x" + RT.toString(16)); | 
					
						
							| 
									
										
										
										
											2014-03-29 02:05:50 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	return out; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-05-29 22:30:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 09:07:51 +00:00
										 |  |  | function write_comments_bin(data/*::, opts*/) { | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 	var ba = buf_array(); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 	var iauthor/*:Array<string>*/ = []; | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 	write_record(ba, 0x0274 /* BrtBeginComments */); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 	write_record(ba, 0x0276 /* BrtBeginCommentAuthors */); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 	data.forEach(function(comment) { | 
					
						
							|  |  |  | 		comment[1].forEach(function(c) { | 
					
						
							|  |  |  | 			if(iauthor.indexOf(c.a) > -1) return; | 
					
						
							|  |  |  | 			iauthor.push(c.a.slice(0,54)); | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 			write_record(ba, 0x0278 /* BrtCommentAuthor */, write_BrtCommentAuthor(c.a)); | 
					
						
							| 
									
										
										
										
											2023-06-13 04:49:18 +00:00
										 |  |  | 			if(c.T && c.ID && iauthor.indexOf("tc=" + c.ID) == -1) { | 
					
						
							|  |  |  | 				iauthor.push("tc=" + c.ID); | 
					
						
							|  |  |  | 				write_record(ba, 0x0278 /* BrtCommentAuthor */, write_BrtCommentAuthor("tc=" + c.ID)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 	write_record(ba, 0x0277 /* BrtEndCommentAuthors */); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 	write_record(ba, 0x0279 /* BrtBeginCommentList */); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 	data.forEach(function(comment) { | 
					
						
							|  |  |  | 		comment[1].forEach(function(c) { | 
					
						
							| 
									
										
										
										
											2023-06-13 04:49:18 +00:00
										 |  |  | 			var _ia = -1; | 
					
						
							|  |  |  | 			if(c.ID) _ia = iauthor.indexOf("tc=" + c.ID); | 
					
						
							|  |  |  | 			if(_ia == -1 && comment[1][0].T && comment[1][0].ID) _ia = iauthor.indexOf("tc=" + comment[1][0].ID); | 
					
						
							|  |  |  | 			if(_ia == -1) _ia = iauthor.indexOf(c.a); | 
					
						
							|  |  |  | 			c.iauthor = _ia; | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 			var range = {s:decode_cell(comment[0]),e:decode_cell(comment[0])}; | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 			write_record(ba, 0x027B /* BrtBeginComment */, write_BrtBeginComment([range, c])); | 
					
						
							|  |  |  | 			if(c.t && c.t.length > 0) write_record(ba, 0x027D /* BrtCommentText */, write_BrtCommentText(c)); | 
					
						
							|  |  |  | 			write_record(ba, 0x027C /* BrtEndComment */); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 			delete c.iauthor; | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 	write_record(ba, 0x027A /* BrtEndCommentList */); | 
					
						
							| 
									
										
										
										
											2017-12-30 05:40:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-12 14:05:57 +00:00
										 |  |  | 	write_record(ba, 0x0275 /* BrtEndComments */); | 
					
						
							| 
									
										
										
										
											2017-04-02 06:47:25 +00:00
										 |  |  | 	return ba.end(); | 
					
						
							|  |  |  | } |