使用JavaScript通过C++禁用Excel中的兼容性检查器

在 JavaScript 中禁用 Excel 工作表的兼容性检查器

如何使用Microsoft Excel禁用兼容性检查器

要在Microsoft Excel中禁用兼容性检查程序(例如Microsoft Excel 2007/2010):

  • (Excel 2007)在办公按钮上,单击准备,然后单击运行兼容性检查,然后清除保存此工作簿时检查兼容性选项。
  • (Excel 2010)单击“文件”选项卡,然后单击信息,再单击“检查问题”,再单击“检查兼容性”,最后清除“保存此工作簿时检查兼容性”选项。

如何使用Aspose.Cells API禁用兼容性检查器

Workbook.checkCompatibility属性设置为false以禁用Microsoft Excel的兼容性检查器。

代码示例

以下示例代码演示如何通过 C++ 使用 Aspose.Cells for JavaScript 来禁用兼容性检查器。

<!DOCTYPE html>
<html>
    <head>
        <title>Aspose.Cells Example</title>
    </head>
    <body>
        <h1>Disable Compatibility Checker Example</h1>
        <input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
        <button id="runExample">Run Example</button>
        <a id="downloadLink" style="display: none;">Download Result</a>
        <div id="result"></div>
    </body>

    <script src="aspose.cells.js.min.js"></script>
    <script type="text/javascript">
        const { Workbook, SaveFormat } = AsposeCells;

        AsposeCells.onReady({
            license: "/lic/aspose.cells.enc",
            fontPath: "/fonts/",
            fontList: [
                "arial.ttf",
                "NotoSansSC-Regular.ttf"
            ]
        }).then(() => {
            console.log("Aspose.Cells initialized");
        });

        document.getElementById('runExample').addEventListener('click', async () => {
            const fileInput = document.getElementById('fileInput');
            if (!fileInput.files.length) {
                document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
                return;
            }

            const file = fileInput.files[0];
            const arrayBuffer = await file.arrayBuffer();

            // Instantiating a Workbook object from the uploaded file
            const workbook = new Workbook(new Uint8Array(arrayBuffer));

            // Disable the compatibility checker
            workbook.settings.checkCompatibility = false;

            // Saving the modified Excel file
            const outputData = workbook.save(SaveFormat.Xlsx);
            const blob = new Blob([outputData]);
            const downloadLink = document.getElementById('downloadLink');
            downloadLink.href = URL.createObjectURL(blob);
            downloadLink.download = 'Output_BK_CompCheck.out.xlsx';
            downloadLink.style.display = 'block';
            downloadLink.textContent = 'Download Excel File';

            document.getElementById('result').innerHTML = '<p style="color: green;">Compatibility check disabled. Click the download link to get the modified file.</p>';
        });
    </script>
</html>