advisr-io / excel4node

Node module to allow for easy Excel file creation
MIT License
128 stars 21 forks source link

Add protection to styles #95

Open supermonkeybrainz opened 6 months ago

supermonkeybrainz commented 6 months ago

This adds the protection option to styles for cells. This allows users to lock specific cells. There are other protection options, but this is a good start.

supermonkeybrainz commented 6 months ago

Allows you to do stuff like this:

  const styles = {
    // Create a reusable style
    unlocked: workbook.createStyle({
      protection: { hidden: false, locked: false },
    }),
  };

  worksheet
        .cell(1, 1)
        .string(`test`)
        .style(styles.unlocked);

Then you can lock the sheet like this:

    const worksheetOptions = {
      sheetProtection: { objects: true, scenarios: true, sheet: true },
    };
    const worksheet = workbook.addWorksheet('Test', worksheetOptions);