}//end writeTechTixToList() private void writeBillingListToXlsx() { //String saveAs; int percent; int count = threadVars.BillingRecords.Count + 1; Excel.Application xlApp; Excel.Workbook xlWorkbook; Excel.Worksheet xlWorksheet; Excel.Range rng; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); activeXl.Add(xlApp); xlWorkbook = xlApp.Workbooks.Add(misValue); activeXl.Add(xlWorkbook); xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); activeXl.Add(xlWorksheet); xlWorksheet.Cells[1, 1] = "Ticket No"; xlWorksheet.Cells[1, 2] = "Summary"; xlWorksheet.Cells[1, 3] = "Resolution"; xlWorksheet.Cells[1, 4] = "Created"; xlWorksheet.Cells[1, 5] = "Closed"; xlWorksheet.Cells[1, 6] = "Hours"; xlWorksheet.Cells[1, 7] = "Labor"; xlWorksheet.Cells[1, 8] = "Purchases"; xlWorksheet.Cells[1, 9] = "Expenses"; xlWorksheet.Cells[1, 10] = "Total"; rng = (Excel.Range)xlWorksheet.get_Range(xlWorksheet.Cells[1, 1], xlWorksheet.Cells[1, 10]); rng.Interior.Color = ColorTranslator.ToOle(Color.GreenYellow); try { progressBar progressForm = new progressBar(); progressForm.Show(); int row = 1; foreach (BillingRecord record in threadVars.BillingRecords) { row++; xlWorksheet.Cells[row, 1] = record.TicketNo; xlWorksheet.Cells[row, 2] = record.Summary; xlWorksheet.Cells[row, 3] = record.Resolution; xlWorksheet.Cells[row, 4] = record.CreatedAt; xlWorksheet.Cells[row, 5] = record.ClosedAt; xlWorksheet.Cells[row, 6] = record.TotalHours; xlWorksheet.Cells[row, 7] = record.TotalLabor; xlWorksheet.Cells[row, 8] = record.Purchases; xlWorksheet.Cells[row, 9] = record.Expenses; xlWorksheet.Cells[row, 10] = record.GrandTotal; rng = (Excel.Range)xlWorksheet.get_Range(xlWorksheet.Cells[row, 1], xlWorksheet.Cells[row, 10]); if (row % 2 == 0) { rng.Interior.Color = ColorTranslator.ToOle(Color.LightGray); } else { rng.Interior.Color = ColorTranslator.ToOle(Color.White); } xlWorksheet.Rows.RowHeight = 16.5; //progress = (double)(row/count); //percent = (double)findPercent(row, count); //percent = percent * 100; //progPercent = (int)(percent); percent = findPercent(row, count); //showProgress(progressForm, percent); //progressForm.showProgress(); progressForm.WindowName(); progressForm.UpdateProgress(percent, row, count); } //t2 = new Thread(writeBillToXlEven); //t2.SetApartmentState(ApartmentState.STA); //t2.IsBackground = true; //t2.Start(); //t3 = new Thread(writeBillToXlOdd); //t3.SetApartmentState(ApartmentState.STA); //t3.IsBackground = true; //t3.Start(); //t2.Join(); //t3.Join(); //SaveFileDialog attempt = new SaveFileDialog(); //attempt.Filter = "Excel Files | *.xlsx"; //attempt.DefaultExt = "xlsx"; //attempt.ShowDialog(); //saveAs = attempt.FileName; ////xlWorkbook.SaveAs(saveAs, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); //xlWorkbook.SaveAs(saveAs); saveXL(xlWorkbook); //MessageBox.Show("Your report was succesfully created!"); } catch (Exception ex) { Console.WriteLine(ex.Message); //MessageBox.Show("There was an issue writing your report to Excel."); } finally { if (!cancelClick) { xlWorkbook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorksheet); releaseObject(xlWorkbook); releaseObject(xlApp); } } }//end writeListToXlsx(billing)
}//end writeListToXlsx(Ticketing) private void writeTechTixListToXlsx() { //String saveAs; int percent; int count = threadVars.TechTixRecords.Count + 1; Excel.Application xlApp; Excel.Workbook xlWorkbook; Excel.Worksheet xlWorksheet; Excel.Range rng; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); activeXl.Add(xlApp); xlWorkbook = xlApp.Workbooks.Add(misValue); activeXl.Add(xlWorkbook); xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); activeXl.Add(xlWorksheet); xlWorksheet.Cells[1, 1] = "Ticket No"; xlWorksheet.Cells[1, 2] = "Summary"; xlWorksheet.Cells[1, 3] = "Tech"; xlWorksheet.Cells[1, 4] = "Account"; xlWorksheet.Cells[1, 5] = "Type"; xlWorksheet.Cells[1, 6] = "Status"; xlWorksheet.Cells[1, 7] = "Notes"; rng = (Excel.Range)xlWorksheet.get_Range(xlWorksheet.Cells[1, 1], xlWorksheet.Cells[1, 7]); rng.Interior.Color = ColorTranslator.ToOle(Color.GreenYellow); try { progressBar pf = new progressBar(); pf.Show(); int row = 1; foreach (TechTixRecord record in threadVars.TechTixRecords) { row++; xlWorksheet.Cells[row, 1] = record.TicketNo; xlWorksheet.Cells[row, 2] = record.Summary; xlWorksheet.Cells[row, 3] = record.Tech; xlWorksheet.Cells[row, 4] = record.Account; xlWorksheet.Cells[row, 5] = record.Type; xlWorksheet.Cells[row, 6] = record.Status; xlWorksheet.Cells[row, 7] = record.Notes; rng = (Excel.Range)xlWorksheet.get_Range(xlWorksheet.Cells[row, 1], xlWorksheet.Cells[row, 7]); if (row % 2 == 0) { rng.Interior.Color = ColorTranslator.ToOle(Color.LightGray); } else { rng.Interior.Color = ColorTranslator.ToOle(Color.White); } xlWorksheet.Rows.RowHeight = 16.5; percent = findPercent(row, count); pf.WindowName(); pf.UpdateProgress(percent, row, count); } //SaveFileDialog attempt = new SaveFileDialog(); //attempt.Filter = "Excel Files | *.xlsx"; //attempt.DefaultExt = "xlsx"; //attempt.ShowDialog(); //saveAs = attempt.FileName; //xlWorkbook.SaveAs(saveAs, Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); //MessageBox.Show("Your report was succesfully created!"); saveXL(xlWorkbook); } catch (Exception ex) { Console.WriteLine(ex.Message); MessageBox.Show("There was an issue writing your report to Excel."); } finally { if (!cancelClick) { xlWorkbook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorksheet); releaseObject(xlWorkbook); releaseObject(xlApp); } } }//end writeListToXlsx(TechTix)
}//end findPercent() private void showProgress(progressBar pf, int percent) { pf.WindowName(); pf.ProgPercent = percent; }//end showProgress()