这个是初始化的代码:
- const fetchData = usePersistFn(
- async (
- columnDataBindings: string[],
- spreadDataColumns: ColumnSchemaUnion[],
- ) => {
- let dataTotal: string | null = null
- 请求数据。。。
- if (spreadWorkbook && activeSheet) {
- activeSheet.suspendPaint()
- activeSheet.setRowCount(dataTotal ? Number(dataTotal) + 50 : 200)
- activeSheet.setColumnCount(spreadDataColumns.length + 20)
- const Json = window.localStorage.getItem(
- `spreadViewSummary_${templateId}`,
- )
- if (!Json) {
- activeSheet.tables.add(
- 'table1',
- 0,
- 0,
- lists.length,
- spreadDataColumns.length,
- )
- }
- 创建表格即初始化
- const table = activeSheet.tables.findByName('table1')
- table.showHeader(true)
- table.style(Spread.Sheets.Tables.TableThemes.medium7)
- const tableColumns = spreadDataColumns.map((item, index) => {
- activeSheet.setColumnWidth(index, 200)
- return new Spread.Sheets.Tables.TableColumn(
- index,
- item.binding,
- item.name,
- item.dataType === 'Date' ? 'yyyy-MM-dd' : undefined,
- undefined,
- needNameMapFields.includes(item.binding)
- ? (value: Record<string, any>) => {
- return (
- accountSvc.getAccountSync(value[item.binding])
- ?.displayName || ''
- )
- }
- : needTicketStatusMapFields.includes(item.binding)
- ? (value: Record<string, any>) => {
- return ticketStatusDataMap.get(value[item.binding]) || ''
- }
- : undefined,
- )
- })
- table.autoGenerateColumns(false)
- table.bind(tableColumns, undefined, lists)
- activeSheet.suspendCalcService(false)
-
- // 禁止数据范围的单元格编辑
- const style = new Spread.Sheets.Style()
- style.locked = false
- activeSheet
- .getRange(lists.length + 1, 0, 50, spreadDataColumns.length + 20)
- .setStyle(style)
- activeSheet
- .getRange(0, spreadDataColumns.length, lists.length + 50, 20)
- .setStyle(style)
- activeSheet.options.isProtected = true
- activeSheet.resumeCalcService(true)
-
- activeSheet.resumePaint()
- }
- setSpreadViewData(lists)
- },
- )
复制代码 |