public void btnExportExcel_Click(object sender, EventArgs e) { string localFilePath = ""; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel Files(07版本 *.xlsx)|*.xlsx|(03版本 *.xls)|*.xls|所有文件(*.*)|*.*"; sfd.FilterIndex = 1; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { localFilePath = sfd.FileName.ToString(); //获得文件路径 } if (localFilePath == "") { MessageBox.Show("未选择Excel文件"); return; } NopiExcel.TableToExcel(dgv, localFilePath); }
public void ExpToExcel() { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { string localFilePath = ""; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel Files(07版本 *.xlsx)|*.xlsx|(03版本 *.xls)|*.xls|所有文件(*.*)|*.*"; sfd.FilterIndex = 1; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { localFilePath = sfd.FileName.ToString(); //获得文件路径 } if (localFilePath == "") { MessageBox.Show("未选择Excel文件"); return; } NopiExcel.TableToExcel(dgv, localFilePath); } }
public void btnImportExcel_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|*.xlsx|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; string fName = null; if (openFileDialog.ShowDialog() == DialogResult.OK) { fName = openFileDialog.FileName; } if (fName == "") { MessageBox.Show("未选择Excel文件"); return; } NopiExcel.ExcelToTable(fName, dgv); DataGridViewToServer(dgv); }