zoukankan      html  css  js  c++  java
  • winform NPOI excel 导出并选择保存文件路径

            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);
            }
    

      

  • 相关阅读:
    [JSOI2018]潜入行动
    [ZJOI2013]丽洁体
    [CTSC2017]吉夫特
    [SDOI2016]储能表
    POJ-3616 Milking Time
    POJ-2385 Apple Catching---DP
    POJ-2229 Sumsets---完全背包变形
    hdu-1114 Piggy-Bank---完全背包
    POJ-3050 Hopscotch---DFS
    POJ-3187 Backward Digit Sums---枚举全排列
  • 原文地址:https://www.cnblogs.com/aj407blogs/p/9780423.html
Copyright © 2011-2022 走看看