1

Can you recommend some tool or library that I can incorporate into my React / SPFX project what would be capable of doing some modifications to one of the sheet in existing multi-sheet Excel file?

The spreadsheet itself is quite complex, many sheets, calculations, formulas etc. First sheet acts as a data source so the goal is to open the file, fill in first sheet with data and save, so the rest of the sheets can pick up this data when the file is re-opened by other users. This is pretty much my use case. Seems to be simple, but my first look on the net proves that the libraries are usually about creating spreadsheets and downloading them, not editing unfortunately.

Would be greatfull if someone here can share some experiences / thoughts.

Thanks!

Regards M.

1 Answers1

1

One option for modifying an existing Excel file in a React or SPFX project is to use the ExcelJS library. ExcelJS is a JavaScript library that allows you to read, manipulate, and write spreadsheet data in a variety of formats, including Excel files.

To use ExcelJS in your project, you will need to install the library using npm:

npm install exceljs

Once the library is installed, you can use the "ExcelJS.Workbook" class to open an existing Excel file and modify the data in the file. For example, you can use the following code to open an existing Excel file and update the data in the first sheet:

import ExcelJS from 'exceljs';

async function updateExcelFile(filePath, data) {
  // Open the existing Excel file
  const workbook = new ExcelJS.Workbook();
  await workbook.xlsx.readFile(filePath);

  // Get the first sheet in the file
  const sheet = workbook.getWorksheet(1);

  // Update the data in the sheet
  sheet.getCell('A1').value = data;

  // Save the changes to the file
  await workbook.xlsx.writeFile(filePath);
}

This code opens the specified Excel file using the readFile() method of the Workbook class, gets the first sheet in the file using the getWorksheet() method, updates the data in the sheet using the getCell() and value properties, and saves the changes to the file using the writeFile() method.

You can use the ExcelJS