private void btnUpdateExcel_Click(object sender, EventArgs e) { // the saving dialog var saveFileDialog = new SaveFileDialog(); // the types of files that can be saved saveFileDialog.Filter = "XLS files (*.xls)|*.xls|XLT files (*.xlt)|*.xlt|XLSX files (*.xlsx)|*.xlsx|XLSM files (*.xlsm)|*.xlsm|XLTX (*.xltx)|*.xltx|XLTM (*.xltm)|*.xltm|ODS (*.ods)|*.ods|OTS (*.ots)|*.ots|CSV (*.csv)|*.csv|TSV (*.tsv)|*.tsv|HTML (*.html)|*.html|MHTML (.mhtml)|*.mhtml|PDF (*.pdf)|*.pdf|XPS (*.xps)|*.xps|BMP (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPEG (*.jpg)|*.jpg|PNG (*.png)|*.png|TIFF (*.tif)|*.tif|WMP (*.wdp)|*.wdp"; saveFileDialog.FilterIndex = 3; if (saveFileDialog.ShowDialog() == DialogResult.OK) { // create a new excel file var workbook = new ExcelFile(); // add a new excel sheet var worksheet = workbook.Worksheets.Add("Sheet1"); // From metrogrid1 to ExcelFile. DataGridViewConverter.ImportFromDataGridView(worksheet, this.metroGrid1, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); // saves the file workbook.Save(saveFileDialog.FileName); } }
private void ExportToFile(DataGridView dg, string worksheetName) { SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY"); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XLS files (*.xls)|*.xls|XLT files (*.xlt)|*.xlt|XLSX files (*.xlsx)|*.xlsx|XLSM files (*.xlsm)|*.xlsm|XLTX (*.xltx)|*.xltx|XLTM (*.xltm)|*.xltm|ODS (*.ods)|*.ods|OTS (*.ots)|*.ots|CSV (*.csv)|*.csv|TSV (*.tsv)|*.tsv|HTML (*.html)|*.html|MHTML (.mhtml)|*.mhtml|PDF (*.pdf)|*.pdf|XPS (*.xps)|*.xps|BMP (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPEG (*.jpg)|*.jpg|PNG (*.png)|*.png|TIFF (*.tif)|*.tif|WMP (*.wdp)|*.wdp"; saveFileDialog.FilterIndex = 3; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ExcelFile ef = new ExcelFile(); ExcelWorksheet ws = ef.Worksheets.Add(worksheetName); DataGridViewConverter.ImportFromDataGridView( ef.Worksheets[0], dg, new ImportFromDataGridViewOptions() { ColumnHeaders = true } ); ws.PrintOptions.FitWorksheetWidthToPages = 1; ef.Save(saveFileDialog.FileName); } }
public static void exportToExcel(DataGridView dgv, string name, bool footer) { SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY"); // Load Excel (XLSX) from a file. ExcelFile workbook = new ExcelFile(); ExcelWorksheet worksheet = workbook.Worksheets.Add($"{name}"); worksheet.Cells["A1"].Value = ""; workbook.Save($"{name}.xlsx"); var workbook1 = ExcelFile.Load($"{name}.xlsx"); // Import DataGridView back to active worksheet. DataGridViewConverter.ImportFromDataGridView( workbook1.Worksheets.ActiveWorksheet, dgv, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); // Save Excel (XLSX) to a file. workbook1.Save($"{name}.xls"); File.Delete($"{name}.xlsx"); if (footer == true) { SheetHeaderFooter hfooter = workbook1.Worksheets.ActiveWorksheet.HeadersFooters; hfooter.DefaultPage.Footer.CenterSection.Content = $"Number of Non-Active Members: {numberNonActive},\nNumber of Active Members: {numberActive},\nNumber of Members Owing: {numberOwing},\nTotal Amount Owed: {amountOwedTotal}"; workbook1.Save($"{name}.xls"); } }
private void m_B_Export_Click(object sender, EventArgs e) { if (System.IO.File.Exists(this.m_TaskCsvName)) { if (MessageBox.Show("文件已经存在,是否覆盖?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel) { return; } } ExcelFile ef = new ExcelFile(); ExcelWorksheet ws = ef.Worksheets.Add("Mrg"); try { DataGridViewConverter.ImportFromDataGridView(ws, this.m_dgv_ItemDetail, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); ef.Save(this.m_TaskCsvName, CsvSaveOptions.CsvDefault); Process.Start("Excel.exe", this.m_TaskCsvName); } catch (System.Exception ex) { MessageBox.Show("文件保存失败 : " + ex.Message, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } }
public void SaveDataToExcel(DataGridView dataGridView1, string file) { SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY"); var workbook = new ExcelFile(); var worksheet = workbook.Worksheets.Add("Sheet1"); // From DataGridView to ExcelFile. DataGridViewConverter.ImportFromDataGridView(worksheet, dataGridView1, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); workbook.Save(file); }
private void SaveExcelFromDataGridView(string excelFile) { ExcelFile ef = new ExcelFile(); ExcelWorksheet ws = ef.Worksheets.Add("DGW Sheet"); // From DataGridView to ExcelFile. DataGridViewConverter.ImportFromDataGridView( ws, this.dataGridView1, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); ef.Save(excelFile); }
private void saveButton_Click(object sender, EventArgs e) { DataGridViewConverter.ImportFromDataGridView( File.Tables.Worksheets[tabControl1.SelectedIndex], this.tableGridView1, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); try { FileManager.SaveFile(File); } catch (Exception) { } }
private void save_service_Click(object sender, EventArgs e) { var saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XLS files (*.xls)|*.xls|XLSX files (*.xlsx)|*.xlsx|CSV (*.csv)|*.csv|All files (*.*)|*.*"; saveFileDialog.FilterIndex = 3; if (saveFileDialog.ShowDialog() == DialogResult.OK) { var workbook = new ExcelFile(); var worksheet = workbook.Worksheets.Add("Services"); // From DataGridView to ExcelFile. DataGridViewConverter.ImportFromDataGridView(worksheet, this.dgvService, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); workbook.Save(saveFileDialog.FileName); } }
private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XLS files (*.xls)|*.xls|XLT files (*.xlt)|*.xlt|XLSX files (*.xlsx)|*.xlsx|XLSM files (*.xlsm)|*.xlsm|XLTX (*.xltx)|*.xltx|XLTM (*.xltm)|*.xltm|ODS (*.ods)|*.ods|OTS (*.ots)|*.ots|CSV (*.csv)|*.csv|TSV (*.tsv)|*.tsv|HTML (*.html)|*.html|MHTML (.mhtml)|*.mhtml|PDF (*.pdf)|*.pdf|XPS (*.xps)|*.xps|BMP (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPEG (*.jpg)|*.jpg|PNG (*.png)|*.png|TIFF (*.tif)|*.tif|WMP (*.wdp)|*.wdp"; saveFileDialog.FilterIndex = 3; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ExcelFile ef = new ExcelFile(); ExcelWorksheet ws = ef.Worksheets.Add("Sheet1"); // From DataGridView to ExcelFile. DataGridViewConverter.ImportFromDataGridView(ws, this.dataGridView1, new ImportFromDataGridViewOptions() { ColumnHeaders = true }); ef.Save(saveFileDialog.FileName); } }
private void btn_excel_Click(object sender, EventArgs e) { // If using Professional version, put your serial key below. SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY"); string path = AppDomain.CurrentDomain.BaseDirectory + @"\lib\Ficheros\deslinde.xls"; ExcelFile workbook = ExcelFile.Load(path); //var workbook = new ExcelFile(); var worksheet = workbook.Worksheets.ActiveWorksheet; DataGridViewConverter.ImportFromDataGridView(worksheet, dataGridView1, new ImportFromDataGridViewOptions() { ColumnHeaders = false, StartRow = 7, StartColumn = 1 }); //workbook.Save("deslinde.xls"); workbook.Save(path); MessageBox.Show("Done"); Process.Start(path); }