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

设置Excel模板某列为DropDownList形式,用户不用输入,采取选择的方式避免输入的信息不符合要求

时间:2015-01-13 11:52:55      阅读:324      评论:0      收藏:0      [点我收藏+]

标签:

   using (FileStream file = new FileStream(Path.Combine(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath), filepath + filename + ".xls"), FileMode.Open, FileAccess.Read))
            {
                HSSFWorkbook workbook = new HSSFWorkbook(file);

                HSSFSheet sheet0 = workbook.GetSheetAt(0);
                HSSFSheet sheet1 = workbook.GetSheetAt(1);
                HSSFSheet sheet2 = workbook.GetSheetAt(2);


                WriteMaterialInfoTable(workbook, sheet0, materialInfoDt, 0, 0, true, false, true);
                if (materialTypeDt != null && materialTypeDt.Rows.Count > 0)
                    WriteMaterialInfoTable(workbook, sheet1, materialTypeDt, 0, 0, false, false, true);
                if (spendingDt != null && spendingDt.Rows.Count > 0)
                    WriteMaterialInfoTable(workbook, sheet2, spendingDt, 0, 0, false, false, true);            

                var minUnitIndex = materialInfoDt.Columns.IndexOf("Min Unit(List)");
                if (minUnitIndex > 0)
                {
                    var regions3 = new CellRangeAddressList(1, 65535, minUnitIndex, minUnitIndex);
                    var constraint3 = DVConstraint.CreateExplicitListConstraint(minUnitStrings);
                    var dataValidate3 = new HSSFDataValidation(regions3, constraint3);
                    sheet0.AddValidationData(dataValidate3);
                }
                return Render(workbook);
            }

设置Excel模板某列为DropDownList形式,用户不用输入,采取选择的方式避免输入的信息不符合要求

标签:

原文地址:http://www.cnblogs.com/citygs/p/4220647.html

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