Add new column using LinqToExcel

35 Views Asked by At

Using LinqToExcel (https://github.com/paulyoder/LinqToExcel), I'd like to know how I can add a new column to the end of each row of a user-uploaded Excel file, and then allow the user to download the modified Excel file so they can view the results in the new column (ideally the Excel file with the new column would only be created in memory and streamed rather than saved on physical disk).

var excelFile = new ExcelQueryFactory(@"C:\MyExcelFile.xlsx");
var worksheetName = excelFile.GetWorksheetNames().FirstOrDefault();

Original File

Name | Email
--------------------
John | [email protected]

The change would be to add a new "Sent" column to the end of each row:

New File

Name | Email | Sent
--------------------
John | [email protected] | Yes

This will be used for random user-uploaded files that have a variable number of columns. I'm looking for a solution that avoids manually creating a new custom Excel file based on mapping the data from the original to a new custom object, because in the event I write "No" in a "Sent" cell, I would like the user to be able to re-upload the file for additional processing.

1

There are 1 best solutions below

0
Fabian On

As far as I know LinqToExcel is for querying only. I use MiniExcel for editing.