public async Task <IActionResult> DownloadProductionDataAsync(ProductionSheetData productiondata) { if (productiondata == null) { throw new ArgumentNullException(nameof(productiondata)); } else { string fileName = Path.GetTempFileName(); var data = productionDataSheetWriter.GenerateExcelSheet(productiondata); SpreadsheetWriter.Write(fileName, data); var memory = new MemoryStream(); using (var fileStream = new FileStream(fileName, FileMode.Open)) { await fileStream.CopyToAsync(memory); } memory.Position = 0; Response.Headers.Add("Content-Disposition", "attachment; filename=ExcelFile.xlsx"); return(File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")); } }
private void SetColumnHeaders(WorksheetDfn worksheet, ProductionSheetData productionSheetData) { List <CellDfn> columnHeaders = new List <CellDfn>(); foreach (var header in productionSheetData.ColumnHeaders) { CellDfn cell = new CellDfn(); cell.Value = header; cell.Bold = true; columnHeaders.Add(cell); } worksheet.ColumnHeadings = columnHeaders; }
public WorkbookDfn GenerateExcelSheet(ProductionSheetData productionSheetData) { WorkbookDfn wb = new WorkbookDfn(); WorksheetDfn ws = new WorksheetDfn(); SetWorksheetNames(ws); SetColumnHeaders(ws, productionSheetData); SetRowData(ws, productionSheetData); List <WorksheetDfn> worksheetDfns = new List <WorksheetDfn> { ws }; wb.Worksheets = worksheetDfns; return(wb); }
private void SetRowData(WorksheetDfn worksheet, ProductionSheetData productionSheetData) { List <RowDfn> rows = new List <RowDfn>(); foreach (var dataRow in productionSheetData.DataRows) { RowDfn row = new RowDfn(); List <CellDfn> cells = new List <CellDfn>(); foreach (var cellData in dataRow) { CellDfn cell = new CellDfn(); cell.Value = cellData; cells.Add(cell); } row.Cells = cells; rows.Add(row); } worksheet.Rows = rows; }