public void ExcelOp(DataGridView gdv,ArrayList selHead)
{
if (selHead.Count==0)
{
MessageBox.Show("沒有數據,無法導出EXCEL!");
return;
}
IWorkbook excel = new HSSFWorkbook();//創建.xls文件
ISheet sheet = excel.CreateSheet("sheet1"); //創建sheet
IRow row = sheet.CreateRow(0);
//創建行對象,填充表頭
row.CreateCell(0).SetCellValue("月份");
row.CreateCell(1).SetCellValue("門\\病");
row.CreateCell(2).SetCellValue("科別");
row.CreateCell(3).SetCellValue("收入類別");
row.CreateCell(4).SetCellValue("姓名");
//寫入文件 彈出文件保存
//string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//桌面路徑
string filename = statistics_head.Text+ printDetailClass.GetUnixTime(DateTime.Now).ToString();//文件名
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "xls";
saveDialog.Filter = "Excel文件|*.xls";
saveDialog.FileName = filename;
saveDialog.ShowDialog();
filename = saveDialog.FileName;
if (filename.IndexOf(":") < 0) return; //被點了取消
FileStream xlsfile = new FileStream(saveDialog.FileName, FileMode.Create);
excel.Write(xlsfile);
xlsfile.Close();
System.Diagnostics.Process.Start(filename);
}