Я довольно новичок в C # /. net и ищу более чистый способ задания имен столбцов и данных для экспорта в Excel.
Код ниже работает, но, как я уже сказал, я ищу лучший способ сделать это (возможно, в al oop или что-то)?
var gw = new RequestGateway();
var results = gw.GetResultsForExcelExport(customerId).ToList();
var columnnames = gw.GetColumnNamesForExcelExport(languageCode).First();
ExcelPackage Ep = new ExcelPackage();
ExcelWorksheet Sheet = Ep.Workbook.Worksheets.Add("Report");
Sheet.Cells["A1"].Value = columnnames.ordno;
Sheet.Cells["B1"].Value = columnnames.barcode;
Sheet.Cells["C1"].Value = columnnames.customerDescription;
Sheet.Cells["D1"].Value = columnnames.customerLabel;
Sheet.Cells["E1"].Value = columnnames.itemCode;
Sheet.Cells["F1"].Value = columnnames.anaCode;
Sheet.Cells["G1"].Value = columnnames.testname;
Sheet.Cells["H1"].Value = columnnames.analyte;
Sheet.Cells["I1"].Value = columnnames.result;
Sheet.Cells["J1"].Value = columnnames.resultUnit;
Sheet.Cells["K1"].Value = columnnames.resultComment;
Sheet.Cells["L1"].Value = columnnames.matrix;
Sheet.Cells["M1"].Value = columnnames.samplingDate;
Sheet.Cells["N1"].Value = columnnames.productionDate;
Sheet.Cells["O1"].Value = columnnames.folderNo;
Sheet.Cells["P1"].Value = columnnames.dateReceived;
Sheet.Cells["Q1"].Value = columnnames.customerReference;
Sheet.Cells["R1"].Value = columnnames.reportDate;
int row = 2;
foreach (var result in results)
{
Sheet.Cells[string.Format("A{0}", row)].Value = result.ordno;
Sheet.Cells[string.Format("B{0}", row)].Value = result.barcode;
Sheet.Cells[string.Format("C{0}", row)].Value = result.customerDescription;
Sheet.Cells[string.Format("D{0}", row)].Value = result.customerLabel;
Sheet.Cells[string.Format("E{0}", row)].Value = result.itemCode;
Sheet.Cells[string.Format("F{0}", row)].Value = result.anaCode;
Sheet.Cells[string.Format("G{0}", row)].Value = result.testname;
Sheet.Cells[string.Format("H{0}", row)].Value = result.analyte;
Sheet.Cells[string.Format("I{0}", row)].Value = result.result;
Sheet.Cells[string.Format("J{0}", row)].Value = result.resultUnit;
Sheet.Cells[string.Format("K{0}", row)].Value = result.resultComment;
Sheet.Cells[string.Format("L{0}", row)].Value = result.matrix;
Sheet.Cells[string.Format("M{0}", row)].Value = result.samplingDate;
Sheet.Cells[string.Format("N{0}", row)].Value = result.productionDate;
Sheet.Cells[string.Format("O{0}", row)].Value = result.folderNo;
Sheet.Cells[string.Format("P{0}", row)].Value = result.dateReceived;
Sheet.Cells[string.Format("Q{0}", row)].Value = result.customerReference;
Sheet.Cells[string.Format("R{0}", row)].Value = result.reportDate;
row++;
}