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

Merging of cells duplicates the data in other merged cell instead of show text in one cell[BUG] XYZ #2755

Open
bkrajor19 opened this issue Apr 26, 2024 · 2 comments

Comments

@bkrajor19
Copy link

bkrajor19 commented Apr 26, 2024

So, i am facing an issue while merging the cells using excelJs, below is the code where i want to merge the cells from B1 to C1, instead of merging the cell it duplicates the value of B1 into C1.See the Attached screenshot.
Screenshot from 2024-04-26 13-22-03

Lib version: 4.4.0

`async getProjectReport(data) {
try {
// Create a new workbook and add a worksheet for the report
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Project Report');

  // Add headers for the project data table
  worksheet.addRow(['Project No.', 'Project Name']).font = {
    bold: true,
  };

  // merge cells
  worksheet.mergeCells('B1:C1');

  // Set column widths for the project data table
  worksheet.columns = [{ width: 12 }, { width: 30 }, { width: 15 }];

  const projectDetailsRow = worksheet.addRow(['1', 'Project Abc']);

  // Write the workbook to a buffer and return it
  const buffer = await workbook.xlsx.writeBuffer();
  return buffer;
} catch (error) {
  throw new Error(error);
}

}`

The expected behaviour:

I want an output like the attached screenshot
Screenshot from 2024-04-26 13-24-50

I also tried the below function to acheive the output i want but got the same result
// merge by start row, start column, end row, end column (equivalent to K10:M12) worksheet.mergeCells(1,2,2,3);

@dinhhai96-vn
Copy link

It is working properly, you should merge before assigning value to it.

@LSL1618
Copy link

LSL1618 commented May 16, 2024

Try to fill in the value of the cell first,Then merge the cells.

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

3 participants