TS2339:“工作表”类型上不存在属性“getOoxml”

问题描述 投票:0回答:1

使用节点v20.12.0 “反应”:“^18.2.0”

我已经使用 yo man Generator for Office 版本 5.0.0 创建了 React 应用程序。

文件代码如下:

async function getExcelOOXML() {
    try {
        await Excel.run(async (context) => {
            const sheet = context.workbook.worksheets.getActiveWorksheet();
            const ooxml = sheet.getOoxml();
            await context.sync();

            console.log('OOXML content:', ooxml.value);
            // Handle the OOXML data as needed
        });
    } catch (error) {
        console.error('Error retrieving OOXML:', error);
    }
}


export default getExcelOOXML;

出现以下错误:

  TS2339: Property 'getOoxml' does not exist on type 'Worksheet'.

请提供合适的修复方法。 我已尝试安装开发依赖项,但问题仍然存在:

 npm install @types/office-js --save-dev

请提供可以解决问题的可能解决方案或解决指导。

reactjs office-js
1个回答
0
投票

错误是正确的。 Worksheet 类型上没有这样的方法。仅 Word 支持

getOoxml
方法。 Excel 中没有。

© www.soinside.com 2019 - 2024. All rights reserved.