private void executeToExcel(Record record) { string path = Application.StartupPath + ConfigurationManager.AppSettings["excelPath"].ToString(); File.Copy(path, Application.StartupPath + @"\test.xlsx", true); ExcelEdit excelOperator = new ExcelEdit(); excelOperator.Open(Application.StartupPath + @"\test.xlsx"); Microsoft.Office.Interop.Excel.Worksheet sheet1 = excelOperator.GetSheet("Sheet1"); sheet1.Cells[4, 5].Value = record.Operator; sheet1.Cells[4, 8].Value = record.CreateTime.ToString("yyyy-MM-dd"); sheet1.Cells[6, 2].Value = record.SeriesNum; sheet1.Cells[6, 5].Value = record.ProName; sheet1.Cells[6, 8].Value = record.Result == 1 ? "合格" : "不合格"; for (int i = 0; i < record.RecordDetailList.Count; i++) { sheet1.Cells[i + 11, 2].Value = record.RecordDetailList[i].Index; sheet1.Cells[i + 11, 3].Value = record.RecordDetailList[i].TestValue + " N·m"; sheet1.Cells[i + 11, 4].Value = record.RecordDetailList[i].Standard + " N·m"; sheet1.Cells[i + 11, 5].Value = record.RecordDetailList[i].Difference; sheet1.Cells[i + 11, 6].Value = record.RecordDetailList[i].Percent + "%"; sheet1.Cells[i + 11, 7].Value = record.Result == 1 ? "合格" : "不合格"; sheet1.Cells[i + 11, 8].Value = record.RecordDetailList[i].Upper + " N·m"; sheet1.Cells[i + 11, 9].Value = record.RecordDetailList[i].Lower + " N·m"; } if (ConfigurationManager.AppSettings["printMode"].ToString().Equals("preview")) { sheet1.PrintPreview(); } else if (ConfigurationManager.AppSettings["printMode"].ToString().Equals("print")) { sheet1.PrintOutEx(); } excelOperator.Save(); excelOperator.Close(); GC.Collect(); }