.Net读取xlsx文件Excel2007

开源的读取Excel文件组件-ExcelDataReader 阅读详情
.NET 读取Excel 2007的xlsx文件和读取老的.xls文件是一样的,都是用Oledb读取,仅仅连接字符串不同而已。
读取xlsx 用的是Microsoft.Ace.OleDb.12.0;
具体操作方法如下:
public static DataTable GetExcelToDataTableBySheet(string FileFullPath, string SheetName)
{
            //string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + FileFullPath + ";Extended Properties='Excel 8.0; HDR=NO; IMEX=1'"; //此连接只能操作Excel2007之前(.xls)文件
            string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + FileFullPath + ";Extended Properties='Excel 12.0; HDR=NO; IMEX=1'"; //此连接可以操作.xls与.xlsx文件
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            DataSet ds = new DataSet();
            OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", SheetName), conn);                    //("select * from [Sheet1$]", conn);
            odda.Fill(ds, SheetName);
            conn.Close();
            return ds.Tables[0];
 
}
  
 
读取Excel文件时,可能一个文件中会有多个Sheet,因此获取Sheet的名称是非常有用的。
 
具体操作方法如下:
 
//根据Excel物理路径获取Excel文件中所有表名
 
public static String[] GetExcelSheetNames(string excelFile)
{
            OleDbConnection objConn = null;
            System.Data.DataTable dt = null;
 
            try
            {
                //string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + excelFile + ";Extended Properties='Excel 8.0; HDR=NO; IMEX=1'"; //此连接只能操作Excel2007之前(.xls)文件
 
                string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + excelFile + ";Extended Properties='Excel 12.0; HDR=NO; IMEX=1'"; //此连接可以操作.xls与.xlsx文件
                objConn = new OleDbConnection(strConn);
                objConn.Open();
                dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                if (dt == null)
                {
                    return null;
                }
                String[] excelSheets = new String[dt.Rows.Count];
                int i = 0;
                foreach (DataRow row in dt.Rows)
                {
                    excelSheets[i] = row["TABLE_NAME"].ToString();
                    i++;
                }
 
                return excelSheets;
            }
            catch
            {
                return null;
            }
            finally
            {
                if (objConn != null)
                {
                    objConn.Close();
                    objConn.Dispose();
                }
                if (dt != null)
                {
                    dt.Dispose();
                }
            }
}
非常简单就可以读取到文件内容了,.NET就是强大。
命名空间:using System.IO;
返回路径:StreamReader sr = new StreamReader(@"路径", System.Text.Encoding.GetEncoding("GB18030")); //[设置中文编码]
读取文件:textBox1.Text = sr.ReadToEnd();
关闭流:sr.Close();
三种ASP.NET读取Excel文件的方法浅析(含完整代码) 一、ASP.NET读取Excel文件方法一:采用OleDB读取Excel文件: 把Excel文件当做一个数据源来进行数据的读取操作,实例如下: 1. public DataSet ExcelToDS(string Path) 2. { 3. string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data Source="+ Path +";"+"Extended Properties=Excel 8.0;"; 4. OleDbConnection conn = new OleDbConnection(strConn); 5. conn.Open(); 6. string strExcel = ""; 7. OleDbDataAdapter myCommand = null; 8. DataSet ds = null; …… 立即下载

相关推荐

读写xlsx.zip

在项目开发过程中,策划们可能会配置很多的数据在一些文本文本中,例如商城物品,随机名称等,往往这些数据会放在不同的Excel当中。那么我们就需要通过读取或者写入Excel的内容,已供程序使用

C# .NET读取和写入Excel表数据(手把手教)

(1)首先在程序:“引用”右键--点击“管理NuGet程序包” (我这里是已经引入过了,所以会显示引用中有NPOI)(3)在程序中引入相应的命名空间,编写读取excel表格的封装代码(万能)(2)在“浏览”处搜索“NPOI”,选择适当版本安装(需要联网)(1)同样按照上面读取excel中的第一步,添加NPOI引用。(4)调用上述读取excel表的方法,读取数据并存取。(2)添加命名空间,编写将数据写入excel表的代码。(3)调用上述写入excel表的代码,写入数据。

ucic_0000001的博客 3万+

C#通过NOPI导出Excel(支持Excel2007以上和以下,全支持,完整代码封装,绝对可用,支持List,DataTable)

C#通过NOPI导出Excel(支持Excel2007以上和以下,全支持,完整代码封装,绝对可用,支持List,DataTable),资源包含,导出的Nopi所需的所有dll引用,导出源代码封装,代码使用范例。真实可用。直接引入开发,可在源代码上自行修改扩展功能。

.Net通过OleDb方式读取Excel

.Net读取xlsx文件 连接 Excel 表: string sqlconnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\\Book\\Book.xls;Extended Properties=Excel 8.0"; (1)Excel 连接字符串: 通过OleDb方式读取Excel...

weixin_30617797的博客 236

PCIe链路训练Recovery状态机:从RcvrLock到链路稳定的关键路径

本文深入解析PCIe链路训练中的Recovery状态机,特别是RcvrLock状态的关键作用。从Block对齐、均衡预设值应用到状态转移条件,详细介绍了确保链路稳定的技术要点,并提供了高速率下的特殊处理方法和常见问题排查指南,帮助工程师解决PCIe链路不稳定问题。

weixin_28739079的博客 175

python中frida的安装+frida-server(雷电模拟器)保姆级安装教程

frida的安装,安卓逆向,adb

2301_80224944的博客 4582

ASP.NET读取EXCEL文件的三种经典方法

最近研究了ASP.NET如何高效读取EXCEL文件,现总结如下: 1.方法一:采用OleDB读取EXCEL文件: 把EXCEL文件当做一个数据源来进行数据的读取操作,实例如下:public DataSet ExcelToDS(string Path) { string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"Data S...

weixin_30834783的博客 555

VM与欧姆龙PLC通讯设置实战:Fins TCP/UDP协议详解

本文详细解析了VM(VisionMaster)与欧姆龙PLC通过Fins TCP/UDP协议进行通讯的实战设置。内容涵盖网络配置、协议选择(TCP可靠性与UDP实时性)、VM端地址映射与数据点添加、以及数据接收解析流程,并提供了常见错误排查与高级调试技巧,帮助视觉与自动化工程师快速实现稳定可靠的工业通讯集成。

weixin_29172963的博客 330

.NET读取Execl数据

需要引用 using System.Data; using System.Data.OleDb; 调用:var customerInfoList = await GetExeclTableAsync("D:/......./ddd.xlsx"); 封装方法 #region 读取Excel中的数据 /// <summary> /// 读取...

zhongniangyou的专栏 313

Office Tool Plus:正版Office干净部署指南

Office部署是Windows新机配置的关键环节,涉及版本选择、架构匹配、语言支持与合规激活等基础技术问题。其核心原理基于微软官方Office Deployment Tool(ODT)的声明式XML配置机制,通过标准化流程确保安装可复现、可审计、无第三方捆绑。技术价值在于规避官网安装器的版本锁定、架构误配和语言缺失等常见风险,提升部署稳定性与安全性。典型应用场景包括企业批量部署、IT运维标准化、隐私敏感型用户自主安装。本文以Office Tool Plus为实践载体,深入解析ODT底层逻辑、XML配置规范

1188

即梦(Dreamina)技术浅析(六):多模态生成模型

多模态生成模型的目标是结合不同模态的数据(如文本和图像),生成新的视觉内容。其核心思想是利用文本描述引导图像或视频的生成过程,使得生成结果能够准确反映用户的意图。

m0_75253143的博客 1337

.Net读取xlsx文件Excel2007 .Net读取xlsx文件Excel2007

简单得很,利用ADO.NET,就像操作数据库一样,“insert into [Sheet1$] values(..,...,...)” excel2007的链接字符串这样写:"provider=microsoft.ace.oledb.12.0;data source=" + @文件路径 + ";extended properties=\"excel 12.0\...

weixin_30596165的博客 253

Dify 第 10 篇 Dify 知识库手把手案例

本文介绍了如何利用Dify平台构建《阿里巴巴Java开发手册》智能助手。首先详细讲解了知识库创建的完整流程,包括文档上传、分段设置(推荐父子分段+段落上下文)、索引方式选择(高质量+混合检索)等关键步骤。随后指导用户进行分段质量检查和召回测试,强调TopK和Score参数的调优策略。接着演示了Chatflow应用开发过程,通过知识检索节点和LLM节点的配置,实现从知识库智能获取答案的功能。最后展示了应用发布和实际使用效果,成功实现了基于知识库的问答交互。案例采用DeepSeek-R1大模型,并支持答案引用显

甘蓝的专栏 1703

.Net读取xlsx文件

连接 Excel 表:    string sqlconnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\\Book\\Book.xls;Extended Properties=Excel 8.0";       (1)Excel 连接字符串:     通过OleDb方式读取Excel文件时常常出现读取某些字段为null值,

编程技术交流/记录/分享/资源共享 2005

【YOLO26科研级突破】集成BiFPN双向特征金字塔,让多尺度特征融合效率与精度双跃升

打开确保模型解析器能识别BiFPN模块。通过将BiFPN双向特征金字塔集成到YOLO26中,我们实现了一个“全尺度双向特征流动+加权融合+精准检测”的目标检测模型。这个改进不仅在工程上能大幅提升多尺度、复杂场景下的检测精度,更在科研上提供了“双向特征融合”的创新思路——这种思路可以延伸到其他检测网络(如Faster R-CNN、SSD)的Neck模块改进中,帮你在论文中打造独特的研究点。

LXY_LOVE36的博客 200

基于 STM32 的校园电动车充电桩智能计费与过载保护系统设计与实现

本系统基于 STM32F103 主控,通过 HLW8032 电能计量芯片实现精准计费,配合继电器实现过载保护,RC522 模块完成刷卡身份识别,整体方案成本低、可靠性高,适合校园电动车集中充电场景的批量部署。软件采用状态机设计,逻辑清晰,可扩展多路充电口、远程监控等功能。

weixin_42300449的博客 58

Reading and writing to Excel 2007 or Excel 2010 from C#

转载自: http://www.sadev.co.za/content/reading-and-writing-to-excel-2007-or-excel-2010-using-c-part-i-primer-1   Over the past week I have been learning about the complexity of working with Excel 200

mrliming的专栏 759

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

C# 讀取Excel、xlsx文件Excel2007

转载自:http://blog.csdn.net/rocky69/article/details/7259697 NET 讀取Excel 2007的xlsx文件和讀取老的.xls文件是一樣的,都是用Oledb讀取,僅僅連接字符串不同而已。讀取xlsx 用的是Microsoft.Ace.OleDb.12.0;具體操作方法如下: public static DataTable GetExcelTo...

weixin_34291004的博客 192

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

C#读取和操作EXCEL

Data Source=" + 包括路径的文件名 + @";HDR=YES""";Data Source=" + 包括路径的文件名 + @";HDR=YES"";c)dr并不会遇到空行认为文件结束(即使空行后再无有内容的行),因而需做判断,使其到达空行后停止读取,而不是单独使用dr.read()的返回值判断;1、使用.NET读取EXCEL文件效率最高的方法是将EXCEL视为OLEDB数据源,进行数据连接,使用SQL语句读取;

hohoyu的专栏 889

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

iss版本服务器读取_服务器发布IIS之后,.Net 程序读取不到Excel内容

usingSystem.Collections.Generic;usingSystem.Data;usingSystem.IO;usingSystem.Linq;usingNPOI.HSSF.UserModel;usingNPOI.SS.UserModel;usingNPOI.XSSF.UserModel;public classExcelHelper{public classx2003{#reg...

weixin_39808953的博客 223

.net读取excel

Excel分类: •.xls格式 Office2003及以下版本•.xlsx格式   Office2007 及以上版本•.csv格式 以逗号分隔的字符串文本(可以将上述两种文件类型另存为此格式)   读取前两种格式和读取后一种格式会用两种不同的方法。 下面看程序:页面前台:<div> <%-- 文件上传控件 用于将要读取的文件上传 ...

weixin_30477797的博客 126
上一篇: javascript下拉列表框取值
下一篇: 如何用SQL语句查询Excel数据?
Mevin
博客等级 码龄18年 27粉丝 3原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值