C# NPOI Excel 고정 템플릿 데이터 쓰기

4395 단어 자료 기록excel
데이터 트리거 내보내기:<div>


백그라운드 구현:
//Excel 
 string TempletFileName = context.Server.MapPath("..../UploadFile/test.xls");
            HSSFWorkbook wk = null;
            using (FileStream fs = File.Open(TempletFileName, FileMode.Open,
            FileAccess.Read, FileShare.ReadWrite))
            {
                // xls workbook , 
                wk = new HSSFWorkbook(fs);
                fs.Close();
            }
            HSSFSheet sheet1 = (HSSFSheet)wk.GetSheetAt(0);
            DoctorBLL bll = new DoctorBLL();
            DataTable exportTable = bll.GetExportQuestionTable();
            if (exportTable != null)
            {
                int nRow = 2;
                string nextFirstTxt = string.Empty;
                for (int i = 0; i < exportTable.Rows.Count; i++)
                {
                    IRow row = sheet1.CreateRow(nRow);
                    for (int j = 0; j < exportTable.Columns.Count; j++)
                    {
                    // excel                         row.CreateCell(j).SetCellValue(exportTable.Rows[i][j]);
                    }
                    nRow++;
                }
            }
            context.Response.ContentType = "application/vnd.ms-excel";
            //  ,    
            context.Response.AddHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
            context.Response.AddHeader("Content-Transfer-Encoding", "binary");
            context.Response.ContentType = "application/octet-stream";
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;
            MemoryStream file = new MemoryStream();
            wk.Write(file);
            context.Response.BinaryWrite(file.GetBuffer());

좋은 웹페이지 즐겨찾기