public void MainSync() { var excel = new Excel.Application { Visible = true, EnableAnimations = false }; var wkb = ExcelFeatures.Open(excel, this.FilePath); List <Information> calculation = CalculateAllWorksheetsSync(wkb); Information.PrintInformation(calculation); excel.EnableAnimations = true; wkb.Close(true); excel.Quit(); ExcelFeatures.CloseExcelExe(excel); }
public Information CalculateSingleWorksheetSync(Excel.Worksheet wks) { int resultFromCalculation = 0; int resultTryParse; int lastRow = ExcelFeatures.LastRowPerColumn(1, wks); for (int i = 1; i < lastRow; i++) { if (Int32.TryParse(wks.Cells[i, 1].Text, out resultTryParse)) { resultFromCalculation += resultTryParse; } } Information infoToReturn = new Information(wks.Name, resultFromCalculation, lastRow); Console.WriteLine(infoToReturn.ToString()); return(infoToReturn); }
public async Task <Information> CalculateSingleWorksheetAsync(Excel.Worksheet wks) { int lastRow = ExcelFeatures.LastRowPerColumn(1, wks); int result = await Task.Run(() => { int resultFromCalculation = 0; int resultTryParse; for (int i = 1; i < lastRow; i++) { if (Int32.TryParse(wks.Cells[i, 1].Text, out resultTryParse)) { resultFromCalculation += resultTryParse; } } return(resultFromCalculation); }); Information infoToReturn = new Information(wks.Name, result, lastRow); Console.WriteLine(infoToReturn.ToString()); return(infoToReturn); }