1

I want to insert checkbox button into cell and I want to check it when it true how can i do

How can I insert checkbox button into cell with nodejs.checkbox button and I try to use exceljs, excel4node, xlsx i can't do it. Pls help!!!!

Gorrof
  • 11
  • 1

1 Answers1

0
const ExcelJS = require('exceljs');

async function insertCheckbox() {
  const workbook = new ExcelJS.Workbook();
  const worksheet = workbook.addWorksheet('Sheet 1');

  // Add a checkbox to a specific cell
  const cell = worksheet.getCell('A1');
  cell.type = ExcelJS.ValueType.Boolean;
  cell.value = true;
  cell.style = {
    alignment: {
      horizontal: 'center',
      vertical: 'middle'
    }
  };

  // Save the workbook
  await workbook.xlsx.writeFile('output.xlsx');
  console.log('Checkbox inserted successfully.');
}

insertCheckbox().catch(console.error);

In the above code, we create a new Excel workbook and add a worksheet. We then specify the cell where we want to insert the checkbox, which is cell 'A1' in this example. We set the cell's type to boolean and assign true to indicate a checked checkbox. Finally, we save the workbook to a file called output.xlsx.

Make sure to adjust the cell reference and other formatting options as needed for your specific use case.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31