public static void WriteResult(List <SampleInfo> allVolumeInfos, string sFile) { Application excelApp = new Application(); excelApp.DisplayAlerts = false; Workbook workBook = excelApp.Workbooks.Open(sFile); try { Worksheet xlsWs = null; Range ExcelCellText; xlsWs = (Worksheet)workBook.Worksheets.get_Item(1); string startCell = ConfigurationManager.AppSettings["startCell"]; ExcelCellText = xlsWs.get_Range(startCell, Missing.Value); ExcelCellText = ExcelCellText.get_Resize(allVolumeInfos.Count, 3); string[,] myArray = new string[allVolumeInfos.Count, 3]; for (int r = 0; r < allVolumeInfos.Count; r++) { myArray[r, 0] = allVolumeInfos[r].orgBarcode; myArray[r, 1] = allVolumeInfos[r].curBarcode; myArray[r, 2] = allVolumeInfos[r].volume; } System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); ExcelCellText.set_Value(Missing.Value, myArray); workBook.Save(); } finally { workBook.Close(); excelApp.Quit(); } }
public static void Write() { PlateData plateData = GlobalVars.Instance.PlatesInfo.CurrentPlateData; string sFileName = GlobalVars.Instance.PlatesInfo.CurrentPlateData.FilePath; AcquiredStage curStage = plateData.Stage; Application excel = new Application(); Workbook workBook = excel.Workbooks.Open(sFileName); Worksheet xlsWs = null; Range ExcelCellText; xlsWs = (Worksheet)workBook.Worksheets.get_Item(2); string sCell = curStage == AcquiredStage.BackGround ? "C12" : "C2"; ExcelCellText = xlsWs.get_Range(sCell, Missing.Value); ExcelCellText = ExcelCellText.get_Resize(8, 12); double[,] myArray = new double[8, 12]; int curIndex = 0; for (int r = 0; r < myArray.GetLength(0); r++) { for (int c = 0; c < myArray.GetLength(1); c++) { double val = curStage == AcquiredStage.BackGround ? plateData.Values[curIndex].backGround : plateData.Values[curIndex].sampleVal; myArray[r, c] = val; curIndex++; } } ExcelCellText.set_Value(Missing.Value, myArray); workBook.Save(); try { if (curStage == AcquiredStage.SampleVal) { Process.Start("explorer.exe", sFileName); } } catch (Exception ex) { Debug.WriteLine("未能打印!"); } workBook.Close(); excel.Quit(); }