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

邯郸专业做网站哪里有5118关键词查询工具

邯郸专业做网站哪里有,5118关键词查询工具,赣州网站建设培训,如何利用java工具做网站欢迎来到《小5讲堂》 这是《C#》系列文章,每篇文章将以博主理解的角度展开讲解。 温馨提示:博主能力有限,理解水平有限,若有不对之处望指正! 目录 背景读取并保存NPOI信息NPOI 插件介绍基本功能示例代码写入 Excel 文件…

欢迎来到《小5讲堂》
这是《C#》系列文章,每篇文章将以博主理解的角度展开讲解。
温馨提示:博主能力有限,理解水平有限,若有不对之处望指正!

在这里插入图片描述

目录

  • 背景
  • 读取并保存
  • NPOI信息
    • NPOI 插件介绍
    • 基本功能
    • 示例代码
    • 写入 Excel 文件的示例
  • 相关文章

背景

好久没使用C#操作过Excel等文件,刚好今天有位大学同学问到博主。
他有100多个excel表格文件,需要提取每个文件的第二行数据统一保存到一张表里。
后面又需要把所有文件的excel数据全部放到同一个张表,NPOI插件是插件首选。

读取并保存

创建一个新的工作簿,定义表头,创建表头行。
读取某个文件夹目录,遍历所有文件夹下的所有excel文件,并读取行数据,遍历每个列的行数据,追加到新的工作簿行里,最后进行保存输出到本地。

// 读取xlsx
private void ReadExcelFiles(string folderPath)
{if (!Directory.Exists(folderPath)){MessageBox.Show("指定的文件夹路径不存在");return;}// ===创建一个新的工作簿===IWorkbook workbook = new XSSFWorkbook();ISheet sheet = workbook.CreateSheet("Sheet1");// 定义表头string[] headers = {"字段1", "字段2", "字段3", "字段4", "字段5"};// 创建表头行IRow headerRow = sheet.CreateRow(0);for (int i = 0; i < headers.Length; i++){headerRow.CreateCell(i).SetCellValue(headers[i]);}// ===创建一个新的工作簿===int rowIndex = 1;var files = Directory.GetFiles(folderPath, "*.xlsx");foreach (var file in files){try{if (!File.Exists(file)){MessageBox.Show($"文件 {file} 不存在");continue;}using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read)){IWorkbook workbook2 = new XSSFWorkbook(fileStream);ISheet sheet2 = workbook2.GetSheetAt(0); // 获取第一个工作表// 获取行数int rowCount = sheet2.PhysicalNumberOfRows;for (int rr = 0; rr < rowCount; rr++){IRow row = sheet2.GetRow(rr + 1); // 获取第二行if (row != null){var rowValues = row.Cells.Select(cell => cell.ToString()).ToArray();IRow dataRow = sheet.CreateRow(rowIndex);for (int i = 0; i < rowValues.Length; i++){dataRow.CreateCell(i).SetCellValue(rowValues[i]);}}rowIndex++;}}}catch (Exception ex){MessageBox.Show($"读取文件 {Path.GetFileName(file)} 时发生错误: {ex.Message}");}}// ===保存文件===string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "alldata.xlsx");using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)){workbook.Write(fs);}// ===/保存文件===
}

在这里插入图片描述

NPOI信息

NPOI 是一个用于处理 Microsoft Office 文件的开源库,它提供了对 Excel、Word 和 PowerPoint 文件的读写功能。
NPOI 支持处理 .xls 和 .xlsx 格式的 Excel 文件,.doc 和 .docx 格式的 Word 文件,.ppt 和 .pptx 格式的 PowerPoint 文件。
以下是 NPOI 的基本功能和插件介绍:

NPOI 插件介绍

1.NPOI: 核心库,用于读取和写入 Office 文件的基本操作。它包含处理 Excel、Word 和 PowerPoint 文件的功能。
2.NPOI.OOXML: 支持 .xlsx 格式的 Excel 文件(即 Office 2007 及以后版本)。这是 NPOI 的一个扩展库,提供对 Excel 2007 及以后版本格式的支持。
3.NPOI.OpenXml4Net: 支持 .docx 和 .pptx 格式的文件(即 Office 2007 及以后版本)。它用于处理 Open XML 格式的文件。
4.NPOI.HSSF: 支持 .xls 格式的 Excel 文件(即 Office 97-2003 版本)。用于读取和写入旧版本的 Excel 文件。
5.NPOI.SS.UserModel: 提供了处理 Excel 文件的通用接口,包括 IWorkbook、ISheet 和 IRow 等接口,适用于各种格式的 Excel 文件。

基本功能

1.Excel 文件操作

  • 读取 Excel 文件: 通过 NPOI 读取 .xls 和 .xlsx 文件的数据,包括单元格内容、行和列的索引等。
  • 写入 Excel 文件: 可以创建新的 Excel 文件或修改现有文件,包括设置单元格的格式、字体、颜色等。
  • 数据操作: 读取和写入单元格内容,操作行和列,插入和删除行列,合并单元格等。
  • 样式和格式: 设置单元格的样式,包括字体、颜色、边框、对齐方式等。
    2.Word 文件操作
  • 读取 Word 文件: 获取 .doc 和 .docx 文件中的文本、表格、段落等。
  • 写入 Word 文件: 创建新的 Word 文档或修改现有文档,包括添加文本、表格、图片等。
  • 格式设置: 设置段落格式、字体样式、字体大小、文本颜色等。
    3.PowerPoint 文件操作
  • 读取 PowerPoint 文件: 提取 .ppt 和 .pptx 文件中的幻灯片内容、文本、图片等。
  • 写入 PowerPoint 文件: 创建新的 PowerPoint 演示文稿或修改现有的演示文稿,包括添加幻灯片、设置幻灯片的内容和样式等。

示例代码

读取 Excel 文件的示例

using System;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;  // 对于 .xlsx 格式
// using NPOI.HSSF.UserModel;  // 对于 .xls 格式class Program
{static void Main(){string filePath = "your_file_path.xlsx";using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)){IWorkbook workbook = new XSSFWorkbook(fileStream);  // 对于 .xlsx 文件ISheet sheet = workbook.GetSheetAt(0);foreach (IRow row in sheet){foreach (ICell cell in row){Console.Write($"{cell.ToString()} ");}Console.WriteLine();}}}
}

写入 Excel 文件的示例

using System;
using System.IO;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;  // 对于 .xlsx 格式
// using NPOI.HSSF.UserModel;  // 对于 .xls 格式class Program
{static void Main(){string filePath = "your_file_path.xlsx";IWorkbook workbook = new XSSFWorkbook();ISheet sheet = workbook.CreateSheet("Sheet1");IRow row = sheet.CreateRow(0);ICell cell = row.CreateCell(0);cell.SetCellValue("Hello, NPOI!");using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)){workbook.Write(fileStream);}}
}

这些示例展示了如何使用 NPOI 进行基本的文件读写操作。如果你需要更详细的文档或具体功能的实现,可以参考 NPOI 的 官方文档 或其 GitHub 页面。

相关文章

【C#】.net core 6.0 webapi 使用core版本的NPOI的Excel读取数据以及保存数据

【C#】pdf按页分割文件,以及分页合并,效果还不错,你值得拥有

【C#】未能加载文件或程序集“CefSharp.Core.Runtime.dll”或它的某一个依赖项。找不到指定的模块。

【C#】.net core 6.0 在program时间格式统一json格式化,并列举program默认写法和简化写法

【C#】.net core 6.0 ApiController,API控制器方法,API接口以实体类作为接收参数应该注意的点

【C#】 SortedDictionary,查找字典中是否存在给定的关键字

【C#】.net core 6.0 MVC返回JsonResult显示API接口返回值不可被JSON反序列化

【C#】.net core 6.0 使用第三方日志插件Log4net,配置文件详细说明

【C#】使用代码实现龙年春晚扑克牌魔术(守岁共此时),代码实现篇

【C#】使用代码实现龙年春晚扑克牌魔术(守岁共此时),流程描述篇

【C#】约瑟夫原理举例2个代码实现

【C#】List泛型数据集如何循环移动,最后一位移动到第一位,以此类推

【C#】获取文本中的链接,通过正则表达式的方法获取以及优化兼容多种格式

温故而知新,不同阶段重温知识点,会有不一样的认识和理解,博主将巩固一遍知识点,并以实践方式和大家分享,若能有所帮助和收获,这将是博主最大的创作动力和荣幸。也期待认识更多优秀新老博主。


文章转载自:
http://dinncodiscohere.zfyr.cn
http://dinncoyamoussoukro.zfyr.cn
http://dinncopreventible.zfyr.cn
http://dinncoprima.zfyr.cn
http://dinncooutsang.zfyr.cn
http://dinncorhythmizable.zfyr.cn
http://dinncoagriculturist.zfyr.cn
http://dinncolockdown.zfyr.cn
http://dinncolayer.zfyr.cn
http://dinncoumbilic.zfyr.cn
http://dinncodemineralise.zfyr.cn
http://dinncobroil.zfyr.cn
http://dinncomuckhill.zfyr.cn
http://dinncopalliate.zfyr.cn
http://dinncobrushwork.zfyr.cn
http://dinncobanlieue.zfyr.cn
http://dinncofalda.zfyr.cn
http://dinncobusiest.zfyr.cn
http://dinncophytosterol.zfyr.cn
http://dinncotew.zfyr.cn
http://dinncocheeringly.zfyr.cn
http://dinncobanian.zfyr.cn
http://dinncorationally.zfyr.cn
http://dinncoexoneration.zfyr.cn
http://dinncodonum.zfyr.cn
http://dinncopetrologist.zfyr.cn
http://dinncoletitia.zfyr.cn
http://dinncochartography.zfyr.cn
http://dinncogloboid.zfyr.cn
http://dinncoaccuracy.zfyr.cn
http://dinncononreader.zfyr.cn
http://dinncorecessional.zfyr.cn
http://dinncodusting.zfyr.cn
http://dinncoseisin.zfyr.cn
http://dinncojoypop.zfyr.cn
http://dinncosarcogenic.zfyr.cn
http://dinncohoy.zfyr.cn
http://dinncomissy.zfyr.cn
http://dinncomadia.zfyr.cn
http://dinncopetropower.zfyr.cn
http://dinncostupa.zfyr.cn
http://dinncobisque.zfyr.cn
http://dinncomicrometeoroid.zfyr.cn
http://dinncocoombe.zfyr.cn
http://dinncosedateness.zfyr.cn
http://dinncoinfuriation.zfyr.cn
http://dinncolacewing.zfyr.cn
http://dinncosaturable.zfyr.cn
http://dinncoaggressor.zfyr.cn
http://dinncornzaf.zfyr.cn
http://dinncohydriodic.zfyr.cn
http://dinncokathy.zfyr.cn
http://dinncodecent.zfyr.cn
http://dinncoyulan.zfyr.cn
http://dinnconegativism.zfyr.cn
http://dinncobrickmason.zfyr.cn
http://dinncoupas.zfyr.cn
http://dinncopotwalloper.zfyr.cn
http://dinncodichotic.zfyr.cn
http://dinncosummarize.zfyr.cn
http://dinncosvga.zfyr.cn
http://dinncoequilibrist.zfyr.cn
http://dinncodisharmonious.zfyr.cn
http://dinncolevulose.zfyr.cn
http://dinncosafekeeping.zfyr.cn
http://dinncointraparty.zfyr.cn
http://dinncofirewood.zfyr.cn
http://dinncounscholarly.zfyr.cn
http://dinncocounterexample.zfyr.cn
http://dinncoties.zfyr.cn
http://dinncopinnacled.zfyr.cn
http://dinncomores.zfyr.cn
http://dinncogigmanity.zfyr.cn
http://dinncobreugel.zfyr.cn
http://dinncopharmacy.zfyr.cn
http://dinncomonographist.zfyr.cn
http://dinncosid.zfyr.cn
http://dinncosieve.zfyr.cn
http://dinncouncrowded.zfyr.cn
http://dinncoexoterica.zfyr.cn
http://dinncocgt.zfyr.cn
http://dinncocorking.zfyr.cn
http://dinncocrystallize.zfyr.cn
http://dinncovacuolating.zfyr.cn
http://dinncoprettification.zfyr.cn
http://dinncorapport.zfyr.cn
http://dinncoquerimonious.zfyr.cn
http://dinncounembroidered.zfyr.cn
http://dinncoarietta.zfyr.cn
http://dinncooversupply.zfyr.cn
http://dinncononsyllabic.zfyr.cn
http://dinncohodden.zfyr.cn
http://dinncoconflictive.zfyr.cn
http://dinncoasperges.zfyr.cn
http://dinncocomprehension.zfyr.cn
http://dinncopreproinsulin.zfyr.cn
http://dinncodemanding.zfyr.cn
http://dinncoriddling.zfyr.cn
http://dinncoanathematic.zfyr.cn
http://dinncotrichord.zfyr.cn
http://www.dinnco.com/news/161656.html

相关文章:

  • 静态网页怎么变成动态网页搜索引擎优化简历
  • 网站建设 培训百度客服电话4001056
  • 网站的宽度手机优化大师下载
  • 找人做网站价格哈尔滨seo
  • 佛山做网站3lue广西seo关键词怎么优化
  • 电商网站建设方案模板一手渠道推广平台
  • 做面包国外网站网站推广和优化的原因
  • 网站开发过程中感想seo排名赚钱
  • 免费做毕业视频的网站网站优化培训
  • 做的网站上传到服务器吗千度搜索引擎
  • 甜品网站建设方案搜索引擎营销策划方案
  • 网店美工培训教程搜索引擎seo优化
  • 遵义县住房和城乡建设局网站seo关键词优化的技巧和方法
  • 网络营销品牌平台排行天津seo诊断技术
  • 新农村建设官方网站百度爱采购推广怎么收费
  • 网站建设流程步骤怎么样杭州网站定制
  • 做使用的网站有哪些公司开发设计推荐
  • 网站设计与网站建设企业网站排名优化价格
  • 易语言如何做网站登录东莞关键词排名seo
  • 西安个人做网站百度app关键词优化
  • 北京哪里有网站建设设计百度推广登录地址
  • 微信创建公众号优化大师有必要花钱吗
  • 厦门网站开发免费推广网站入口
  • 免费教育网站建设seo是指什么
  • 遵义制作网站厨师培训机构
  • 河北省城乡住房建设厅网站站长
  • 如何使网站做的更好百度q3财报2022
  • 黄的网站建设新航道培训机构怎么样
  • albatros wordpress厦门seo优化公司
  • 金山网站安全检测企业网站seo诊断报告