forked from sheetjs/sheetjs
		
	XLSX write page margins
changes distilled from Siguza/js-xlsx see https://github.com/protobi/js-xlsx/pull/19 for discussion
This commit is contained in:
		
							parent
							
								
									09fba37eac
								
							
						
					
					
						commit
						c356e91fdc
					
				| @ -143,6 +143,10 @@ function parse_ws_xml_margins(margin) { | ||||
| 	}); | ||||
| 	return o; | ||||
| } | ||||
| function write_ws_xml_margins(margin) { | ||||
| 	default_margins(margin); | ||||
| 	return writextag('pageMargins', null, margin); | ||||
| } | ||||
| 
 | ||||
| function parse_ws_xml_cols(columns, cols) { | ||||
| 	var seencol = false; | ||||
| @ -452,7 +456,7 @@ function write_ws_xml(idx/*:number*/, opts, wb/*:Workbook*/, rels)/*:string*/ { | ||||
| 	delete ws['!links']; | ||||
| 
 | ||||
| 	/* printOptions */ | ||||
| 	/* pageMargins */ | ||||
| 	if (ws['!margins'] != null) o[o.length] =  write_ws_xml_margins(ws['!margins']) | ||||
| 	/* pageSetup */ | ||||
| 
 | ||||
| 	var hfidx = o.length; | ||||
|  | ||||
							
								
								
									
										31
									
								
								test.js
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										31
									
								
								test.js
									
									
									
									
									
								
							| @ -658,6 +658,14 @@ function hlink(wb) { | ||||
| 	assert.equal(get_cell(ws, "A7").l.Tooltip, "foo bar baz"); | ||||
| } | ||||
| 
 | ||||
| function check_margin(margins, exp) { | ||||
| 	assert.equal(margins.left, exp[0]); | ||||
| 	assert.equal(margins.right, exp[1]); | ||||
| 	assert.equal(margins.top, exp[2]); | ||||
| 	assert.equal(margins.bottom, exp[3]); | ||||
| 	assert.equal(margins.header, exp[4]); | ||||
| 	assert.equal(margins.footer, exp[5]); | ||||
| } | ||||
| 
 | ||||
| describe('parse features', function() { | ||||
| 	describe('sheet visibility', function() { | ||||
| @ -977,14 +985,6 @@ describe('parse features', function() { | ||||
| 	}); | ||||
| 
 | ||||
| 	describe('page margins', function() { | ||||
| 		function check_margin(margins, exp) { | ||||
| 			assert.equal(margins.left, exp[0]); | ||||
| 			assert.equal(margins.right, exp[1]); | ||||
| 			assert.equal(margins.top, exp[2]); | ||||
| 			assert.equal(margins.bottom, exp[3]); | ||||
| 			assert.equal(margins.header, exp[4]); | ||||
| 			assert.equal(margins.footer, exp[5]); | ||||
| 		} | ||||
| 		var wb1, wb2, wb3, wb4, wb5, wbs; | ||||
| 		var bef = (function() { | ||||
| 			wb1 = X.readFile(paths.pmxls); | ||||
| @ -1251,6 +1251,21 @@ describe('roundtrip features', function() { | ||||
| 		}); | ||||
| 	}); | ||||
| 
 | ||||
| 	describe('should preserve page margins', function() {[ | ||||
| 			//['xlml', paths.pmxml],
 | ||||
| 			['xlsx', paths.pmxlsx], | ||||
| 			['xlsb', paths.pmxlsb] | ||||
| 		].forEach(function(w) { it(w[0], function() { | ||||
| 			var wb1 = X.readFile(w[1]); | ||||
| 			var wb2 = X.read(X.write(wb1, {bookType:w[0], type:"binary"}), {type:"binary"}); | ||||
| 			check_margin(wb2.Sheets["Normal"]["!margins"], [0.7, 0.7, 0.75, 0.75, 0.3, 0.3]); | ||||
| 			check_margin(wb2.Sheets["Wide"]["!margins"], [1, 1, 1, 1, 0.5, 0.5]); | ||||
| 			check_margin(wb2.Sheets["Wide"]["!margins"], [1, 1, 1, 1, 0.5, 0.5]); | ||||
| 			check_margin(wb2.Sheets["Narrow"]["!margins"], [0.25, 0.25, 0.75, 0.75, 0.3, 0.3]); | ||||
| 			check_margin(wb2.Sheets["Custom 1 Inch Centered"]["!margins"], [1, 1, 1, 1, 0.3, 0.3]); | ||||
| 			check_margin(wb2.Sheets["1 Inch HF"]["!margins"], [0.7, 0.7, 0.75, 0.75, 1, 1]); | ||||
| 	}); }); }); | ||||
| 
 | ||||
| 	describe('should preserve sheet visibility', function() { [ | ||||
| 			['xlml', paths.svxml], | ||||
| 			['xlsx', paths.svxlsx], | ||||
|  | ||||
| @ -10100,6 +10100,10 @@ function parse_ws_xml_margins(margin) { | ||||
| 	}); | ||||
| 	return o; | ||||
| } | ||||
| function write_ws_xml_margins(margin) { | ||||
| 	default_margins(margin); | ||||
| 	return writextag('pageMargins', null, margin); | ||||
| } | ||||
| 
 | ||||
| function parse_ws_xml_cols(columns, cols) { | ||||
| 	var seencol = false; | ||||
| @ -10409,7 +10413,7 @@ function write_ws_xml(idx/*:number*/, opts, wb/*:Workbook*/, rels)/*:string*/ { | ||||
| 	delete ws['!links']; | ||||
| 
 | ||||
| 	/* printOptions */ | ||||
| 	/* pageMargins */ | ||||
| 	if (ws['!margins'] != null) o[o.length] =  write_ws_xml_margins(ws['!margins']) | ||||
| 	/* pageSetup */ | ||||
| 
 | ||||
| 	var hfidx = o.length; | ||||
|  | ||||
							
								
								
									
										6
									
								
								xlsx.js
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										6
									
								
								xlsx.js
									
									
									
									
									
								
							| @ -10038,6 +10038,10 @@ function parse_ws_xml_margins(margin) { | ||||
| 	}); | ||||
| 	return o; | ||||
| } | ||||
| function write_ws_xml_margins(margin) { | ||||
| 	default_margins(margin); | ||||
| 	return writextag('pageMargins', null, margin); | ||||
| } | ||||
| 
 | ||||
| function parse_ws_xml_cols(columns, cols) { | ||||
| 	var seencol = false; | ||||
| @ -10347,7 +10351,7 @@ function write_ws_xml(idx, opts, wb, rels) { | ||||
| 	delete ws['!links']; | ||||
| 
 | ||||
| 	/* printOptions */ | ||||
| 	/* pageMargins */ | ||||
| 	if (ws['!margins'] != null) o[o.length] =  write_ws_xml_margins(ws['!margins']) | ||||
| 	/* pageSetup */ | ||||
| 
 | ||||
| 	var hfidx = o.length; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user