forked from sheetjs/sheetjs
		
	- all formats accept `sheetRows` option (fixes #1062 h/t @prog666) - `table_to_*` support for `sheetRows` - demo cleanup
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
 | |
| /* eslint-env browser */
 | |
| /* global XLSX, chrome */
 | |
| chrome.runtime.onInstalled.addListener(function() {
 | |
| 	chrome.contextMenus.create({
 | |
| 		type: "normal",
 | |
| 		id: "sjsexport",
 | |
| 		title: "Export Table to XLSX",
 | |
| 		contexts: ["page", "selection"]
 | |
| 	});
 | |
| 	chrome.contextMenus.create({
 | |
| 		type: "normal",
 | |
| 		id: "sj5export",
 | |
| 		title: "Export All Tables in Page",
 | |
| 		contexts: ["page", "selection"]
 | |
| 	});
 | |
| 	chrome.contextMenus.onClicked.addListener(function(info/*, tab*/) {
 | |
| 		var mode = "";
 | |
| 		switch(info.menuItemId) {
 | |
| 			case 'sjsexport': mode = "JS"; break;
 | |
| 			case 'sj5export': mode = "J5"; break;
 | |
| 			default: return;
 | |
| 		}
 | |
| 		chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
 | |
| 			chrome.tabs.sendMessage(tabs[0].id, {Sheet:mode}, sjsexport_cb);
 | |
| 		});
 | |
| 	});
 | |
| 
 | |
| 	chrome.contextMenus.create({
 | |
| 		id: "sjsabout",
 | |
| 		title: "About",
 | |
| 		contexts: ["browser_action"]
 | |
| 	});
 | |
| 	chrome.contextMenus.onClicked.addListener(function(info/*, tab*/) {
 | |
| 		if(info.menuItemId !== "sjsabout") return;
 | |
| 		chrome.tabs.create({url: "https://sheetjs.com/"});
 | |
| 	});
 | |
| });
 | |
| 
 | |
| function sjsexport_cb(wb) {
 | |
| 	if(!wb || !wb.SheetNames || !wb.Sheets) { return alert("Error in exporting table"); }
 | |
| 	XLSX.writeFile(wb, "export.xlsx");
 | |
| }
 |