Utility Functions实用程序函数
The utility functions in this section fall into two categories:本节中的实用程序功能分为两类:
Data Packaging数据打包
The "Input" functions create SheetJS data structures (worksheets or workbooks) from rows of data or other common JS data representations“Input”函数从数据行或其他常见的JS数据表示创建SheetJS数据结构(工作表或工作簿)
These functions are paired with 这些函数与write
or writeFile
to create exports. For example, the following diagram shows the steps to export an HTML TABLE to XLSX:write
或writeFile
成对使用以创建导出。例如,下图显示了将HTML TABLE导出到XLSX的步骤:
Data Extraction数据提取
The "Output" functions extract data from worksheets to friendlier structures.“输出”功能将数据从工作表中提取到更友好的结构中。
These functions are paired with 这些函数与read
or readFile
to process data from files. read
或readFile
成对使用,以处理文件中的数据。The following diagram shows the steps to generate an HTML TABLE from a URL:下图显示了从URL生成HTML TABLE的步骤:
Array Output数组输出
Generate rows of data from a worksheet从工作表生成数据行
var arr = XLSX.utils.sheet_to_json(ws, opts);
This function is described in a dedicated page此功能在专用页面中进行了描述
Array of Arrays Input数组的数组输入
Create a worksheet from an array of arrays从数组创建工作表
var ws = XLSX.utils.aoa_to_sheet(aoa, opts);
Add data from an array of arrays to an existing worksheet将数组中的数据添加到现有工作表
XLSX.utils.sheet_add_aoa(ws, aoa, opts);
These functions are described in a dedicated page这些功能在专用页面中进行了描述
Array of Objects Input对象数组输入
Create a worksheet from an array of objects从对象数组创建工作表
var ws = XLSX.utils.json_to_sheet(aoo, opts);
Add data from an array of objects to an existing worksheet将对象数组中的数据添加到现有工作表中
XLSX.utils.sheet_add_json(ws, aoo, opts);
These functions are described in a dedicated page这些功能在专用页面中进行了描述
HTML Table InputHTML表格输入
Create a worksheet or workbook from a TABLE element从TABLE元素创建工作表或工作簿
var ws = XLSX.utils.table_to_sheet(elt, opts);
var wb = XLSX.utils.table_to_book(elt, opts);
Add data from a TABLE element to an existing worksheet将TABLE元素中的数据添加到现有工作表中
XLSX.utils.sheet_add_dom(ws, elt, opts);
These functions are described in a dedicated page这些功能在专用页面中进行了描述
HTML OutputHTML输出
Display worksheet data in a HTML table在HTML表中显示工作表数据
var html = XLSX.utils.sheet_to_html(ws, opts);
This function are described in a dedicated page此功能在专用页面中进行了描述
Delimiter-Separated Output分隔符分隔的输出
Generate CSV from a Worksheet从工作表生成CSV
var csv = XLSX.utils.sheet_to_csv(ws, opts);
Export worksheet data in "UTF-16 Text" or Tab-Separated Values (TSV)以“UTF-16文本”或制表符分隔值(TSV)导出工作表数据
var txt = XLSX.utils.sheet_to_txt(ws, opts);
These functions are described in a dedicated page这些功能在专用页面中进行了描述
Formulae Output公式输出
Extract all formulae from a worksheet从工作表中提取所有公式
var fmla_arr = XLSX.utils.sheet_to_formulae(ws);
This function is described in a dedicated page此功能在专用页面中进行了描述