private void SalvaToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count == 0) { MessageBox.Show("Nessuna riga da salvare"); return; } data = (DataTable)dataGridView1.DataSource; SaveFileDialog1.Title = "Salva File"; SaveFileDialog1.Filter = "File Excel (*.xls)|*.xls|Tutti i file (*.*)|*.*"; if (SaveFileDialog1.ShowDialog() == DialogResult.OK) { string sFileName = SaveFileDialog1.FileName; if (sFileName.Trim() != "") { try { ExcelTool writer = new ExcelTool(sFileName); writer.SetDriver("NPOI"); writer.FromDataTable(data); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private DataTable LoadFile(string filename) { try { ExcelTool xls = new ExcelTool(filename); xls.SetDriver("NPOI"); return(xls.ToDataTable()); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(null); }