dtjohnson / xlsx-populate

Excel XLSX parser/generator written in JavaScript with Node.js and browser support, jQuery/d3-style method chaining, encryption, and a focus on keeping existing workbook features and styles in tact.
MIT License
956 stars 183 forks source link

Max content height is not working #364

Open vel-kathir opened 9 months ago

vel-kathir commented 9 months ago

const handleExport = (data) => { const title = [ [ "SL.No", "Employee Name", "Portfolio data saved", "Processed by", "Processing and Checking of portfolio data", "Processed by", "Reconciliation of data and reports", "Processed by", "Review of reconciliation and reports", "Processed by", "2nd level review of reconciliation and reports submitted by SRM", "Processed by", "Release the report to the client", "Processed by", ], ];

const getCellStyle = (val) => {
  const stringValue = String(val);
  const numericValue = parseFloat(stringValue);
  console.log(numericValue, "luslhfhksgfkgjkgjhjkl");
  return isNaN(numericValue)
    ? "000000"
    : numericValue === 0
    ? stringValue.startsWith("-")
      ? "E2A42C"
      : "00861D"
    : numericValue < 0
    ? "E22C2C"
    : "00861D";
};

const rows = data.flatMap((family, index) => {
  return [
    [
      index + 1,
      family.familyName,
      family.task1balanceSla === 0 || family.task1balanceSla === null
        ? ""
        : convertDecimalDaysToTime(family.task1balanceSla),
      family.task1employeeName || "N/A",
      family.task2balanceSla === 0 || family.task2balanceSla === null
        ? ""
        : convertDecimalDaysToTime(family.task2balanceSla),
      family.task2employeeName || "N/A",
      family.task3balanceSla === 0 || family.task3balanceSla === null
        ? ""
        : convertDecimalDaysToTime(family.task3balanceSla),
      family.task3employeeName || "N/A",
      family.task4balanceSla === 0 || family.task4balanceSla === null
        ? ""
        : convertDecimalDaysToTime(family.task4balanceSla),
      family.task4employeeName || "N/A",
      family.task5balanceSla === 0 || family.task5balanceSla === null
        ? ""
        : convertDecimalDaysToTime(family.task5balanceSla),
      family.task5employeeName || "N/A",
      family.task6balanceSla === 0 || family.task6balanceSla === null
        ? ""
        : convertDecimalDaysToTime(family.task6balanceSla),
      family.task6employeeName || "N/A",
    ],
  ];
});

const finalData = [...title, ...rows];

return XlsxPopulate.fromBlankAsync()
  .then((workbook) => {
    finalData.forEach((row, rowIndex) => {
      row.forEach((cellValue, colIndex) => {
        const cell = workbook.sheet(0).cell(rowIndex + 1, colIndex + 1);
        cell.value(cellValue);
        console.log(cellValue, parseFloat(cellValue));
        if (
          colIndex === 2 ||
          colIndex === 4 ||
          colIndex === 6 ||
          colIndex === 8 ||
          colIndex === 10 ||
          colIndex === 12
        ) {
          cell.style({
            fontColor: getCellStyle(cellValue),
          });
        }
        cell.style({
          horizontalAlignment: "center",
          verticalAlignment: "center",
          wrapText: true,
        });
      });
    });

    workbook.sheet(0).range("A1:N1").style({
      bold: true,
      horizontalAlignment: "center",
      verticalAlignment: "center",
      fontColor: "000000",
    });
    workbook.sheet(0).row(1).height(25);
    const columnWidths = [
      8, 20, 25, 30, 40, 30, 35, 30, 40, 30, 65, 30, 35, 30,
    ];
    columnWidths.forEach((width, index) => {
      workbook
        .sheet(0)
        .column(index + 1)
        .width(width);
    });

    return workbook.outputAsync();
  })
  .then((blob) => URL.createObjectURL(blob));

};

handleExport(response?.data?.employeeData).then((url) => { const downloadAnchorNode = document.createElement("a"); downloadAnchorNode.setAttribute("href", url); downloadAnchorNode.setAttribute( "download", Customer_Analytics_Progress_${formattedDate}.xlsx ); downloadAnchorNode.click(); downloadAnchorNode.remove(); });

image