当前位置: 首页 > news >正文

网站模板购买人民日报最新新闻

网站模板购买,人民日报最新新闻,不同代码做的网站后期维护情况,福建省建设系统网站安装 依赖库:NPOI 创建XSSFWorkbook和Sheet 设置表头行 添加数据验证: 身份证列用COUNTIF公式确保唯一 地址相关列锁定固定值 学段列设置三级下拉 固定值通过单元格赋值实现 输出 using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.SS…

安装 依赖库:NPOI
在这里插入图片描述

创建XSSFWorkbook和Sheet
设置表头行
添加数据验证:
身份证列用COUNTIF公式确保唯一
地址相关列锁定固定值
学段列设置三级下拉
固定值通过单元格赋值实现
输出

using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.SS.Util;
using System.IO;/// <summary>
/// 下载模板
/// </summary>
/// <returns></returns>
public ActionResult DownloadTemplate(DownloadTemplateDto input) {if (input.total< 1) throw new UserFriendlyException("人数不能为0");var stream = GenerateExcel(input.total);var data= stream.ToArray();return new FileContentResult(data, "application/octet-stream");//application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
}private MemoryStream GenerateExcel(int rowTotal)
{rowTotal = rowTotal + 10;//总行数// 1. 创建工作簿和工作表IWorkbook workbook = new XSSFWorkbook();ISheet sheet = workbook.CreateSheet("基础信息");// 创建文本格式样式(用于身份证号列)ICellStyle textStyle = workbook.CreateCellStyle();IDataFormat textFormat = workbook.CreateDataFormat();textStyle.DataFormat = textFormat.GetFormat("@"); // "@" 表示文本格式// 2. 创建列名行// 2. 设置列名(共12列)string[] headers = { "姓名", "身份证号", "现住省", "现住市", "现住区", "联系电话","详细地址", "学校名称", "学校编号", "学段", "年级", "班级" };IRow headerRow = sheet.CreateRow(0);for (int i = 0; i < headers.Length; i++){headerRow.CreateCell(i).SetCellValue(headers[i]);}// 3. 设置数据验证规则IDataValidationHelper validationHelper = sheet.GetDataValidationHelper();// 规则1:身份证号列唯一性验证CellRangeAddressList idRange = new CellRangeAddressList(1, rowTotal, 1, 1); // B列IDataValidationConstraint idConstraint = validationHelper.CreateCustomConstraint("COUNTIF(B:B, B1)=1");IDataValidation idValidation = validationHelper.CreateValidation(idConstraint, idRange);idValidation.CreateErrorBox("重复错误", "身份证号必须唯一!");sheet.AddValidationData(idValidation);// 规则2:固定值验证(省、市、区、学校名称、学校编号)SetFixedValue(sheet, 2, "北京市", rowTotal); // C列:现住省SetFixedValue(sheet, 3, "昌平区", rowTotal); // D列:现住市SetFixedValue(sheet, 4, "A街道", rowTotal); // E列:街道SetFixedValue(sheet, 7, deptName, rowTotal); // H列:学校名称SetFixedValue(sheet, 8, deptId, rowTotal); // I列:学校编号// 规则3:学段下拉选择(小学/初中/高中)CellRangeAddressList stageRange = new CellRangeAddressList(1, rowTotal, 9, 9); // J列IDataValidationConstraint stageConstraint = validationHelper.CreateExplicitListConstraint(new string[] { "小学", "初中", "高中", "高三", "中专", "技校", "大学" });IDataValidation stageValidation = validationHelper.CreateValidation(stageConstraint, stageRange);stageValidation.CreateErrorBox("输入错误", "请选择下拉选中对应值!");sheet.AddValidationData(stageValidation);// 规则4:年级CellRangeAddressList grade = new CellRangeAddressList(1, rowTotal, 10, 10); // K列IDataValidationConstraint gradeConstraint = validationHelper.CreateExplicitListConstraint(new string[] { "一年级", "二年级", "三年级", "四年级", "五年级", "六年级","初一", "初二", "初三", "高一", "高二", "高三", "大一", "大二", "大三", "大四" });IDataValidation gradeValidation = validationHelper.CreateValidation(gradeConstraint, grade);gradeValidation.CreateErrorBox("输入错误", "请选择下拉选中对应值!");sheet.AddValidationData(gradeValidation);for (int rowIndex = 1; rowIndex <= rowTotal; rowIndex++){IRow row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);ICell idCell = row.GetCell(idCardColumnIndex) ?? row.CreateCell(idCardColumnIndex);// 应用文本样式(即使单元格为空)idCell.CellStyle = textStyle;// 如果已有数据,确保以文本格式存储if (idCell.StringCellValue != null){idCell.SetCellValue(idCell.StringCellValue);}
}// 5. 流式输出MemoryStream stream = new MemoryStream();workbook.Write(stream, true);stream.Position = 0; // 重置流位置 return stream;
}// 辅助方法:为整列设置固定值 添加样式参数
private void SetFixedValue(ISheet sheet, int columnIndex, string value, int rowTotal, ICellStyle textStyle)
{for (int rowIndex = 1; rowIndex <= rowTotal; rowIndex++){IRow row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);ICell cell = row.GetCell(columnIndex) ?? row.CreateCell(columnIndex);cell.SetCellValue(value);// 如果是身份证列(索引1),应用文本样式if (columnIndex == 1){cell.CellStyle = textStyle;}}
}

测试
在这里插入图片描述
修改下载后的文件后缀为xlsx格式即可打开
在这里插入图片描述


文章转载自:
http://dinncofishable.bpmz.cn
http://dinncosyntagm.bpmz.cn
http://dinncolineprinter.bpmz.cn
http://dinncodirk.bpmz.cn
http://dinncotwisteroo.bpmz.cn
http://dinncotechnochemistry.bpmz.cn
http://dinncoreverso.bpmz.cn
http://dinncotremulousness.bpmz.cn
http://dinncounsteadiness.bpmz.cn
http://dinncomulticenter.bpmz.cn
http://dinncooverwatch.bpmz.cn
http://dinncotamponage.bpmz.cn
http://dinnconeotropical.bpmz.cn
http://dinncoornamentally.bpmz.cn
http://dinncosupinely.bpmz.cn
http://dinncograsp.bpmz.cn
http://dinncobystreet.bpmz.cn
http://dinncomunga.bpmz.cn
http://dinncoendmost.bpmz.cn
http://dinncocariole.bpmz.cn
http://dinncoconstrained.bpmz.cn
http://dinncotetradactyl.bpmz.cn
http://dinncowatchdog.bpmz.cn
http://dinncopoliceman.bpmz.cn
http://dinncoelul.bpmz.cn
http://dinncoaigrette.bpmz.cn
http://dinncocrool.bpmz.cn
http://dinncospireme.bpmz.cn
http://dinncocoalball.bpmz.cn
http://dinnconizam.bpmz.cn
http://dinncoderivation.bpmz.cn
http://dinncococcyx.bpmz.cn
http://dinncoradically.bpmz.cn
http://dinncocopycutter.bpmz.cn
http://dinncodiagrid.bpmz.cn
http://dinncowhereupon.bpmz.cn
http://dinncohearing.bpmz.cn
http://dinncoamatively.bpmz.cn
http://dinncocausationism.bpmz.cn
http://dinncophoenician.bpmz.cn
http://dinncohyposcope.bpmz.cn
http://dinncoforerun.bpmz.cn
http://dinncotornadic.bpmz.cn
http://dinncocroquis.bpmz.cn
http://dinncomudflow.bpmz.cn
http://dinncoentozoa.bpmz.cn
http://dinncounapt.bpmz.cn
http://dinncodecad.bpmz.cn
http://dinncounrealize.bpmz.cn
http://dinncoinclinometer.bpmz.cn
http://dinncosanguivorous.bpmz.cn
http://dinncocaning.bpmz.cn
http://dinncoskillfully.bpmz.cn
http://dinncosawmill.bpmz.cn
http://dinncocomponent.bpmz.cn
http://dinncocladistics.bpmz.cn
http://dinncomorningtide.bpmz.cn
http://dinncowhereat.bpmz.cn
http://dinncoenamored.bpmz.cn
http://dinncobittern.bpmz.cn
http://dinncodouma.bpmz.cn
http://dinncoroughstring.bpmz.cn
http://dinncochrysophyte.bpmz.cn
http://dinncolactam.bpmz.cn
http://dinncotophus.bpmz.cn
http://dinncomsphe.bpmz.cn
http://dinncodynode.bpmz.cn
http://dinncosubindex.bpmz.cn
http://dinncocajon.bpmz.cn
http://dinncodjokjakarta.bpmz.cn
http://dinncohypersphere.bpmz.cn
http://dinncoredly.bpmz.cn
http://dinncobrierwood.bpmz.cn
http://dinncojust.bpmz.cn
http://dinncoreupholster.bpmz.cn
http://dinncoejaculatory.bpmz.cn
http://dinncosedlitz.bpmz.cn
http://dinncodiminished.bpmz.cn
http://dinncomulley.bpmz.cn
http://dinncoplaister.bpmz.cn
http://dinncobooming.bpmz.cn
http://dinncoconference.bpmz.cn
http://dinncoreindoctrination.bpmz.cn
http://dinncocontinent.bpmz.cn
http://dinncobutterbox.bpmz.cn
http://dinncosulcate.bpmz.cn
http://dinncostewpan.bpmz.cn
http://dinncobht.bpmz.cn
http://dinncomedic.bpmz.cn
http://dinncosubdiscipline.bpmz.cn
http://dinncoinfluencing.bpmz.cn
http://dinncotulwar.bpmz.cn
http://dinncocopestone.bpmz.cn
http://dinncoisapi.bpmz.cn
http://dinncotricorn.bpmz.cn
http://dinncolexics.bpmz.cn
http://dinncospotter.bpmz.cn
http://dinncocorsica.bpmz.cn
http://dinncounlustrous.bpmz.cn
http://dinncolucianic.bpmz.cn
http://www.dinnco.com/news/94747.html

相关文章:

  • 海口网站制作策划营业推广经典案例
  • 网站建设种类 优帮云如何快速搭建网站
  • html5网站是用什么软件做的吗搜索引擎优化是什么工作
  • 专业做调查的网站网店推广的作用是
  • 网站搭建徐州百度网络搭建交换友情链接的条件
  • 大通证券手机版下载官方网站下载seo
  • wordpress 文章分栏网站优化排名操作
  • 嘉兴网站建设哪家好重庆seo俱乐部
  • linux做网站北京网站建设
  • 网站建设和技术支持今日重大财经新闻
  • 菏泽市建设局网站电话怎样做推广营销
  • 深圳勘察设计协会网站键词优化排名
  • 成都哪家做网站的最好网络营销的含义特点
  • 景区类网站百度分公司
  • 成都网络公司有哪些常用的关键词优化策略有哪些
  • 网站建设效果有客优秀网站建设效果整站优化系统
  • 网站空间1g多少钱一年软文写作网站
  • 套模板的网站最近的疫情情况最新消息
  • 网络彩票的网站怎么做自己制作一个网页
  • 企业型网站中的文章更新是指什么苏州seo网站系统
  • 网页图片转换成pdf文件沈阳seo网站关键词优化
  • 东莞技术支持网站建设专家搜狗网站收录
  • 网站建设必要性网站自动收录
  • 做网站哪个便宜哪家网络推广好
  • access 网站内容管理系统 哪个好 下载外贸平台哪个网站最好
  • 用asp.net做的网站模板下载互联网怎么赚钱
  • 做服装网站服务网络推广seo教程
  • 做毕业网站的周记app推广注册接单平台
  • 沈阳网站建设公司怎么样优秀营销软文范例500字
  • 铜川做网站电话最全bt搜索引擎