Loading...
The copied and exported content can be directly displayed in Excel, and S2 has completed the format compatibility.
This function can quickly copy the content of the table to the clipboard @antv/s2
core layer provides a basic copy function, which can be enabled by configuring enableCopy
The export component of S2 provides copying of original data and copying of formatted data respectively.
Use the shortcut key command/ctrl + c
to copy the selected area (partial copy)
const s2Options = {interaction: {// 是否开启复制copy: { enable: true },// 复制格式化后的数据 (s2DataConfig.meta 中配置的 formatter)withFormat: false,// 复制数值时是否携带所对应的行列头维值withHeader: true,// 圈选复制前,需要开启圈选功能brushSelection: {dataCell: true, // 圈选数值单元格 (默认开启)rowCell: true, // 圈选行头单元格colCell: true, // 圈选列头单元格}}};
HTML
格式)false
const s2Options = {interaction: {copy: { enable: true },withHeader: true,}};
withFormat: 当 S2DataConfig
的 meta
中配置了 自定义格式函数时, 是否按照 formatter
复制数据
const s2DataConfig = {fields: { ... }meta: [{field: 'city',name: '城市',formatter: (value) => `${value}-xx`}]}const s2Options = {interaction: {copy: { enable: true },withFormat: true,}};
@antv/s2-react
component layer provides export function
@antv/s2
内置了一系列工具函数,见下方文档
import { SheetComponent } from '@antv/s2-react'<SheetComponentdataCfg={dataCfg}options={options}header={{export: {open: true}}}/>
Click the copy or download button to export the full amount of data (full amount copy)
Functions such as copying and exporting of the component layer are encapsulated based on a series of tools and methods exposed by the core layer @antv/s2
, which can be self-encapsulated based on tools and methods according to actual business
import { copyData, copyToClipboard, download } from '@antv/s2'// 拿到复制数据const data = copyData(spreadsheet, '\t', false)// 复制数据到剪贴板// 同步复制:copyToClipboard(data, false)copyToClipboard(data).then(() => {console.log('复制成功')}).catch(() => {console.log('复制失败')})// 导出数据download(data, 'filename')
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
spreadsheet | s2 instance | SpreadSheet | ✓ | |
split | delimiter | string | ✓ | |
formatOptions | Whether to format, you can format the data cell and row header separately, and passing Boolean values will take effect on the cell and row header at the same time. | boolean | { formatHeader?: boolean, formatData?: boolean} | false |
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
data | data source | string | ✓ | |
async | Whether to copy data asynchronously (default is asynchronous) | boolean | true |
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
data | data source | string | ✓ | |
filename | file name | string | ✓ |
According to the CSV specification and Excel's handling rules, S2
will process special characters as follows:
,
"
\r
\n
\t
"
within a field will be escaped as two double quotes ""
.\n
will be replaced with \r\n
\r\n
will remain unchanged