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

制作一个.net网站需要全网营销推广平台有哪些

制作一个.net网站需要,全网营销推广平台有哪些,Wordpress百万访问优化,网站建设需要数学NuGet中安装npoi 创建excel模板,替换其中的内容生成新的excel文件。 例子中主要写了这四种情况: 1、替换单个单元格内容; 2、替换横向多个单元格; 3、替换表格; 4、单元格中插入图片; using System.IO; …

NuGet中安装npoi

创建excel模板,替换其中的内容生成新的excel文件。

例子中主要写了这四种情况:

1、替换单个单元格内容;
2、替换横向多个单元格;
3、替换表格;
4、单元格中插入图片;

using System.IO;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using System.Diagnostics;public static void exportExcel(){string currentDirectory = System.AppDomain.CurrentDomain.BaseDirectory;string templatePath = currentDirectory + "/template.xlsx";string outputPath = currentDirectory + "/output/" + DateTime.Now.ToString("yyyyMMdd"); //存储路径string outputPathExcel = outputPath + "/" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_test.xlsx";// 检查路径是否存在if (!Directory.Exists(outputPath)){Directory.CreateDirectory(outputPath);}//1、单元格直接替换部分Dictionary<string, string> replacements = new Dictionary<string, string>{{ "test1", "测试1" },{ "test2", "测试2" }};//2、横向数组,曲线表格Dictionary<string, double[]> replacementsArrayH = = new Dictionary<string, double[]>();replacementsArrayH["item1"] = new double[] { 1.1, 2.2, 3.3 };replacementsArrayH["item2"] = new double[] { 4.4, 5.5, 6.6 };//3、表格数据//自己定义类//public TaskItem{//  private string name;//  private string age;//  public TaskItem(){//  }//  public TaskItem(string name, string age){//	  this.name=name;//	  this.age=age;//  }//  ……//}List<TaskItem> taskItemList = new List<TaskItem>();taskItemList.Add(new TaskItem("Alice", "30"));taskItemList.Add(new TaskItem("Bob", "25"));try{// excel导出using (FileStream file = new FileStream(templatePath, FileMode.Open, FileAccess.Read)){IWorkbook workbook = new XSSFWorkbook(file);ISheet sheet = workbook.GetSheetAt(0);// 替换模板中的字符串for (int rowIndex = 0; rowIndex <= sheet.LastRowNum; rowIndex++){IRow row = sheet.GetRow(rowIndex);if (row == null){continue;}for (int cellIndex = 0; cellIndex < row.LastCellNum; cellIndex++){ICell cell = row.GetCell(cellIndex);if (cell != null && cell.CellType == CellType.String){string cellValue = cell.StringCellValue;//填充单个文本foreach (var replacement in replacements){if (cellValue.Equals(replacement.Key)){cell.SetCellValue(cellValue.Replace(replacement.Key, replacement.Value));}}//填充横向数组foreach (var replacement in replacementsArrayH){string placeholder = replacement.Key;double[] values = replacement.Value;int index = values.Length;if (cellValue.Equals(replacement.Key)){for (int colNum = 0; colNum < index; colNum++){cell = row.GetCell(cellIndex + colNum);cell.SetCellValue(cellValue.Replace(placeholder, values[colNum].ToString()));}}}//填充详情表格if (cellValue.Equals("table")){if (list == null) // list 为业务需要写入数据{continue;}// 添加数据行for (var i = 0; i < list.Count; i++){TaskItem item = list[i];// 因为模版内已经存在一格空行,所以直接赋值,后续从此行进行 CopyRow 即可if (i == 0){SetRowCellValue(row, item, cellIndex);continue;}//其他行var newRow = sheet.CopyRow(rowIndex, rowIndex + i);SetRowCellValue(newRow, item, cellIndex);}}}}}//4、导出图片string picPath = currentDirectory + "/test.png";//图片byte[] bytes = File.ReadAllBytes(picPath);int pictureIndex = workbook.AddPicture(bytes, PictureType.PNG);// 定义图片的位置var drawingPatriarch = sheet.CreateDrawingPatriarch();var anchor = drawingPatriarch.CreateAnchor(0, 0, 0, 0, 1, 6, 12, 13); // 参数依次是:dx1, dy1, dx2, dy2, col1, row1, col2, row2// 在单元格中添加图片var picture = drawingPatriarch.CreatePicture(anchor, pictureIndex);// 保存新文件using (FileStream outputFile = new FileStream(outputPathExcel, FileMode.Create, FileAccess.Write)){workbook.Write(outputFile);}}}catch (Exception ex){}}/// <summary>/// 填充表格数据/// </summary>/// <param name="row">填充行</param>/// <param name="item">填充数据</param>/// <param name="cellIndex">列开始行</param>private static void SetRowCellValue(IRow row, TaskItem item, int cellIndex){ICell cell = row.GetCell(cellIndex++);cell.SetCellValue(item.name);cellIndex++;cell = row.GetCell(cellIndex++);cell.SetCellValue(item.age);}

excel模板内容:

导出后:

http://www.jinmujx.cn/news/80769.html

相关文章:

  • 用淘宝域名做网站什么效果新手学seo
  • 网站广告位投放抖音seo软件
  • 在哪能学到网站建设专业百度平台投诉人工电话
  • 长春哪家公司做网站好百度pc网页版
  • 网站到期可以续费广州网络公司
  • 给你一个网站你怎么做的吗广告投放策略
  • 如何做网站条幅闪图新网域名注册官网
  • wordpress个人站无法升级经典模板网站建设
  • 做tb任务赚钱的网站龙华网站建设
  • 外贸公司怎么做网站百度关键词优化和百度推广
  • 模板建网站多少钱百度推广开户费用标准
  • 网站怎么做动态主图深圳网站seo哪家快
  • 枣庄网站建设电话西安今日头条新闻
  • 谷歌地图嵌入网站网页制作公司
  • 企业网站建设服务热线今日头条搜索优化
  • 网站建设及推广方案武汉网站运营专业乐云seo
  • 手机怎样做网站广告推广系统
  • 成都网站建设外贸优搜云seo
  • 天津网站优化公司哪家专业网页制作教程步骤
  • 找人做网站要准备什么软件可以访问境外的浏览器
  • 网站建设比较好的多少钱百度收录关键词
  • 网站开发常用中间件廊坊seo推广
  • 江门模板建站定制今日头条热搜榜
  • 自适应网站怎么做移动配置怎么在百度做宣传广告
  • 揭阳网站制作费用百度seo教程网
  • 宁波网站建设与推广方案海外营销推广
  • 潢川网站建设企业员工培训课程有哪些
  • 怎么做阿里妈妈推广网站seo排名第一
  • 会泽做网站淘客推广
  • 在哪个网站做ppt模板赚钱如何做好营销推广