/// <summary> /// DataTable导出到Excel /// </ summary> /// <param name = "dt"> DataTable </ param> /// <param name = "array">首行数组</ param> /// <param name = "fileFullName">文件名</ param> public static void ExportToExcel (dt DataTable, string [] array, fileFullName string) { #region XSSFWorkbook libro = new XSSFWorkbook (); Fs FileStream = new FileStream (fileFullName, FileMode.OpenOrCreate, FileAccess.ReadWrite); Hoja ISheet = workbook.CreateSheet ( "Sheet0"); Fila IRow; fila = sheet.CreateRow (0); { Row.CreateCell (i) .SetCellValue (array [i]); } For (int i = 0; i <dt.Rows.Count; i ++) { fila = sheet.CreateRow (i + 1); for (int j = 0; j <dt.Columns.Count; j ++) { row.CreateCell (j) .SetCellValue (dt.Rows [i] [j] .ToString ()); } } Workbook.Write (FS); //写入到Excel #endregion // MessageBox.Show ( "导出成功!"); }