首页 > 解决方案 > 使用 MS Graph 将 excel 转换为 pdf 返回错误文件

问题描述

我正在使用 MS Graph API 将 excel 转换为 pdf。

但是我从 MS Graph API 获得的 pdf 文件与我从打印 Excel 获得的文件不同。

例如:我的 excel 只有 2 页,当我使用 excel 打印 PDF 时,我正好得到 2 页,但是当我使用 MS Graph API 将 excel 转换为 pdf 时,我的 pdf 文件有 4 页。

这是我将 excel 转换为 pdf 的 js 代码,只需将 http 请求作为文档发送:

export const convertPDF = async (token: string, fileID: string): Promise<ArrayBuffer> => {
  return new Promise((resolve, reject): void => {
    const baseUrl = `https://graph.microsoft.com/v1.0/me/drive/items/${fileID}/content?format=pdf`;
    axios
      .get(baseUrl, {
        headers: {
          Authorization: `Bearer ${token}`,
        },
        responseType: "arraybuffer",
      })
      .then((response): void => {
        resolve(response.data);
      });
  });
};

标签: javascriptexcelpdfmicrosoft-graph-api

解决方案


推荐阅读