本帖最后由 Matthew.Xue 于 2026-1-16 16:10 编辑
- readFile() {
- let filePath
- if (this.queryParam.type == 2) {
- filePath = '/templates/宏观成本计算对象报表模板两侧LC.xlsx' // 请替换为实际的另一张表文件名
- } else if (this.queryParam.type == 3) {
- filePath = '/templates/宏观成本计算对象报表模板雁宝公司LC.xlsx'
- } else {
- filePath = '/templates/宏观成本计算对象报表模板LC.xlsx'
- }
- console.log(filePath, 'filePath')
- // 宏观成本计算对象报表模板雁宝公司LC
- fetch(filePath)
- .then((response) => {
- return response.blob()
- })
- .then((data) => {
- this.readWithFromJson(data, this.spread)
- })
- .catch((error) => {
- console.log('读取文件失败', error)
- })
- },
- readWithFromJson(data, spread) {
- const file = new File([data], 'temp.xlsx', {
- type:
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- })
- const reader = new FileReader()
- reader.onload = (e) => {
- var io = new ExcelIO.IO()
- io.open(
- e.target.result,
- (json) => {
- // 在 fromJSON 完成后执行
- spread.fromJSON(json)
- const sheet = spread.getActiveSheet() // 获取当前工作表
- // sheet.setValue(0, 2, `${this.peiZhi.budgetYear}年经营情况预算表`) // 设置单位名称
- console.log(sheet, 'sheet')
- spread.options.scrollbarMaxAlign = true
- spread.options.tabStripVisible = false
- const products = this.getProducts(
- this.dataSource[0].macroCostReportDetailsList.length,
- ) // 假设 getProducts 是你的数据方法
- const dataArray = products.map((item) => Object.values(item))
- sheet.setArray(3, 3, dataArray)
- // // 7. 调整列宽
- sheet.setColumnWidth(0, 120)
- sheet.setRowHeight(0, 60)
- sheet.setColumnWidth(0, 120)
- sheet.setColumnWidth(20, 500)
- console.log(this.columnCount, 'this.columnCount')
- for (let i = 2; i < this.columnCount - 1; i++) {
- sheet.setColumnWidth(i, 180)
- }
- },
- (error) => {
- console.log('导入失败', error)
- },
- )
- }
- reader.readAsArrayBuffer(file)
- }
复制代码
我npm run build打包以后,部署在系统上报错404未找到,
但是dist里有这个文件他这个要怎么设置?
|