I am writing a routine to create and fill an Excel sheet in ASP.NET MVC. The object that I want to transfer to the sheet is a List, where T is a structure.
Do you know of any piece of code that does this?
The constructor that do this is:
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
…
public byte[] ExcelContent;
public ExportExcel(List<OrdViewModel> ol)
{
MemoryStream memstream = new MemoryStream();
SpreadsheetDocument XlsxDoc = SpreadsheetDocument.Create(memstream, SpreadsheetDocumentType.Workbook);
WorkbookPart workbookpart = XlsxDoc.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
// Add a WorksheetPart to the WorkbookPart.
WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
// Add Sheets to the Workbook.
Sheets sheets = XlsxDoc.WorkbookPart.Workbook.
AppendChild<Sheets>(new Sheets());
Sheet sheet = new Sheet()
{
Id = XlsxDoc.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Sheet1"
};
sheets.Append(sheet);
// code here…
XlsxDoc.Close();
ExcelContent = memstream.ToArray();
}
// code here…is where I want to insert the code to fill the excel document. In this moment, I have no code where is the above tag...