2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
									
										
										
										
											2023-01-22 04:23:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								title: Browser Automation
							 
						 
					
						
							
								
									
										
										
										
											2023-10-23 01:20:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pagination_prev: demos/net/email/index
							 
						 
					
						
							
								
									
										
										
										
											2024-04-01 10:44:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								pagination_next: demos/net/dom
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-27 09:12:19 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import current from '/version.js';
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import Tabs from '@theme/Tabs';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import TabItem from '@theme/TabItem';
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import CodeBlock from '@theme/CodeBlock';
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								Headless automation involves controlling "headless browsers" to access websites
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								and submit or download data.  It is also possible to automate browsers using
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								custom browser extensions.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-22 06:32:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The [SheetJS standalone scripts ](/docs/getting-started/installation/standalone )
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								can be added to any website by inserting a `SCRIPT`  tag.  Headless browsers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								usually provide utility functions for running custom snippets in the browser and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								passing data back to the automation script.
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Use Case
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This demo focuses on exporting table data to a workbook.  Headless browsers do
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								not generally support passing objects between the browser context and the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								automation script, so the file data must be generated in the browser context
							 
						 
					
						
							
								
									
										
										
										
											2023-01-22 04:23:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								and sent back to the automation script for saving in the file system.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This demo exports data from https://sheetjs.com/demos/table.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::note pass
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								It is also possible to parse files from the browser context, but parsing from
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								the automation context is more efficient and strongly recommended.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#### Key Steps
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-01-22 04:23:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```mermaid
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								sequenceDiagram
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  autonumber off
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  actor U as User
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  participant C as Controller
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  participant B as Browser
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  U->>C: run script
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  rect rgba(255, 0, 0, 0.25)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    C->>B: launch browser
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    C->>B: load URL
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  rect rgba(0, 127, 0, 0.25)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    C->>B: add SheetJS script
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  rect rgba(255, 0, 0, 0.25)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    C->>B: ask for file
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Note over B: scrape tables
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Note over B: generate workbook
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    B->>C: file bytes
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  rect rgba(0, 127, 0, 0.25)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    C->>U: save file
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  end
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1) Launch the headless browser and load the target site.
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								2) Add the standalone SheetJS build to the page in a `SCRIPT`  tag.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								3) Add a script to the page (in the browser context) that will:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  Make a SheetJS workbook object[^1] from the first table using the SheetJS 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  `table_to_book` [^2] method.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  Generate the bytes for an XLSB file using the SheetJS `write` [^3] method. 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								-  Send the bytes back to the automation script 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								4) When the automation context receives data, save to a file
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Puppeteer
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[Puppeteer ](https://pptr.dev/ ) enables headless Chromium automation for NodeJS
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								and BunJS. Releases ship with a script that installs a headless browser.
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								Binary strings are the favored data type.  They can be safely passed from the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								browser context to the automation script.  NodeJS provides an API to write
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								binary strings to file (`fs.writeFileSync` using encoding `binary` ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The key steps are commented below:
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< CodeBlock  language = "js"  title = "SheetJSPuppeteer.js" > {`\ 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								const fs = require("fs");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const puppeteer = require('puppeteer');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(async () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /* (1) Load the target page */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const browser = await puppeteer.launch();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const page = await browser.newPage();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  page.on("console", msg => console.log("PAGE LOG:", msg.text()));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  await page.setViewport({width: 1920, height: 1080});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  await page.goto('https://sheetjs.com/demos/table');
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  /* (2) Load the standalone SheetJS build from the CDN */
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  await page.addScriptTag({ url: 'https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js' });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  /* (3) Run the snippet in browser and return data */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const bin = await page.evaluate(() => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /* NOTE: this function will be evaluated in the browser context.
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       \`page\`, \`fs\` and \`puppeteer\` are not available.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       \`XLSX\` will be available thanks to step 2 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* find first table */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var table = document.body.getElementsByTagName('table')[0];
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* call table_to_book on first table */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var wb = XLSX.utils.table_to_book(table);
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* generate XLSB and return binary string */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return XLSX.write(wb, {type: "binary", bookType: "xlsb"});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  });
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  /* (4) write data to file */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fs.writeFileSync("SheetJSPuppeteer.xlsb", bin, { encoding: "binary" });
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  await browser.close();
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								})();`}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**Demo**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 03:29:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::note Tested Deployments
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This demo was tested in the following deployments:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| Puppeteer | Date       |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								|:----------|:-----------|
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `23.11.1`  | 2024-12-31 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `22.15.0`  | 2024-12-31 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `21.11.0`  | 2024-12-31 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `20.9.0`   | 2024-12-31 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `15.5.0`   | 2024-12-31 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `10.4.0`   | 2024-12-31 |
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1) Install SheetJS and Puppeteer:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< Tabs  groupId = "ssplat" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < TabItem  value = "nodejs"  label = "NodeJS" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< CodeBlock  language = "bash" > {`\ 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz puppeteer@23.11.1`}
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < TabItem  value = "bunjs"  label = "BunJS" > 
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< CodeBlock  language = "bash" > {`\ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bun install https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz puppeteer@23.11.1`}
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / Tabs >  
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								2) Save the `SheetJSPuppeteer.js`  code snippet to `SheetJSPuppeteer.js` .
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								3) Run the script:
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< Tabs  groupId = "ssplat" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < TabItem  value = "nodejs"  label = "NodeJS" > 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								node SheetJSPuppeteer.js
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < TabItem  value = "bunjs"  label = "BunJS" > 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								bun SheetJSPuppeteer.js
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / Tabs >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When the script finishes, the file `SheetJSPuppeteer.xlsb`  will be created.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This file can be opened with a spreadsheet editor that supports XLSB workbooks.
							 
						 
					
						
							
								
									
										
										
										
											2022-08-25 08:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								## Playwright
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 03:29:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[Playwright ](https://playwright.dev/ ) presents a unified scripting framework for
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Chromium, WebKit, and other browsers. It draws inspiration from Puppeteer. In
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								fact, the example code is almost identical!
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Differences from the Puppeteer example are highlighted below:
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< CodeBlock  language = "js"  title = "SheetJSPlaywright.js" > {`\ 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								const fs = require("fs");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// highlight-next-line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const { webkit } = require('playwright'); // import desired browser
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(async () => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /* (1) Load the target page */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // highlight-next-line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const browser = await webkit.launch(); // launch desired browser
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const page = await browser.newPage();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  page.on("console", msg => console.log("PAGE LOG:", msg.text()));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // highlight-next-line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  await page.setViewportSize({width: 1920, height: 1080}); // different name :(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  await page.goto('https://sheetjs.com/demos/table');
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  /* (2) Load the standalone SheetJS build from the CDN */
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  await page.addScriptTag({ url: 'https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js' });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  /* (3) Run the snippet in browser and return data */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const bin = await page.evaluate(() => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /* NOTE: this function will be evaluated in the browser context.
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								       \`page\`, \`fs\` and the browser engine are not available.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								       \`XLSX\` will be available thanks to step 2 */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* find first table */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var table = document.body.getElementsByTagName('table')[0];
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* call table_to_book on first table */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var wb = XLSX.utils.table_to_book(table);
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* generate XLSB and return binary string */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return XLSX.write(wb, {type: "binary", bookType: "xlsb"});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  });
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  /* (4) write data to file */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fs.writeFileSync("SheetJSPlaywright.xlsb", bin, { encoding: "binary" });
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  await browser.close();
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								})();`}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								**Demo**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 03:29:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::note Tested Deployments
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This demo was tested in the following deployments:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| Playwright | Date       |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								|:-----------|:-----------|
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `1.49.1`    | 2024-12-31 |
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								1) Install SheetJS and Playwright:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< Tabs  groupId = "ssplat" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < TabItem  value = "nodejs"  label = "NodeJS" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< CodeBlock  language = "bash" > {`\ 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz playwright@1.49.1`}
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < TabItem  value = "bunjs"  label = "BunJS" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< CodeBlock  language = "bash" > {`\ 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bun install https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz playwright@1.49.1`}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / Tabs >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								2) Save the `SheetJSPlaywright.js`  code snippet to `SheetJSPlaywright.js` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								3) Run the script
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< Tabs  groupId = "ssplat" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < TabItem  value = "nodejs"  label = "NodeJS" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								node SheetJSPlaywright.js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < TabItem  value = "bunjs"  label = "BunJS" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								bun SheetJSPlaywright.js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < / TabItem > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / Tabs >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When the script finishes, the file `SheetJSPlaywright.xlsb`  will be created.
							 
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This file can be opened with a spreadsheet editor that supports XLSB workbooks.
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::caution pass
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 03:29:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The commmand may fail with a message such as:
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								╔═════════════════════════════════════════════════════════════════════════╗
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								║ Looks like Playwright Test or Playwright was just installed or updated. ║
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								║ Please run the following command to download new browsers:              ║
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								║                                                                         ║
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								║     npx playwright install                                              ║
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								║                                                                         ║
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								║ < 3  Playwright  Team                                                       ║ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								╚═════════════════════════════════════════════════════════════════════════╝
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 03:29:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Running the recommended command will download and install browser engines:
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								npx playwright install
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 03:29:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								After installing engines, re-run the script.
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								## PhantomJS
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-11-07 10:41:00 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								PhantomJS is a headless web browser powered by WebKit.
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-14 07:40:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::danger pass
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This information is provided for legacy deployments.  PhantomJS development has
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								been suspended and there are known vulnerabilities, so new projects should use
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								alternatives.  For WebKit automation, new projects should use Playwright.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Binary strings are the favored data type.  They can be safely passed from the
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								browser context to the automation script.  PhantomJS provides an API to write
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								binary strings to file (`fs.write` using mode `wb` ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-01-23 18:52:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::note Tested Deployments
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This demo was tested in the following environments:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| Architecture | PhantomJS | Date       |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								|:-------------|:----------|:-----------|
							 
						 
					
						
							
								
									
										
										
										
											2025-04-01 02:57:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| `darwin-x64`  | `2.1.1`    | 2025-03-31 |
							 
						 
					
						
							
								
									
										
										
										
											2025-01-23 18:52:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								| `win11-x64`   | `2.1.1`    | 2025-01-19 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								| `linux-x64`   | `2.1.1`    | 2025-01-07 |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-08 04:47:04 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< details >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < summary > < b > Integration Details and Demo< / b >  (click to show)< / summary > 
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The steps are marked in the comments:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< CodeBlock  language = "js"  title = "SheetJSPhantom.js" > {`\ 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								var page = require('webpage').create();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								page.onConsoleMessage = function(msg) { console.log(msg); };
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/* (1) Load the target page */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								page.open('https://sheetjs.com/demos/table', function() {
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  /* (2) Load the standalone SheetJS build from the CDN */
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  page.includeJs("https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js", function() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* (3) Run the snippet in browser and return data */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var bin = page.evaluateJavaScript([ "function(){",
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      /* find first table */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "var table = document.body.getElementsByTagName('table')[0];",
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      /* call table_to_book on first table */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "var wb = XLSX.utils.table_to_book(table);",
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								      /* generate XLSB file and return binary string */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "return XLSX.write(wb, {type: 'binary', bookType: 'xlsb'});",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "}" ].join(""));
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    /* (4) write data to file */
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    require("fs").write("SheetJSPhantomJS.xlsb", bin, "wb");
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								\n\
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    phantom.exit();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  });
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								});`}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / CodeBlock >  
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-16 18:54:32 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::caution pass
							 
						 
					
						
							
								
									
										
										
										
											2022-07-07 04:05:14 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								PhantomJS is very finicky and will hang if there are script errors.  It is
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								strongly recommended to add verbose logging and to lint scripts before use.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								**Demo**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-29 03:29:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								1) [Download and extract PhantomJS ](https://phantomjs.org/download.html )
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								2) Save the `SheetJSPhantom.js`  code snippet to `SheetJSPhantom.js` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								3) Run the `phantomjs`  program and pass the script as the first argument.
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-14 08:19:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For example, if the macOS Archive Utility unzipped the `2.1.1`  release, binaries
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								will be placed in `phantomjs-2.1.1-macosx/bin/`  and the command will be:
							 
						 
					
						
							
								
									
										
										
										
											2023-04-29 11:21:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								./phantomjs-2.1.1-macosx/bin/phantomjs SheetJSPhantom.js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								When the script finishes, the file `SheetJSPhantomJS.xlsb`  will be created.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This file can be opened with Excel.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-01 10:44:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								:::caution pass
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								When this demo was last tested on Linux, there were multiple errors.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This application failed to start because it could not find or load the Qt platform plugin "xcb".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The environment variable `QT_QPA_PLATFORM=phantom`  resolves the issue. There is
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								a different error after assignment:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								140412268664640:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libproviders.so): libproviders.so: cannot open shared object file: No such file or directory
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								140412268664640:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								140412268664640:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=providers, path=providers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								140412268664640:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=providers
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								This error is resolved by ignoring SSL errors. The complete command is:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								env OPENSSL_CONF=/dev/null QT_QPA_PLATFORM=phantom ./phantomjs-2.1.1-linux-x86_64/bin/phantomjs --ignore-ssl-errors=true test.js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:::
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-16 18:54:32 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / details >  
						 
					
						
							
								
									
										
										
										
											2025-01-06 02:51:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[^1]: See ["Workbook Object" ](/docs/csf/book ) for more details about the SheetJS workbook object.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[^2]: See [`table_to_book` in "HTML" Utilities ](/docs/api/utilities/html#create-new-sheet )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[^3]: See [`write` in "Writing Files" ](/docs/api/write-options )