- function handleGetWorkBook() {
- const id = route.params.id;
- if (typeof id !== 'string') return;
- apiGetForm(id).then(res => {
- fstForm.clone(res)
- if (res.period == '0000-00') {
- buttonType.value = 0
- } else if (Number(route.params.leaf) == 1) {
- buttonType.value = 2
- } else {
- buttonType.value = 3
- }
- const file = new File([base64ToArrayBuffer(res.content)], `${res.name}.xlsx`, {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
- const spread = toRaw(spreadRef.value)
- spread?.import(file, function () {
- loading.value = false
- // 监听清除内容动作
- spread?.bind(GC.Spread.Sheets.Events.RangeChanged, function (sender: any, args: any) {
- console.log(sender, args)
- if (args.action == 2 && !args.isUndo) {
- onCellClear({
- type: 'RangeChanged',
- keyList: args.changedCells.map((item: any) => {
- return spread.name + '-' + args.sheetName + '-' + item.row + '-' + item.col
- })
- })
- }
- })
- // 监听值改变
- spread?.bind(GC.Spread.Sheets.Events.ValueChanged, function (sender: any, args: any) {
- console.log(sender, args)
- if (!args.newValue) {
- const key = spread.name + '-' + args.sheetName + '-' + args.row + '-' + args.col
- onCellClear({
- type: 'ValueChanged',
- keyList: [key]
- })
- }
- })
- spread.name = res.id
- const sheetCount = spread?.getSheetCount() || 0;
- for (let i = 0; i < sheetCount; i++) {
- const sheet = spread?.getSheet(i);
- if (sheet == undefined) continue;
- sheet.options.showFormulas = false
- // sheet.options.isProtected = true
- }
- }, function (err: any) {
- loading.value = false
- console.log(err)
- }, {
- fileType: GC.Spread.Sheets.FileType.excel,
- fullRecalc: false,
- includeFormulas: true,
- openMode: 1
- })
- })
- }
复制代码
你好,我这里目前实现的逻辑是,把内容用import的方式引入后,默认不会fullRecalc,然后切换的时候,会触发以下方法
- function handleFullRecalc() {
- const file = new File([base64ToArrayBuffer(fstForm.content)], `${fstForm.name}.xlsx`, {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
- const spread = toRaw(spreadRef.value)
- spread?.suspendPaint()
- spread?.import(file, function () {
- console.log(spread.name)
- spread?.resumePaint()
- loading.value = false
- }, function (err: any) {
- loading.value = false
- console.log(err)
- }, {
- fileType: GC.Spread.Sheets.FileType.excel,
- includeFormulas: true,
- fullRecalc: fullRecalc.value,
- openMode: 1
- })
- }
复制代码
然后获取公式就不行 |