XLSX-生成报告 - 角度

发布于 2025-02-06 07:21:49 字数 941 浏览 0 评论 0原文

我对自己想要的报告有问题,如下所示:

[
  {
    // ...
    "forma_pago_cliente": [
      {
        "metodo": "product 1",
        "total": "12"
      },
      {
        "metodo": "product 2",
        "total": "45"
      }
    ],
    // ...
];

我得到的结果如下: 结果

和我的预期结果: 在此处输入图像描述

我的代码如下。

const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json, {
      cellDates: true,
    });

  const workbook: XLSX.WorkBook = {
  Sheets: {
    tiquetes_vuelos: worksheet,
  },
  SheetNames: [
    'tiquetes_vuelos',
  ],
};

const excelBuffer: any = XLSX.write(workbook, {
  bookType: 'xlsx',
  type: 'array',
});

this.saveAsExcel(excelBuffer, excelFileName);

我试图获得预期的结果,但我无法做到,我一直在解决这个问题超过2天。有什么建议吗?

I am having a problem with the report I want, delivering the JSON as follows:

[
  {
    // ...
    "forma_pago_cliente": [
      {
        "metodo": "product 1",
        "total": "12"
      },
      {
        "metodo": "product 2",
        "total": "45"
      }
    ],
    // ...
];

The result I get is as follows:
Result

And my expected result:
enter image description here

My code is as follows.

const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json, {
      cellDates: true,
    });

  const workbook: XLSX.WorkBook = {
  Sheets: {
    tiquetes_vuelos: worksheet,
  },
  SheetNames: [
    'tiquetes_vuelos',
  ],
};

const excelBuffer: any = XLSX.write(workbook, {
  bookType: 'xlsx',
  type: 'array',
});

this.saveAsExcel(excelBuffer, excelFileName);

I am trying to get the expected result but I have not been able to, I have been struggling for more than 2 days with this problem. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2025-02-13 07:21:50

您可能需要将forma_pago_cliente对象弄平以在Excel表中表示。
将下面的对象转换为

[
  {
    // ...
    "forma_pago_cliente": [
      {
        "metodo": "product 1",
        "total": "12"
      },
      {
        "metodo": "product 2",
        "total": "45"
      }
    ],
    // ...
];

喜欢,

[
  {
    // ...
    "product 1": 12,
    "product 1": 45,
    // ...
];

You may need to flatten the forma_pago_cliente object in order to represent it in excel sheet.
Convert the below object to

[
  {
    // ...
    "forma_pago_cliente": [
      {
        "metodo": "product 1",
        "total": "12"
      },
      {
        "metodo": "product 2",
        "total": "45"
      }
    ],
    // ...
];

like this,

[
  {
    // ...
    "product 1": 12,
    "product 1": 45,
    // ...
];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文