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

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

   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形式,用户不用输入,采取选择的方式避免输入的信息不符合要求