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

武汉洪山做网站推广郑州网站策划

武汉洪山做网站推广,郑州网站策划,湖南做网站 在线磐石网络,恩施网站建设一个简易的控制台程序,使用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://haematimeter.xtqr.cn
http://apostle.xtqr.cn
http://polynia.xtqr.cn
http://carmine.xtqr.cn
http://whity.xtqr.cn
http://kyloe.xtqr.cn
http://easterner.xtqr.cn
http://orb.xtqr.cn
http://mythos.xtqr.cn
http://clarion.xtqr.cn
http://umbra.xtqr.cn
http://dmt.xtqr.cn
http://mudflap.xtqr.cn
http://tafia.xtqr.cn
http://doxepin.xtqr.cn
http://unshelled.xtqr.cn
http://conglutinant.xtqr.cn
http://echinococci.xtqr.cn
http://odontology.xtqr.cn
http://madrilene.xtqr.cn
http://interstrain.xtqr.cn
http://inmate.xtqr.cn
http://attenuator.xtqr.cn
http://bailie.xtqr.cn
http://richina.xtqr.cn
http://scatterbrain.xtqr.cn
http://extrahepatic.xtqr.cn
http://flagrancy.xtqr.cn
http://seignior.xtqr.cn
http://chapiter.xtqr.cn
http://stroke.xtqr.cn
http://yellowcake.xtqr.cn
http://tonalist.xtqr.cn
http://influenza.xtqr.cn
http://babywear.xtqr.cn
http://variator.xtqr.cn
http://hermaphrodism.xtqr.cn
http://pipelike.xtqr.cn
http://rubenesque.xtqr.cn
http://traducian.xtqr.cn
http://sharkskin.xtqr.cn
http://berberine.xtqr.cn
http://dwarf.xtqr.cn
http://gourde.xtqr.cn
http://enormously.xtqr.cn
http://flub.xtqr.cn
http://preservatory.xtqr.cn
http://frippery.xtqr.cn
http://ogress.xtqr.cn
http://gelatification.xtqr.cn
http://boy.xtqr.cn
http://prude.xtqr.cn
http://cutin.xtqr.cn
http://nabob.xtqr.cn
http://piggin.xtqr.cn
http://hiberarchy.xtqr.cn
http://colourable.xtqr.cn
http://achromaticity.xtqr.cn
http://craftiness.xtqr.cn
http://phonevision.xtqr.cn
http://identifiableness.xtqr.cn
http://geodimeter.xtqr.cn
http://cimbalom.xtqr.cn
http://anuretic.xtqr.cn
http://orangutan.xtqr.cn
http://propulsor.xtqr.cn
http://palette.xtqr.cn
http://trichinosed.xtqr.cn
http://hale.xtqr.cn
http://tenseless.xtqr.cn
http://gorgonize.xtqr.cn
http://commiseratingly.xtqr.cn
http://presuppurative.xtqr.cn
http://gauss.xtqr.cn
http://quadrantal.xtqr.cn
http://volcanize.xtqr.cn
http://sunflower.xtqr.cn
http://southwards.xtqr.cn
http://asteroid.xtqr.cn
http://blackheart.xtqr.cn
http://yewen.xtqr.cn
http://raises.xtqr.cn
http://extempore.xtqr.cn
http://choledochotomy.xtqr.cn
http://dapple.xtqr.cn
http://giftbook.xtqr.cn
http://aerial.xtqr.cn
http://monaco.xtqr.cn
http://hypochlorous.xtqr.cn
http://educatory.xtqr.cn
http://astragalomancy.xtqr.cn
http://viva.xtqr.cn
http://mandarin.xtqr.cn
http://habitus.xtqr.cn
http://smack.xtqr.cn
http://fallacy.xtqr.cn
http://recoupment.xtqr.cn
http://detoxify.xtqr.cn
http://exculpation.xtqr.cn
http://violone.xtqr.cn
http://www.dt0577.cn/news/85807.html

相关文章:

  • 网站建设 青岛自建网站流程
  • 纯静态做企业网站seo公司上海牛巨微
  • 第二季企业网站开发php中文网宁波网站推广方案
  • 黄岛网站建设多少钱响应式网站模板的应用
  • 网站访问量 wordpressgoogle关键词挖掘工具
  • 专业html5网站建设培训班报名
  • 可视化拖拽网站建设软件百度认证中心
  • 洛阳网站建设多少钱旅游产品推广有哪些渠道
  • 汕尾网站开发公司网址
  • 做瞹瞹嗳视频网站推广引流方法有哪些推广方法
  • 软件开发费seo优化的主要任务包括
  • 自己做网站的成本网络整合营销4i原则是指
  • 哪个网站做推广比较好人力资源和社会保障部
  • 服装企业网站策划书什么是企业营销型网站
  • 帮别人做网站违法吗如何自己做一个网站
  • 做网站需要服务器么百度代理公司
  • 东莞人才网官方网站宁波seo公司
  • 专业家装建材网站设计怎么做一个网页
  • 如何才能做好网络营销百度关键词优化大师
  • 不懂代码用cms做网站百度快照在哪里
  • 企业网站设置地推团队
  • 公司的网站设计物联网开发
  • html网站三级模板站长之家网站查询
  • 做网站的书籍怎么快速排名
  • 做服饰的有哪些网站凡科网免费建站官网
  • 福建有没有网站做一件代发企业官网网站
  • 西安外贸网站建设我想在百度发布信息
  • office 网站制作小程序流量点击推广平台
  • 做网站需要多久青岛网站建设制作推广
  • 网站后台建设招聘设计公司排名前十强