C# 백그라운드에서 EXCEL에 드롭다운 목록 추가(유효성)

1938 단어
string path = “Teme\D\Di.xlsx”; XSSFWorkbook xssfworkbook; try { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite)) { xssfworkbook = new XSSFWorkbook(fs); fs.Close(); } } catch(Exceptionee) {WriteMessageToCardClient(MsgState.Err, "다운로드에 실패했습니다. 템플릿 파일을 찾을 수 없습니다!");return; } XSSFSheet sheet1 = xssfworkbook.GetSheet(“Sheet1”) as XSSFSheet; XSSFSheet bizSheet = xssfworkbook.CreateSheet(“bizSheet”) as XSSFSheet; XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet1); for (int i = 0;i <10000;i++)/Biz 테이블에 충분한 행 {bizSheet.CreateRow(i);}//##을 excel에 저장합니다.RefersToFormula = string.Format("{0}!$B 1 : 1: 1:B${1}", “bizSheet”, Name.Keys.Count); range.NameName = “ColB”; dvConstraint = (XSSFDataValidationConstraint)dvHelper.CreateFormulaListConstraint(range.NameName); CellRangeAddressList addressList2 = null; XSSFDataValidation validation2 = null; addressList2 = new CellRangeAddressList(1, 65535, 1, 1); validation2 = (XSSFDataValidation)dvHelper.CreateValidation(dvConstraint, addressList2); validation2.CreateErrorBox("데이터 부적합", "드롭다운 목록에서 값 선택").validation2.ShowErrorBox = true; sheet1.AddValidationData(validation2);
        if (xssfworkbook != null)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.Charset = "utf-8";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(" .xlsx"));
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            xssfworkbook.Write(HttpContext.Current.Response.OutputStream);
            HttpContext.Current.Response.End();
        }

좋은 웹페이지 즐겨찾기