1金币
本帖最后由 gnip 于 2024-10-29 17:52 编辑
续之前的填报后导出单元格内容和线上不一致的问题
按照给的解决方案,现在版本更新到17.1.8之后,不会报错了,但是下载后,数据下载后本地预览和线上还是有偏差,出现了明显的单元格样式错位的情况,初步尝试copy出来的sheet,并没有数据,仅仅是个模版的结构,并不是数据渲染后的sheet,导致setArray过后样式出现问题
我的代码如下:
- const spread = GC.Spread.Sheets.findControl(spreadDom.value)
- const sheetTabCount = spreadRef.getSheetTabCount()
- const dataMap = new Map()
- for (let i = 0; i < sheetTabCount; i++) {
- const sheetTab = spreadRef.getSheetTab(i)
- const usedRange = sheetTab.getRange()
- console.log('usedRange---', usedRange)
- 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)
- const tagInfo = sheetTab.getSheet().getCell(i, j).tag()
- if (tagInfo && tagInfo.renderCellValue) {
- value = tagInfo.renderCellValue
- }
- arr.push(value)
- }
- sheetMapItem.push(arr)
- }
- }
- const temp = new GC.Spread.Sheets.Workbook()
- await temp.fromJSON(spread.toJSON())
- resolveColAndRowHeader(true, temp)
- const t_sheetTabCount = temp.getSheetTabCount()
- for (let i = 0; i < t_sheetTabCount; i++) {
- const t_sheetTab = temp.getSheetTab(i)
- const usedRange = t_sheetTab.getRange()
- t_sheetTab.renderMode('Preview')
- t_sheetTab.getSheet().setArray(usedRange.row, usedRange.col, dataMap.get(i))
- }
- console.log('dataMap', dataMap)
- 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
- }
- )
复制代码
|
-
|