52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
		
		
			
		
	
	
			52 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
|  | <!DOCTYPE html> | ||
|  | <html> | ||
|  | <head> | ||
|  |   <meta name="robots" content="noindex"> | ||
|  |   <title>SheetJS + Dojo Store Export Demo</title> | ||
|  | 	<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.14.1/dijit/themes/claro/claro.css"> | ||
|  | </head> | ||
|  | <body class="claro"> | ||
|  |   <h1>SheetJS + Dojo Store Export Demo</h1> | ||
|  |   <br/> | ||
|  |   This demo exports data from a simple Dojo store, attempting to create a XLSX workbook. | ||
|  |   <br/> | ||
|  |   (this HTML page is not minified -- feel free to view source!)<br/><br/> | ||
|  |   <a href="https://docs.sheetjs.com">SheetJS CE Documentation</a><br/><br/> | ||
|  | <script> | ||
|  |   dojoConfig = { | ||
|  |     parseOnLoad: true, | ||
|  |     packages: [ | ||
|  |       { name: "xlsx", location: "https://cdn.sheetjs.com/xlsx-latest/package/dist", main: "xlsx.full.min" } | ||
|  |     ] | ||
|  |   }; | ||
|  | </script> | ||
|  | <script src="//ajax.googleapis.com/ajax/libs/dojo/1.14.1/dojo/dojo.js" data-dojo-config=""></script> | ||
|  | <script> | ||
|  | require([ | ||
|  |   "dojo/store/Memory", | ||
|  |   "dijit/registry", | ||
|  |   "xlsx" | ||
|  | ], function(Memory, registry, _XLSX) { | ||
|  |   /* create simple Memory store */ | ||
|  |   var data = [ | ||
|  |     { Name: "Bill Clinton", Index: 42 }, | ||
|  |     { Name: "GeorgeW Bush", Index: 43 }, | ||
|  |     { Name: "Barack Obama", Index: 44 }, | ||
|  |     { Name: "Donald Trump", Index: 45 }, | ||
|  |     { Name: "Joseph Biden", Index: 46 } | ||
|  |   ]; | ||
|  |   var store = new Memory({data: data}); | ||
|  | 
 | ||
|  |   /* pull all data rows from the store */ | ||
|  |   var rows = store.query(function() { return true; }); | ||
|  | 
 | ||
|  |   /* generate SheetJS workbook */ | ||
|  |   var ws = XLSX.utils.json_to_sheet(rows); | ||
|  |   var wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, "Export"); | ||
|  | 
 | ||
|  |   /* write to file */ | ||
|  |   XLSX.writeFile(wb, "SheetJSDojoStoreExport.xlsx"); | ||
|  | }); | ||
|  | </script> | ||
|  | </body> | ||
|  | </html> |