Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last column numFmt overrides the format of previous colums #2747

Open
alexgarciaalcuadrado opened this issue Apr 17, 2024 · 1 comment
Open

Comments

@alexgarciaalcuadrado
Copy link

I'm using exceljs 4.4.0. So far I haven't had problems with it but now that I'm trying to format my columns i get a weird bug.
I'm writting data like this

const natWorksheet = workbook.worksheets[1];

  let rowIndex = 2; // Start from row 2 (row 1 is title)
  forecast.map((brand) => {
    const Acell = natWorksheet.getCell(`A${rowIndex}`);
    Acell.value = brand.name;
    const Kcell = natWorksheet.getCell(`K${rowIndex}`);
    Kcell.value = Number(brand.forecastBudget.salesGrowth);
    const Lcell = natWorksheet.getCell(`L${rowIndex}`);
    Lcell.value = Number(brand.forecastBudget.revenue);
    const Mcell = natWorksheet.getCell(`M${rowIndex}`);
    Mcell.value = Number(brand.forecastBudget.revenueGrowth);

    rowIndex++;

    brand.brandFamilies.map((brandFamily: any) => {
      const Acell = natWorksheet.getCell(`A${rowIndex}`);
      Acell.value = brandFamily.name;
      Acell.style.alignment = { indent: 2 };
      const Kcell = natWorksheet.getCell(`K${rowIndex}`);
      Kcell.value = Number(brandFamily.forecastBudget.salesGrowth);
      const Lcell = natWorksheet.getCell(`L${rowIndex}`);
      Lcell.value = Number(brandFamily.forecastBudget.revenue);
      const Mcell = natWorksheet.getCell(`M${rowIndex}`);
      Mcell.value = Number(brandFamily.forecastBudget.revenueGrowth);

      rowIndex++;
    });
  });

and at the end i want to format K and M as percentages and L as currency

  const natKcolumn = natWorksheet.getColumn('K');
  natKcolumn.numFmt = '0%';
  const natLcolumn = natWorksheet.getColumn('L');
  natLcolumn.numFmt = '"$"#,##0.00';
  const natMcolumn = natWorksheet.getColumn('M');
  natMcolumn.numFmt = '0%';

But in the xlsx file K, L and M appear as percentages. If i change the order and leave L at the end then all columns appear as currency.
How can i fix it? Same happened when i tried to set the numFmt on each cells.

@chriscappy16
Copy link

I'm having this problem as well. Seems like a bug somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants