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

做网站经营流量一站传媒seo优化

做网站经营流量,一站传媒seo优化,沈阳专业网站建设公司排名,小网站靠什么盈利一个简易的控制台程序,使用C#NPOI进行Excel处理,实现多个Excel文件的求和统计。 前提: 待统计的Excel格式相同统计结果表与待统计的表格格式一致 引入如下四个动态库: 1. NPOI.dll 2. NPOI.OOXML.dll 3. NPOI.OpenXml4Net.dll …

一个简易的控制台程序,使用C#+NPOI进行Excel处理,实现多个Excel文件的求和统计。

前提:

  1. 待统计的Excel格式相同
  2. 统计结果表与待统计的表格格式一致

引入如下四个动态库:
1. NPOI.dll
2. NPOI.OOXML.dll
3. NPOI.OpenXml4Net.dll
4. NPOI.OpenXmlFormats.dll

using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;namespace excelMergeCal
{class Program{static String BaseDIir = "d:\\docs";static String ResultFile = "d:\\result.xlsx";static int startRow = 5;static int endRow = 72;static int startColumn = 3;static int endColumn = 67;static List<CellWithPos> AllCells = new List<CellWithPos>();static void Main(string[] args){Console.WriteLine("********************************************************************************");Console.ForegroundColor = ConsoleColor.Red;Console.WriteLine("* 1.将待处理的Excel放在D盘的docs文件夹下****************************************");Console.WriteLine("* 2.将待处理的一个文件的全部数据单元格清空后放在D盘根目录下,命名为result.xlsx *");Console.WriteLine("* 3.关闭打开的excel文件 ********************************************************");Console.WriteLine("* 4.按下回车键(Enter)开始*******************************************************");Console.ForegroundColor = ConsoleColor.White;Console.WriteLine("********************************************************************************");Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("等待按下回车键(Enter)开始...");Console.ForegroundColor = ConsoleColor.White;Console.ReadLine();ReadAllExcel();Console.ForegroundColor = ConsoleColor.Green;Console.WriteLine("处理完成,按回车键(Enter)关闭.");Console.ReadLine();}static void ReadAllExcel(){string[] files = Directory.GetFiles(BaseDIir, "*.*", SearchOption.AllDirectories);foreach (string file in files){Console.WriteLine("正在处理文件:" + file);if (!file.EndsWith("xlsx") && !file.EndsWith("xls")){Console.WriteLine("文件 " + file + " 不是xlsx/xls后缀,已忽略.....");continue;}ReadExcel(file);// 处理每个文件}WriteResult();}static CellWithPos Get(int row, int col){for (int i = 0; i < AllCells.Count; i++){if (AllCells[i].row == row && AllCells[i].column == col)return AllCells[i];}return null;}public static void WriteResult(){String path = ResultFile;string extension = System.IO.Path.GetExtension(path);// 第一步:读取文件流NPOI.SS.UserModel.IWorkbook workbook;using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)){if (extension.Equals(".xls")){workbook = new HSSFWorkbook(stream);}else{workbook = new XSSFWorkbook(stream);}#region 读取第一个sheet页面ISheet sheet = workbook.GetSheetAt(0);//第一个sheet页(列表)int rowCount = sheet.LastRowNum;IRow row = sheet.GetRow(0);  //读取当前行数据for (int i = startRow; i <= sheet.LastRowNum & i <= endRow; i++){row = sheet.GetRow(i);  //读取当前行数据if (row == null) continue;//Console.WriteLine(row.GetCell(1).ToString());for (int j = startColumn; j < row.Cells.Count & j <= endColumn; j++){ICell cell = row.GetCell(j);CellWithPos cp = Get(i, j);if (cp != null){cell.SetCellValue(cp.value);}}}#endregion}// 第三步:写入文件流using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write)){workbook.Write(stream);workbook.Close();}}public static void ReadExcel(string path){try{IWorkbook wk = null;string extension = System.IO.Path.GetExtension(path);FileStream fs = File.OpenRead(path);if (extension.Equals(".xls")){//把xls文件中的数据写入wk中wk = new HSSFWorkbook(fs);}else{//把xlsx文件中的数据写入wk中wk = new XSSFWorkbook(fs);}fs.Close();int sheetCount = wk.NumberOfSheets;//获取sheet的数量ISheet sheet = wk.GetSheetAt(0);//第一个sheet页(列表)int rowCount = sheet.LastRowNum;IRow row = sheet.GetRow(0);  //读取当前行数据#region 读取第一个sheet页面for (int i = startRow; i <= sheet.LastRowNum & i <= endRow; i++){row = sheet.GetRow(i);  //读取当前行数据if (row == null) continue;//Console.WriteLine(row.GetCell(1).ToString());for (int j = startColumn; j < row.Cells.Count & j <= endColumn; j++){ICell cell = row.GetCell(j);double val = 0;if (cell.CellType == CellType.Formula){val = cell.NumericCellValue;}else if (cell.CellType == CellType.Numeric){val = cell.NumericCellValue;}else if (cell.CellType == CellType.String || cell.CellType == CellType.Blank){Double.TryParse(cell.StringCellValue, out val);}else{Console.WriteLine("單元格格式錯誤:" + i + "," + j);Console.WriteLine("單元格的值:" + i + "," + j + " : " + val);}CellWithPos cp = Get(i, j);if (cp != null){cp.value += val;}else{AllCells.Add(new CellWithPos() { row = i, column = j, value = val });}}}#endregion}catch (Exception ex){Console.WriteLine(ex.Message);}}class CellWithPos{public int row;public int column;public double value = 0;}}
}
http://www.ds6.com.cn/news/43856.html

相关文章:

  • wordpress 侧边收起seo分析案例
  • 河南网站制作公司哪家好网络推广营销方案免费
  • 手机网站怎么做SEO优化seo实战培训课程
  • 门户网站属于什么类型的模式谷歌搜索入口 镜像
  • 网站维护内容及费用app开发公司推荐
  • 昆明做企业网站多少钱资源搜索
  • h5制作报价细则志鸿优化网下载
  • asp.net动态网站成品西安seo服务外包
  • 怎么写网站规划方案怎么提高百度搜索排名
  • 传奇端游平台青岛网站建设优化
  • 网站建设是否属于技术合同北京百度推广客服电话多少
  • 网站建设维护合同范本百度推广登录后台
  • 长春哪里做网站今日国际新闻摘抄十条
  • 什么做直播网站浏览器下载安装2023版本
  • 免费咨询医生的软件有什么域名年龄对seo的影响
  • wordpress插件访客能用吗专业seo外包
  • 独立站seo是什么怎么做市场推广
  • wordpress 首页乱码企业站seo报价
  • 如何在网站做淘宝页面新疆头条今日头条新闻
  • 网站域名 文件夹竞价推广哪家公司好
  • 做什么网站比较简单正规网站优化推广
  • 网站开发 定制 多少 钱营销策划案例
  • h5网站开发用什么软件制作网站注册流程
  • wordpress大神北京aso优化
  • linux用.net做网站如何申请一个网站域名
  • 嘉兴网嘉兴网站建设安徽seo
  • 腾飞网站建设营销网站建设选择原则
  • 什么网站做h5做得好南昌seo代理商
  • 中龙建电力建设股份有限公司网站广东整治互联网霸王条款
  • wordpress连接怎么去掉日期搜索seo怎么优化