Newer
Older
smart-metering-front / src / views / business / lab / excelEdit / index.ts
dutingting on 26 Mar 1 KB spreadJS试用
/** 这里定义一些工作表基础使用方法 */
import * as GC from '@grapecity-software/spread-sheets'
/**
 * 导入xlsx、ssjson、csv
 * @param spread sprad实例
 * @param file 文件
 */
export function importFile(spread: any, file: File) {
  console.log('spread:开始执行文件导入')
  console.log('spread', spread)
  console.log('file', file)
  return new Promise((resolve) => {
    spread.import(
      file,
      () => {
        console.log('spread:导入文件成功')
        resolve('')
      },
      (e: any) => {
        console.log('spread:上传文件发生错误', e)
      },
      {
        fileType: GC.Spread.Sheets.FileType.excel,
      },
    )
  })
}

/**
 * 导入ssj
 * @param spread sprad实例
 * @param file 文件
 */
export function importSjsFile(spread: any, file: File) {
  console.log('spread:开始执行文件导入')
  return new Promise((resolve) => {
    spread.open(
      file,
      () => {
        console.log('spread:导入sjs文件成功')
        resolve('')
      },
      (e: any) => {
        console.log('spread:上传sjs文件发生错误', e)
      },
    )
  })
}

/**
 * 导入(方法来源于视频)---暂时不用
 * @param spread sprad实例
 * @param file 文件
 */
export function excelIOimportFile(excelIO: any, file: File) {
  excelIO.open(
    file,
    () => {
      console.log('excelIO:导入文件成功') // 错误回调函数
    },
    (e: any) => {
      console.log('excelIO:上传文件发生错误', e) // 错误回调函数
    },
  )
}