Skip to main content

路线图

大多数涉及电子表格和数据的场景可以分为 5 个部分:

¥Most scenarios involving spreadsheets and data can be divided into 5 parts:

  1. 获取数据:数据可以存储在任何地方:本地或远程文件、数据库、HTML TABLE,甚至在 Web 浏览器中以编程方式生成。

    ¥Acquire Data: Data may be stored anywhere: local or remote files, databases, HTML TABLE, or even generated programmatically in the web browser.

  2. 提取数据:对于电子表格文件,这涉及解析原始字节以读取单元格数据。对于一般的 JS 数据,这涉及到数据的重塑。

    ¥Extract Data: For spreadsheet files, this involves parsing raw bytes to read the cell data. For general JS data, this involves reshaping the data.

  3. 处理数据:从生成汇总统计数据到清理数据记录,这一步是问题的核心。

    ¥Process Data: From generating summary statistics to cleaning data records, this step is the heart of the problem.

  4. 封装数据:这可能涉及制作新的电子表格或使用 JSON.stringify 进行序列化或编写 XML 或简单地为 UI 工具扁平化数据。

    ¥Package Data: This can involve making a new spreadsheet or serializing with JSON.stringify or writing XML or simply flattening data for UI tools.

  5. 发布数据:电子表格文件可以上传到服务器或在本地编写。数据可以在 HTML TABLE 或数据网格中渲染给用户。

    ¥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 TABLE 将被抓取,一行将添加到底部并包含报告日期,并且将生成一个新文件并下载到本地。XLSX.writeFile 负责打包数据并尝试本地下载:

¥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. XLSX.writeFile takes care of packaging the data and attempting a local download:

// 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");

该库尝试通过从电子表格文件 (read / readFile) 中提取有用数据并从数据 (write / writeFile) 生成新电子表格文件的功能来简化步骤 2 和 4。table_to_book 等其他实用函数可与 HTML 表等其他常见数据源配合使用。

¥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). Additional utility functions like table_to_book work with other common data sources like HTML tables.

本文档和各种演示项目涵盖了步骤 1 和 5 的许多常见场景和方法。

¥This documentation and various demo projects cover a number of common scenarios and approaches for steps 1 and 5.

实用函数有助于完成第 3 步。

¥Utility functions help with step 3.

高亮

¥Highlights

"演示" 描述了将 SheetJS 与其他工具和库结合使用的特殊部署。

¥"Demos" describes special deployments using SheetJS in tandem with other tools and libraries.

"数据导入" 描述了常见数据导入场景的解决方案。

¥"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.

"实用函数" 详细介绍了将 JSON 数组和其他常见 JS 结构转换为工作表对象的实用程序函数。

¥"Utility Functions" details utility functions for translating JSON Arrays and other common JS structures into worksheet objects.