function write_ws_biff8(idx, opts, wb) {
	var ba = buf_array();
	var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
	var _WB = ((wb||{}).Workbook||{});
	var _sheet = ((_WB.Sheets||[])[idx]||{});
	var dense = Array.isArray(ws);
	var b8 = opts.biff == 8;
	var ref, rr = "", cols = [];
	var range = safe_decode_range(ws['!ref'] || "A1");
	var MAX_ROWS = b8 ? 65536 : 16384;
	if(range.e.c > 0xFF || range.e.r >= MAX_ROWS) {
		if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
		range.e.c = Math.min(range.e.c, 0xFF);
		range.e.r = Math.min(range.e.c, MAX_ROWS-1);
	}

	write_biff_rec(ba, 0x0809, write_BOF(wb, 0x10, opts));
	/* ... */
	write_biff_rec(ba, "CalcMode", writeuint16(1));
	write_biff_rec(ba, "CalcCount", writeuint16(100));
	write_biff_rec(ba, "CalcRefMode", writebool(true));
	write_biff_rec(ba, "CalcIter", writebool(false));
	write_biff_rec(ba, "CalcDelta", write_Xnum(0.001));
	write_biff_rec(ba, "CalcSaveRecalc", writebool(true));
	write_biff_rec(ba, "PrintRowCol", writebool(false));
	write_biff_rec(ba, "PrintGrid", writebool(false));
	write_biff_rec(ba, "GridSet", writeuint16(1));
	write_biff_rec(ba, "Guts", write_Guts([0,0]));
	/* ... */
	write_biff_rec(ba, "HCenter", writebool(false));
	write_biff_rec(ba, "VCenter", writebool(false));
	/* ... */
	write_biff_rec(ba, 0x200, write_Dimensions(range, opts));
	/* ... */

	if(b8) ws['!links'] = [];
	for(var R = range.s.r; R <= range.e.r; ++R) {
		rr = encode_row(R);
		for(var C = range.s.c; C <= range.e.c; ++C) {
			if(R === range.s.r) cols[C] = encode_col(C);
			ref = cols[C] + rr;
			var cell = dense ? (ws[R]||[])[C] : ws[ref];
			if(!cell) continue;
			/* write cell */
			write_ws_biff8_cell(ba, cell, R, C, opts);
			if(b8 && cell.l) ws['!links'].push([ref, cell.l]);
		}
	}
	var cname = _sheet.CodeName || _sheet.name || s;
	/* ... */
	if(b8 && _WB.Views) write_biff_rec(ba, "Window2", write_Window2(_WB.Views[0]));
	/* ... */
	if(b8 && (ws['!merges']||[]).length) write_biff_rec(ba, "MergeCells", write_MergeCells(ws['!merges']));
	/* ... */
	if(b8) write_ws_biff8_hlinks(ba, ws);
	/* ... */
	write_biff_rec(ba, "CodeName", write_XLUnicodeString(cname, opts));
	/* ... */
	if(b8) write_FEAT(ba, ws);
	/* ... */
	write_biff_rec(ba, "EOF");
	return ba.end();
}
function write_ws_biff8(idx, opts, wb) {
	var ba = buf_array();
	var s = wb.SheetNames[idx], ws = wb.Sheets[s] || {};
	var _WB = ((wb||{}).Workbook||{});
	var _sheet = ((_WB.Sheets||[])[idx]||{});
	var dense = Array.isArray(ws);
	var b8 = opts.biff == 8;
	var ref, rr = "", cols = [];
	var range = safe_decode_range(ws['!ref'] || "A1");
	var MAX_ROWS = b8 ? 65536 : 16384;
	if(range.e.c > 0xFF || range.e.r >= MAX_ROWS) {
		if(opts.WTF) throw new Error("Range " + (ws['!ref'] || "A1") + " exceeds format limit A1:IV16384");
		range.e.c = Math.min(range.e.c, 0xFF);
		range.e.r = Math.min(range.e.c, MAX_ROWS-1);
	}

	write_biff_rec(ba, 0x0809, write_BOF(wb, 0x10, opts));
	/* ... */
	write_biff_rec(ba, "CalcMode", writeuint16(1));
	write_biff_rec(ba, "CalcCount", writeuint16(100));
	write_biff_rec(ba, "CalcRefMode", writebool(true));
	write_biff_rec(ba, "CalcIter", writebool(false));
	write_biff_rec(ba, "CalcDelta", write_Xnum(0.001));
	write_biff_rec(ba, "CalcSaveRecalc", writebool(true));
	write_biff_rec(ba, "PrintRowCol", writebool(false));
	write_biff_rec(ba, "PrintGrid", writebool(false));
	write_biff_rec(ba, "GridSet", writeuint16(1));
	write_biff_rec(ba, "Guts", write_Guts([0,0]));
	/* ... */
	write_biff_rec(ba, "HCenter", writebool(false));
	write_biff_rec(ba, "VCenter", writebool(false));
	/* ... */
	write_biff_rec(ba, 0x200, write_Dimensions(range, opts));
	/* ... */

	if(b8) ws['!links'] = [];
	for(var R = range.s.r; R <= range.e.r; ++R) {
		rr = encode_row(R);
		for(var C = range.s.c; C <= range.e.c; ++C) {
			if(R === range.s.r) cols[C] = encode_col(C);
			ref = cols[C] + rr;
			var cell = dense ? (ws[R]||[])[C] : ws[ref];
			if(!cell) continue;
			/* write cell */
			write_ws_biff8_cell(ba, cell, R, C, opts);
			if(b8 && cell.l) ws['!links'].push([ref, cell.l]);
		}
	}
	var cname = _sheet.CodeName || _sheet.name || s;
	/* ... */
	if(b8 && _WB.Views) write_biff_rec(ba, "Window2", write_Window2(_WB.Views[0]));
	/* ... */
	if(b8 && (ws['!merges']||[]).length) write_biff_rec(ba, "MergeCells", write_MergeCells(ws['!merges']));
	/* ... */
	if(b8) write_ws_biff8_hlinks(ba, ws);
	/* ... */
	write_biff_rec(ba, "CodeName", write_XLUnicodeString(cname, opts));
	/* ... */
	if(b8) write_FEAT(ba, ws);
	/* ... */
	write_biff_rec(ba, "EOF");
	return ba.end();
}
function write_ws_biff8 ( idx , opts , wb ) { var ba = buf_array ( ) ; var s = wb . SheetNames [ idx ] , ws = wb . Sheets [ s ] || { } ; var _WB = ( ( wb || { } ) . Workbook || { } ) ; var _sheet = ( ( _WB . Sheets || [ ] ) [ idx ] || { } ) ; var dense = Array . isArray ( ws ) ; var b8 = opts . biff == 8 ; var ref , rr = "" , cols = [ ] ; var range = safe_decode_range ( ws [ '!ref' ] || "A1" ) ; var MAX_ROWS = b8 ? 65536 : 16384 ; if ( range . e . c > 0xFF || range . e . r >= MAX_ROWS ) { if ( opts . WTF ) throw new Error ( "Range " + ( ws [ '!ref' ] || "A1" ) + " exceeds format limit A1:IV16384" ) ; range . e . c = Math . min ( range . e . c , 0xFF ) ; range . e . r = Math . min ( range . e . c , MAX_ROWS - 1 ) ; } write_biff_rec ( ba , 0x0809 , write_BOF ( wb , 0x10 , opts ) ) ; /* ... */ write_biff_rec ( ba , "CalcMode" , writeuint16 ( 1 ) ) ; write_biff_rec ( ba , "CalcCount" , writeuint16 ( 100 ) ) ; write_biff_rec ( ba , "CalcRefMode" , writebool ( true ) ) ; write_biff_rec ( ba , "CalcIter" , writebool ( false ) ) ; write_biff_rec ( ba , "CalcDelta" , write_Xnum ( 0.001 ) ) ; write_biff_rec ( ba , "CalcSaveRecalc" , writebool ( true ) ) ; write_biff_rec ( ba , "PrintRowCol" , writebool ( false ) ) ; write_biff_rec ( ba , "PrintGrid" , writebool ( false ) ) ; write_biff_rec ( ba , "GridSet" , writeuint16 ( 1 ) ) ; write_biff_rec ( ba , "Guts" , write_Guts ( [ 0 , 0 ] ) ) ; /* ... */ write_biff_rec ( ba , "HCenter" , writebool ( false ) ) ; write_biff_rec ( ba , "VCenter" , writebool ( false ) ) ; /* ... */ write_biff_rec ( ba , 0x200 , write_Dimensions ( range , opts ) ) ; /* ... */ if ( b8 ) ws [ '!links' ] = [ ] ; for ( var R = range . s . r ; R <= range . e . r ; ++ R ) { rr = encode_row ( R ) ; for ( var C = range . s . c ; C <= range . e . c ; ++ C ) { if ( R === range . s . r ) cols [ C ] = encode_col ( C ) ; ref = cols [ C ] + rr ; var cell = dense ? ( ws [ R ] || [ ] ) [ C ] : ws [ ref ] ; if ( ! cell ) continue ; /* write cell */ write_ws_biff8_cell ( ba , cell , R , C , opts ) ; if ( b8 && cell . l ) ws [ '!links' ] . push ( [ ref , cell . l ] ) ; } } var cname = _sheet . CodeName || _sheet . name || s ; /* ... */ if ( b8 && _WB . Views ) write_biff_rec ( ba , "Window2" , write_Window2 ( _WB . Views [ 0 ] ) ) ; /* ... */ if ( b8 && ( ws [ '!merges' ] || [ ] ) . length ) write_biff_rec ( ba , "MergeCells" , write_MergeCells ( ws [ '!merges' ] ) ) ; /* ... */ if ( b8 ) write_ws_biff8_hlinks ( ba , ws ) ; /* ... */ write_biff_rec ( ba , "CodeName" , write_XLUnicodeString ( cname , opts ) ) ; /* ... */ if ( b8 ) write_FEAT ( ba , ws ) ; /* ... */ write_biff_rec ( ba , "EOF" ) ; return ba . end ( ) ; }
/* [MS-XLS] 2.1.7.20.5
/ * [ MS - XLS ] 2 . 1 . 7 . 20 . 5
Write a sheet to a buffer