| 
									
										
										
										
											2017-09-05 05:26:50 +00:00
										 |  |  | /* xlsx.js (C) 2013-present  SheetJS -- http://sheetjs.com */ | 
					
						
							| 
									
										
										
										
											2022-02-08 09:50:51 +00:00
										 |  |  | /* eslint-env phantomjs */ | 
					
						
							|  |  |  | var XLSX = require('xlsx'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-28 04:41:01 +00:00
										 |  |  | var page = require('webpage').create(); | 
					
						
							| 
									
										
										
										
											2022-02-08 09:50:51 +00:00
										 |  |  | page.onConsoleMessage = function(msg) { console.log(msg); }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* this code will be run in the page */ | 
					
						
							|  |  |  | var code = [ "function(){", | 
					
						
							|  |  |  |   /* call table_to_book on first table */ | 
					
						
							|  |  |  |   "var wb = XLSX.utils.table_to_book(document.body.getElementsByTagName('table')[0]);", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* generate XLSB file and return binary string */ | 
					
						
							|  |  |  |   "return XLSX.write(wb, {type: 'binary', bookType: 'xlsb'});", | 
					
						
							|  |  |  | "}" ].join(""); | 
					
						
							| 
									
										
										
										
											2017-03-28 04:41:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 09:50:51 +00:00
										 |  |  | page.open('https://sheetjs.com/demos/table', function() { | 
					
						
							|  |  |  |   console.log("Page Loaded"); | 
					
						
							|  |  |  |   /* Load the browser script from the UNPKG CDN */ | 
					
						
							|  |  |  |   page.includeJs("https://unpkg.com/xlsx/dist/xlsx.full.min.js", function() { | 
					
						
							|  |  |  |     /* Verify the page is loaded by logging the version number */ | 
					
						
							|  |  |  |     var version = "function(){ console.log('Library Version:' + window.XLSX.version); }"; | 
					
						
							|  |  |  |     page.evaluateJavaScript(version); | 
					
						
							| 
									
										
										
										
											2017-03-28 04:41:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 09:50:51 +00:00
										 |  |  |     /* The code will return a binary string */ | 
					
						
							|  |  |  |     var bin = page.evaluateJavaScript(code); | 
					
						
							|  |  |  |     var workbook = XLSX.read(bin, {type: "binary"}); | 
					
						
							|  |  |  |     console.log(XLSX.utils.sheet_to_csv(workbook.Sheets[workbook.SheetNames[0]])); | 
					
						
							| 
									
										
										
										
											2017-03-28 04:41:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 09:50:51 +00:00
										 |  |  |     /* XLSX.writeFile will not work here -- have to write manually */ | 
					
						
							|  |  |  |     require("fs").write("phantomjs.xlsb", bin, "wb"); | 
					
						
							|  |  |  |     phantom.exit(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-03-28 04:41:01 +00:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 |