Home > Net >  Export data to excel in c #
Export data to excel in c #

Time:11-26

Using NPOI components, how to query to show in export data generation to excel in DataGridView (XLS file format, because will use in excel2003 version), the export can choose target folder

CodePudding user response:

 
Public static void Write (Dictionary Data, int wsno=1)
{
System. Windows. Forms. SaveFileDialog saveDia=new System. Windows, Forms, SaveFileDialog ();
SaveDia. Filter="Excel | *. XLS";
SaveDia. Title="export to Excel file";
SaveDia. FileName=System. A DateTime. Now. ToString (" yyyyMMddHHmmss ");

If (saveDia ShowDialog ()==System. Windows. Forms. The DialogResult. OK
& & ! String. The Empty. Equals (saveDia FileName))
{
Using (ExcelPackage ep=new ExcelPackage (new to the FileInfo (saveDia. FileName)))
{
//ExcelWorksheet ws=ep. Workbook. Worksheets. The Add (" 1 ");

ExcelWorksheet ws=ep. Workbook. Worksheets [wsno];
Foreach (String p in the data. Keys)
{
Ws. Cells [p]. Value=https://bbs.csdn.net/topics/data [p].
}
Ep. The Save ();
}
}
}

CodePudding user response:

Very simple, baidu a handful
  •  Tags:  
  • C#
  • Related