c# 导出Excel模板(在项目中有现成的Excel模板)
在项目中会有导出模板功能,把现成的Excel模板导出去填写之后再进行导入,这里说说怎么导出模板:
模板存放位置:
点击导出模板按钮:
private string currentPath = Path.GetFullPath(@"..\..\");
/// <summary> /// 导出模板 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void materialButton4_Click(object sender, EventArgs e) { string path = Path.Combine(currentPath, "Excel", "template", "XXX模板.xlsx"); try { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "excel97-2003文件(*.xls,*xlsx)|*.xls;*xlsx"; sfd.FileName = string.Format("XXX模板{0}", DateTime.Now.ToString("yyyyMMddhhmmss")); if (sfd.ShowDialog() == DialogResult.OK) { Console.WriteLine(sfd.FileName); File.Copy(path, sfd.FileName); MessageBox.Show("导出成功!"); } } catch (Exception ex) { MessageBox.Show(ex.Message+",出现异常exporttemplate"); } }