码迷,mamicode.com
首页 > 其他好文 > 详细

NPOI 2.3

时间:2018-08-25 14:20:23      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:value   load   werror   内存流   osi   tee   个数   约束   mem   

 

 

  /// <summary>
        /// 下载导入数据地图模板
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public FileResult DownloadMapTemplate()
        {
            NpoiMemoryStream memory = new NpoiMemoryStream();
            IWorkbook workbook = new XSSFWorkbook();
            ISheet sheet=workbook.CreateSheet("导入地图数据模板");
            IRow row = sheet.CreateRow(0);
            row.CreateCell(0).SetCellValue("项目名称");
            row.CreateCell(1).SetCellValue("地图名称");
            row.CreateCell(2).SetCellValue("地图类型");
            row.CreateCell(3).SetCellValue("经纬度");
            ISheet sheet1 = workbook.GetSheetAt(0);//获得第一个工作表  
            CellRangeAddressList regions = new CellRangeAddressList(1, 65535, 2, 2);//约束范围:c2到c65535  
            XSSFDataValidationHelper helper = new XSSFDataValidationHelper((XSSFSheet)sheet1);//获得一个数据验证Helper  
            IDataValidation validation = helper.CreateValidation(helper.CreateExplicitListConstraint(new string[]{"项目","标段","桥梁","隧道"}), regions);//创建约束
            validation.CreateErrorBox("错误", "请按右侧下拉箭头选择!");//不符合约束时的提示  
            validation.ShowErrorBox = true;//显示上面提示 = True  
            sheet1.AddValidationData(validation);//添加进去  
            sheet1.ForceFormulaRecalculation = true;  
 
 
            memory.AllowClose = false;
            workbook.Write(memory);
            memory.Flush();
            memory.Position = 0;    // 指定内存流起始值
            
            return File(memory, "application/vnd.ms-excel","地图模板下载.xlsx");
        }

 

NPOI 2.3

标签:value   load   werror   内存流   osi   tee   个数   约束   mem   

原文地址:https://www.cnblogs.com/cnki/p/9533229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!