使用 MS 插件更改 Powerpoint 的内容

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

我正在尝试在 MS-PowerPoint 中打开演示文稿。我已经为它创建了一个加载项。它有一个按钮,单击 s3 中的按钮即可检索文件,然后将文件上传到登录用户的 OneDrive 中。 我可以在后端使用 Microsoft Graph API 和 S3 API 来实现它。 但是,我无法替换当前在 PowerPoint 中打开的文件,图形 API 给出 423 错误,因为我无法修改已打开的文件。 还有其他方法可以实现这一目标吗? 我可以使用 Office JavaScript API 吗?如果是,我如何解析从 S3 获得的 blob 文件的内容? 会有多复杂?

async function uploadToOneDrive(fileBlob, fileName, accessToken) {
    const uploadUrl = `https://graph.microsoft.com/v1.0/me/drive/root:/Documents/${fileName}:/content`;

    try {
        const response = await fetch(uploadUrl, {
            method: 'PUT',
            headers: {
                'Authorization': `Bearer ${accessToken}`,
                'Content-Type': 'application/octet-stream'
            },
            body: fileBlob
        });

        if (!response.ok) {
            throw new Error(`Error uploading file to OneDrive: ${response.statusText}`);
        }
    } catch (error) {
        console.error('Upload to OneDrive failed:', error);
    }
}

我正在使用 Graph API 上传文件并使用 MSAL 库,因为我之前使用过它,但是这会失败,并且会为我打开的文件提供 423 错误。

amazon-s3 microsoft-graph-api powerpoint-addins javascript-api-for-office
1个回答
0
投票

如果你

} catch (error) {
        console.error('Upload to OneDrive failed:', error);

未激活,请使用 PowerShell 脚本检查您的代码。

Start-Process -FilePath "C:\Path\To\YourExecutable.exe" -ArgumentList "arg1", "arg2"
-- With parameters using JS   


-- Using norm Powershell opening

.\YourExecutable.exe
-- Paths
C:/Path/Path/Path/File

我不擅长编码,我无法回答一些编码,但我很乐意帮助其中一些,如果我错了,我很抱歉!

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