Usuário com melhor resposta
EPPlus savefiledialog - como usar?

Pergunta
-
Olá.
Estou usando a library EPPlus para gerar arquivos excel. Atualmente o método que uso para salvar é esse, que já gera o arquivo com nome e local pré-definido:
FileInfo excelFile = new FileInfo(@"C:\Users\sistem\Desktop\arquivosexcel\test3.xlsx"); excel.SaveAs(excelFile);
Acontece que desejo usar o componente savefiledialog para salvar os arquivos gerados em locais diferentes, de acordo com o que o usuário definir.
Estou tentando usar o seguinte código para tal:
try { using (ExcelPackage excel = new ExcelPackage()) { excel.Workbook.Worksheets.Add("Worksheet1"); var worksheet = excel.Workbook.Worksheets["Worksheet1"]; worksheet.Cells["E1"].Value = "Valor líquido"; worksheet.Cells["E8"].Value = "fav.: " + txtbanco.Text; worksheet.Cells["E8"].Style.Font.SetFromFont(new Font("Arial", 8)); worksheet.Cells["D10"].Value = "Ag.: " + txtagência.Text; worksheet.Cells["D10"].Style.Font.SetFromFont(new Font("Arial", 8)); worksheet.Cells["E10"].Value = "C: " + txtconta.Text; worksheet.Cells["E10"].Style.Font.SetFromFont(new Font("Arial", 8)); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.InitialDirectory = @"C:\"; saveFileDialog1.Title = "Salvar arquivo em:"; saveFileDialog1.CheckPathExists = true; saveFileDialog1.DefaultExt = "xlsx"; saveFileDialog1.Filter = "Arquivo do Excel *.xlsx | *.xlsx"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; catch (Exception ex) { MessageBox.Show("Ocorreu um erro ao criar o documento. Erro: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); }
Mexendo nas funções do savefiledialog ainda não descobri uma forma de como salvar o arquivo usando ele.
Alguém poderia dar uma ajuda para resolver isso?
Att.
Respostas
-
Vexor33,
Bem interessante... O "EPPlus" estava na CodePlex e migrou para o GitHub:
========================================================
EPPlus-Create advanced Excel spreadsheets on the server
Create advanced Excel 2007/2010 spreadsheets on the server
https://archive.codeplex.com/?p=epplus
========================================================
JanKallman/EPPlus
https://github.com/JanKallman/EPPlusWelcome to the EPPlus wiki!
https://github.com/JanKallman/EPPlus/wiki========================================================
Por favor, veja esses links:
========================================================
How To Create An Excel File (Development) Using EPPlus .NET Library (C#) - Part One
https://www.c-sharpcorner.com/blogs/how-to-create-excel-file-development-using-epplus-net-library-c-sharp
EpplusDemo Part-1.zip========================================================
CREATE EXCEL 2007/2010 SPREADSHEETS WITH C# AND EPPLUS
https://tedgustaf.com/blog/2012/create-excel-20072010-spreadsheets-with-c-and-epplus/========================================================
How to Create Excel Spreadsheet File using EPPlus .NET Library (C#) [English] - PART 1
https://www.youtube.com/watch?v=IExTaxXN2nk========================================================
Generate excel using epplus library
C#3.5
https://www.codeproject.com/Questions/1196640/Generate-excel-using-epplus-library========================================================
EPPlus Library, save as
https://stackoverflow.com/questions/39870552/epplus-library-save-as// Configure save file dialog box var dlg = new Microsoft.Win32.SaveFileDialog { FileName = "NewSheet", // Default file name DefaultExt = ".xlsx", // Default file extension Filter = "Excel Sheet (.xlsx)|*.xlsx" // Filter files by extension } // Show save file dialog box var result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { // Save document string filename = new FileInfo(dlg.FileName); package.SaveAs(newFile); }
Or you can use SaveFileDialog.OpenStream to have the dialog itself create a stream to save to:
if (result == true) { // Save document using(var stream=dlg.OpenStream()) { package.SaveAs(stream); } }
========================================================
Não sei se te ajuda... mas, enfim...
[]'s,
Fabio I.
- Editado Fabio I domingo, 6 de maio de 2018 01:23
- Marcado como Resposta Filipe B CastroModerator quarta-feira, 30 de maio de 2018 20:02
Todas as Respostas
-
Vexor33,
Bem interessante... O "EPPlus" estava na CodePlex e migrou para o GitHub:
========================================================
EPPlus-Create advanced Excel spreadsheets on the server
Create advanced Excel 2007/2010 spreadsheets on the server
https://archive.codeplex.com/?p=epplus
========================================================
JanKallman/EPPlus
https://github.com/JanKallman/EPPlusWelcome to the EPPlus wiki!
https://github.com/JanKallman/EPPlus/wiki========================================================
Por favor, veja esses links:
========================================================
How To Create An Excel File (Development) Using EPPlus .NET Library (C#) - Part One
https://www.c-sharpcorner.com/blogs/how-to-create-excel-file-development-using-epplus-net-library-c-sharp
EpplusDemo Part-1.zip========================================================
CREATE EXCEL 2007/2010 SPREADSHEETS WITH C# AND EPPLUS
https://tedgustaf.com/blog/2012/create-excel-20072010-spreadsheets-with-c-and-epplus/========================================================
How to Create Excel Spreadsheet File using EPPlus .NET Library (C#) [English] - PART 1
https://www.youtube.com/watch?v=IExTaxXN2nk========================================================
Generate excel using epplus library
C#3.5
https://www.codeproject.com/Questions/1196640/Generate-excel-using-epplus-library========================================================
EPPlus Library, save as
https://stackoverflow.com/questions/39870552/epplus-library-save-as// Configure save file dialog box var dlg = new Microsoft.Win32.SaveFileDialog { FileName = "NewSheet", // Default file name DefaultExt = ".xlsx", // Default file extension Filter = "Excel Sheet (.xlsx)|*.xlsx" // Filter files by extension } // Show save file dialog box var result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { // Save document string filename = new FileInfo(dlg.FileName); package.SaveAs(newFile); }
Or you can use SaveFileDialog.OpenStream to have the dialog itself create a stream to save to:
if (result == true) { // Save document using(var stream=dlg.OpenStream()) { package.SaveAs(stream); } }
========================================================
Não sei se te ajuda... mas, enfim...
[]'s,
Fabio I.
- Editado Fabio I domingo, 6 de maio de 2018 01:23
- Marcado como Resposta Filipe B CastroModerator quarta-feira, 30 de maio de 2018 20:02
-
Boa tarde,
Por falta de retorno essa thread está encerrada.
Se necessário, favor abrir uma nova thread.
Atenciosamente,Filipe B de Castro
Esse conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita
MSDN Community Support
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.