private void button3_Click(object sender, EventArgs e) { ExportToExcel excel = new ExportToExcel(); DataTable dt = (DataTable)luoi.DataSource; excel.Export(dt, "Độc giả", "Thống kê độc giả"); }
private void button3_Click(object sender, EventArgs e) { if (listView1.Items.Count != 0) { ExportToExcel exp = new ExportToExcel(); exp.ExportToExecl(this.listView1); } else { MessageBox.Show("没有可导出的数据!"); } }
private void button1_Click(object sender, EventArgs e) { ExportToExcel d = new ExportToExcel(); d.OutputAsExcelFile(dataGridView1); }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtWorkSheetName.Text)) { MessageBox.Show("Please enter a valid worksheet name"); return; } // file to export too var excelFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Excel1111.xlsx"); // create a dynamic connection for our Excel file to get sheet names var cons = new Connections(); // this class gets sheet names from excelFile var utls = new Utility(); // determine if sheet exists if (!(utls.SheetNames(cons.NoHeaderConnectionString(excelFile)).Where((sheet) => sheet.DisplayName.ToLower() == txtWorkSheetName.Text.ToLower()).Any())) { // prepare for export // current Header property is ignored // compiler suggestion, this hides the form level ops var, no biggie ExportToExcel ops = new ExportToExcel { DatabaseName = msAccessFileName, Headers = false, ExcelFileName = excelFile, TableName = ListBox1.Text, WorkSheetName = txtWorkSheetName.Text }; bool Success = false; // // Export either all fields or selected fields from CheckListBox. // I wrote comments in the Try/Catch for the Execute method about some fields may cause an exception // Note I do not attempt to arrange the order of the columns // if (CheckedListBox1.CheckedItems.Count > 0) { Success = ops.Execute(CheckedListBox1.SelectColumns()); } else { Success = ops.Execute(); } // indicate how many records were exported or show and exception message if (Success) { MessageBox.Show($"Exported {ops.RecordsInserted}"); } else { MessageBox.Show($"Failed: {ops.ExceptionMessage}"); } } else { MessageBox.Show($"{txtWorkSheetName.Text} already exist, aborted."); } }