在Excel中写入值时,如何避免在Excel中覆盖行值Selenium Automation

我有这个麻烦。 我正在运行这个seleniumtesting并更新电子表格中的值。 我正在进行这些testingpararalley。 因为我的方法尝试更新同一行中的值。 如果使用excel文件,我该如何改变这个等待?

Reporting.Report(folder_Report, DateTime.Now.ToString("yyyy-MM-dd"), startTime, "Fail", error, lastScreenshot, GlobalVariables.orderNo, GlobalVariables.orderAmount, GlobalVariables.warnings); throw;' public static void Report(string folder, string reportName,DateTime startTime, string statues, string error, string screenshot, string orderNo, string orderAmount, string warnings) { DateTime endTime = DateTime.Now; TimeSpan duration = endTime-startTime; string startTime_string = startTime.ToString("yyyy-MM-d--HH-mm-ss"); string endTime_string = endTime.ToString("yyyy-MM-d--HH-mm-ss"); string duration_string = duration.ToString(@"hh\:mm\:ss"); string testCaseName = TestContext.CurrentContext.Test.Name; string testCaseDescription = TestContext.CurrentContext.Test.FullName; string xlfile = folder + "\\" + reportName ; string sheetName = "Sheet1"; //string orderNo = GlobalVariables.orderNo; if (orderNo == "") orderNo = "NC"; if (orderAmount == "") orderAmount = "n/a"; string[] xlReport = new string[] { testCaseName, statues, orderNo, orderAmount, startTime_string, endTime_string, duration_string, screenshot, warnings, error }; ExcelEdit.UpdateXlWorkBook_nextRow(xlReport, folder, reportName, sheetName); } public static void UpdateXlWorkBook_nextRow(string[] MyInfo, string xlFolderPath, string xlWorkbookName, string sheetName) { var xlfile = xlFolderPath + "\\" + xlWorkbookName; if (xlWorkbookName == "") xlfile = xlFolderPath; ExcelWorkBook.Application xlApp = new ExcelWorkBook.Application(); xlApp.Visible = false; ExcelWorkBook.Workbook xlWorkBook = xlApp.Workbooks.Open(xlfile, 0, false, 5, "", "", false, ExcelWorkBook.XlPlatform.xlWindows, "", true, false, 0, true, false, false); ExcelWorkBook.Sheets xlSheets = xlWorkBook.Worksheets; ExcelWorkBook.Worksheet xlWorkSheet = (ExcelWorkBook.Worksheet)xlSheets.get_Item(sheetName); //int col = xlWorkSheet.Columns.CurrentRegion.EntireColumn.Count; int row = xlWorkSheet.Rows.CurrentRegion.EntireRow.Count; try { System.String Search1 = ((ExcelWorkBook.Range)xlWorkSheet.get_Range("E2", Type.Missing)).Value2 as string; int r = row+1; int c = 1; for (int counter = 0; counter < MyInfo.Length; counter++) { xlWorkSheet.Cells[r, c] = MyInfo[counter]; c++; } //Save As xlApp.DisplayAlerts = false; xlWorkSheet.SaveAs(xlfile); xlApp.Quit(); } catch (Exception ex) { xlWorkSheet.Cells[1, 2] = ex; xlApp.DisplayAlerts = false; xlWorkSheet.SaveAs(xlfile); xlApp.Quit(); } }