private void SaleDay(string date) { ok = false; SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.Title = "Exportar para Excel"; fileDialog.FileName = "Vendas Diárias - " + date; fileDialog.DefaultExt = "*.xlsx"; fileDialog.Filter = "*.xlsx | *.xlsx"; fileDialog.FileOk += FileDialog_FileOk; fileDialog.ShowDialog(); if (ok == false) { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.Close())); return; } string fileName = fileDialog.FileName; try { File.Copy("Excel\\vendasDiarias.xlsx", fileName, true); value += 1; } catch (IOException ex) { MessageBox.Show(ex.Message); } try { app = new m_Excel.Application(); workbook = app.Workbooks.Open(fileName); worksheet = workbook.Worksheets[1]; List <Relatorio.VendaDia> all = Relatorio.SaleDay(date); value += 1; for (int i = 0; i < all.Count; i++) { worksheet.Cells[i + 3, 1] = all[i].TYPE; worksheet.Cells[i + 3, 2] = all[i].Date; worksheet.Cells[i + 3, 3] = all[i].TotalBrute; worksheet.Cells[i + 3, 4] = all[i].Discount; worksheet.Cells[i + 3, 5] = all[i].Total; worksheet.Cells[i + 3, 6] = all[i].Payment; } value += 1; worksheet = workbook.Worksheets[2]; List <Relatorio.VendaDia> delivery = Relatorio.SaleDayDelivery(date); value += 1; for (int i = 0; i < delivery.Count; i++) { worksheet.Cells[i + 3, 1] = delivery[i].TYPE; worksheet.Cells[i + 3, 2] = delivery[i].Date; worksheet.Cells[i + 3, 3] = delivery[i].TotalBrute; worksheet.Cells[i + 3, 4] = delivery[i].Discount; worksheet.Cells[i + 3, 5] = delivery[i].Total; worksheet.Cells[i + 3, 6] = delivery[i].Payment; } value += 1; worksheet = workbook.Worksheets[3]; List <Relatorio.VendaDia> local = Relatorio.SaleDayLocal(date); value += 1; for (int i = 0; i < local.Count; i++) { worksheet.Cells[i + 3, 1] = local[i].TYPE; worksheet.Cells[i + 3, 2] = local[i].Date; worksheet.Cells[i + 3, 3] = local[i].TotalBrute; worksheet.Cells[i + 3, 4] = local[i].Discount; worksheet.Cells[i + 3, 5] = local[i].Total; worksheet.Cells[i + 3, 6] = local[i].Payment; } value += 1; workbook.Save(); workbook.Close(true, misValue, misValue); value += 1; Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.Close())); Process.Start(fileName); } catch (Exception ex) { throw ex; } finally { app.Quit(); } }