Roadmap路线图
Most scenarios involving spreadsheets and data can be divided into 5 parts:大多数涉及电子表格和数据的场景可分为5部分:
1) Acquire Data获取数据: Data may be stored anywhere: local or remote files, databases, HTML TABLE, or even generated programmatically in the web browser.:数据可以存储在任何地方:本地或远程文件、数据库、HTML表,甚至在web浏览器中以编程方式生成。
2) Extract Data提取数据: For spreadsheet files, this involves parsing raw bytes to read the cell data. :对于电子表格文件,这涉及解析原始字节以读取单元格数据。For general JS data, this involves reshaping the data.对于一般JS数据,这涉及到重塑数据。
3) Process Data处理数据: From generating summary statistics to cleaning data records, this step is the heart of the problem.:从生成摘要统计到清理数据记录,这一步是问题的核心。
4) Package Data包数据: This can involve making a new spreadsheet or serializing with :这可能涉及制作新的电子表格,或使用JSON.stringify
or writing XML or simply flattening data for UI tools.JSON.stringify
序列化,或编写XML,或简单地为UI工具展平数据。
5) Release Data发布数据: Spreadsheet files can be uploaded to a server or written locally. :电子表格文件可以上载到服务器或在本地写入。Data can be presented to users in an HTML TABLE or data grid.数据可以在HTML表或数据网格中呈现给用户。
A common problem involves generating a valid spreadsheet export from data stored in an HTML table. 一个常见问题涉及从存储在HTML表中的数据生成有效的电子表格导出。In this example, an HTML TABLE on the page will be scraped, a row will be added to the bottom with the date of the report, and a new file will be generated and downloaded locally. 在本例中,页面上的一个HTML表将被删除,一行将添加到底部,其中包含报告的日期,并将生成一个新文件并在本地下载。XLSX.writeFile
takes care of packaging the data and attempting a local download:XLSX.writeFile
负责打包数据并尝试本地下载:
// Acquire Data (reference to the HTML table)
var table_elt = document.getElementById("my-table-id");
// Extract Data (create a workbook object from the table)
var workbook = XLSX.utils.table_to_book(table_elt);
// Process Data (add a new row)
var ws = workbook.Sheets["Sheet1"];
XLSX.utils.sheet_add_aoa(ws, [["Created "+new Date().toISOString()]], {origin:-1});
// Package and Release Data (`writeFile` tries to write and save an XLSB file)
XLSX.writeFile(workbook, "Report.xlsb");
This library tries to simplify steps 2 and 4 with functions to extract useful data from spreadsheet files (该库尝试使用从电子表格文件(read
/ readFile
) and generate new spreadsheet files from data (write
/ writeFile
). read
/readFile
)中提取有用数据的函数来简化步骤2和4,并从数据(write
/writeFile
)中生成新的电子表格文件。Additional utility functions like 其他实用程序函数(如table_to_book
work with other common data sources like HTML tables.table_to_book
)与其他常见数据源(如HTML表)配合使用。
This documentation and various demo projects cover a number of common scenarios and approaches for steps 1 and 5.本文档和各种演示项目涵盖了步骤1和5的许多常见场景和方法。
Utility functions help with step 3.实用程序功能有助于执行步骤3。
Highlights集锦
"Data Import" describes solutions for common data import scenarios.描述常见数据导入场景的解决方案。
"Data Export" describes solutions for common data export scenarios.描述常见数据导出场景的解决方案。
"Data Processing" describes solutions for common workbook processing and manipulation scenarios.描述常见工作簿处理和操作场景的解决方案。
"Utility Functions" details utility functions for translating JSON Arrays and other common JS structures into worksheet objects.详细介绍了将JSON数组和其他常见JS结构转换为工作表对象的实用函数。