1金币
之前发了一篇帖子名为【报表自定义单元格后导出单元格文本不对】,按照下面所给的解决方案,但是我本地测试,spreadjs内部直接抛出错了
以下是我导出的代码逻辑
- const spread = GC.Spread.Sheets.findControl(spreadDom.value)
- spread.suspendPaint()
- const sheetTabCount = spread.getSheetTabCount()
- const dataMap = new Map()
- for (let i = 0; i < sheetTabCount; i++) {
- const sheetTab = spread.getSheetTab(i)
- const usedRange = sheetTab.getRange()
- dataMap.set(i, [])
- const sheetMapItem = dataMap.get(i)
- for (let i = 0; i < usedRange.rowCount; i++) {
- const arr = []
- for (let j = 0; j < usedRange.colCount; j++) {
- let value = sheetTab.getValue(i, j)
- value = typeof v === 'object' ? value.label : value
- arr.push(value)
- }
- sheetMapItem.push(arr)
- }
- }
- spread.resumePaint()
- const temp = new GC.Spread.Sheets.Workbook()
- await temp.fromJSON(spread.toJSON())
- const t_sheetTabCount = spread.getSheetTabCount()
- for (let i = 0; i < t_sheetTabCount; i++) {
- const t_sheetTab = temp.getSheetTab(i)
- const usedRange = t_sheetTab.getRange()
- t_sheetTab.getSheet().setArray(usedRange.row, usedRange.col, dataMap.get(i))
- }
- console.log('dataMap.get(i)', temp)
- temp.export(
- (blob) => {
- fileSaver.saveAs(
- blob,
- `${
- typeof downloadFieldName === 'string'
- ? downloadFieldName
- : reportDetail.value.reportName
- }.xlsx`
- )
- // 隐藏行头
- setTimeout(() => {
- resolveColAndRowHeader(false, temp)
- sheetLoading.value = false
- }, 200)
- ElMessage({
- message: '导出成功',
- type: 'success'
- })
- },
- null,
- {
- fileType: GC.Spread.Sheets.FileType.excel
- }
- )
复制代码
|
|