C#访问Excel操作

C#技巧【调用线程无法访问此对象,因为另一个线程拥有该对象的问题的解决办法】【C#读写EXCEL源码提示“office检测到此文件存在一个问题。为帮助保护您的计算机,不能打开此文件”的解决】 SYD8801是一款低功耗高性能蓝牙低功耗SOC,集成了高性能2.4GHz射频收发机、32位ARM Cortex-M0处理器、128kB Flash存储器、以及丰富的数字接口。SYD8801片上集成了Balun无需阻抗匹配网络、高效率DCDC降压转换器,适合用于可穿戴、物联网设备等。具体可咨询:http://www.sydtek.com/ 调用线程无法访问此对象,因为另一个线程拥有该对象的问题的... 阅读详情

/*-----------------------------------------------------------------------------*/
Author:RXW
Date:2004-12-10
/*-----------------------------------------------------------------------------*/

using System;
using System.Reflection;
using Excel;

namespace ExcelCommon
{
 /// <summary>
 /// EXCEL 读取操作
 /// </summary>
 public class XlsRead
 {
  public XlsRead()
  {
   //
   //
   //
  }

  /// <summary>
  /// Open Excel File
  /// </summary>
  /// <param name="XlsFileName">Full Path Name</param>
  public void Open(string XlsFileName)
  {
   if(string.Empty == XlsFileName)return;
   m_ExApp = new ApplicationClass();
   m_ExApp.Visible = false;
   m_ExApp.ScreenUpdating = false;
   object [] vData = new object[]{0,true,null,null,null,null,null};
   Workbooks wbs=m_ExApp.Workbooks;
   m_WorkBook = (Workbook)wbs.GetType().InvokeMember(
    "open",System.Reflection.BindingFlags.InvokeMethod,
    null,wbs,new object []{XlsFileName,vData});
  }
  /// <summary>
  /// Release COM
  /// </summary>
  public void Dispose()
  {
   if(null != m_ExApp)
   {
    m_ExApp.Quit();
    m_ExApp = null;
   }
  }

  private ApplicationClass m_ExApp = null;

  /// <summary>
  /// Excel File
  /// </summary>
  public string XlsFile
  {
   get
   {
    return m_XlsFile;
   }
   set
   {
    m_XlsFile=value;
   }
  }

  private string m_XlsFile=string.Empty;

  public void Open()
  {
   Open(XlsFile);
  }

  private Workbook m_WorkBook=null;


  /// <summary>
  /// Find Data Cell By Position Info
  /// </summary>
  /// <param name="XlsTableName">Worksheet(Table) Name</param>
  /// <param name="FindWhat">KeyWords</param>
  /// <param name="FullText">String of Data Content</param>
  /// <param name="PosX">Row Index</param>
  /// <param name="PosY">Column Index</param>
  /// <returns></returns>
  public bool FindCell(string XlsTableName,string FindWhat,ref string FullText,ref int PosX,ref int PosY)
  {
   if(string.Empty == FindWhat)return false;
   if(null == m_WorkBook)return false;
   foreach(Worksheet sht in m_WorkBook.Worksheets)
   {
    if(XlsTableName == sht.Name)
    {
     object [] vData = new object[]{FindWhat,null,XlFindLookIn.xlValues,XlLookAt.xlPart};
     Range rg = sht.UsedRange;
     Range _rg =(Range)rg.GetType().InvokeMember(
      "find",System.Reflection.BindingFlags.InvokeMethod,
      null,rg,new object[]{vData});
     if(null != _rg)
     {
      PosX = _rg.Row;
      PosY = _rg.Column;
      FullText = _rg.Text.ToString();
     }
     return true;
    }
   }
   return false;
  }

 }
}

C#进阶-OleDb操作Excel和数据库 在C#编程中,使用OleDb可以方便地实现对Excel文件和数据库的操作。本文探讨了在C#中使用OleDb技术操作Excel和数据库的策略。文章详述了OleDb的定义、配置环境的步骤,并通过实际代码示例演示了如何高效读写Excel文件和交互数据库。文中还评估了OleDb技术的优缺点,为需要处理多种数据源的开发者提供了一种有效的数据操作方案。 阅读详情

相关推荐

电路板功能测试系统-FCT for PCBA

电路板功能测试系统用于电路板组件(PCBA)的功能测试(FCT),满足自动化大批量生产的要求。  ● 用户根据自己需要定义测试步骤,灵活方便  ● 适合工业自动化大批量生产应用  ● 系统测试精度高,稳定可靠   一、电路板功能测试系统概述 电路板测试过程通常由多个步骤组成,每单个步骤中需要对多个物理量(电压、电流、电阻、频率、波形等)进行测试。在每个步骤测试时

6813

C#操作Excel(创建、打开、读写、保存)几种方法的总结

在.NET开发中,不管是web程序还是桌面软件(尤其是涉及数据库操作的MIS系统等),常常需操作Excel,如导出数据到Excel,读取Excel中数据到程序中等。总结起来,其操作不外乎创建、打开、读写、保存(后退出/释放),而其操作方法,则主要有:通过ADO.NET数据连接方式、通过Excel对象模型“自动化”操作、使用中间数据格式如文本文件,XML等间接操作Excel、使用第三方控件(主要用于

.Net freamwork 阶梯(Joy) 1717

Floyd算法在社交网络中的应用:如何找到六度人脉的最短路径?

本文探讨了Floyd算法在社交网络分析中的核心应用,特别是如何利用该算法高效计算任意两人之间的最短路径,从而量化“六度人脉”理论。文章通过构建微型社交网络模型,详细拆解了Floyd算法的动态规划原理与代码实现,并展示了如何从计算出的最短路径距离矩阵中挖掘节点中心性、识别社群等关键洞察,为社交推荐、影响力分析等场景提供技术支撑。

blockchain9miner的博客 1003

c#读取excel文件

原文地址:http://blog.youkuaiyun.com/dannywj1371/article/details/7447710 使用OLEDB可以对excel文件进行读取,我们只要把该excel文件作为数据源即可。 一 在D盘创建excel文件test.xls: 二 将工作表Sheet1的内容读取到DataSet string strConn = "Provider=Micro

755

Qt上位机实战:5步搞定STM32 IAP固件升级(附拖拽文件处理技巧)

本文详细介绍了如何使用Qt开发STM32 IAP固件升级上位机。通过五个核心步骤,包括理解IAP机制、搭建Qt环境、实现拖拽文件加载、封装串口通信以及设计可靠通信协议,帮助开发者快速构建一个稳定、易用且支持图形化操作的固件升级工具,显著提升嵌入式产品开发与维护效率。

ss78901的博客 1079

企业微信群机器人配置全攻略:从零到消息推送的完整流程

本文详细介绍了企业微信群机器人的配置与使用全流程,从零开始指导如何创建机器人、获取Webhook地址,到通过HTTP请求发送文本、Markdown、图片及模板卡片等多种消息类型。内容涵盖核心的接口配置、安全实践及实战应用场景,帮助开发与运维团队快速构建自动化消息推送中枢,提升协作效率。

weixin_29231725的博客 842

C#笔记——excel转pdf

nuget下载这个包 using Spire.Xls; //xlsx转pdf Workbook workbook = new Workbook(); workbook.LoadFromFile(fname); workbook.SaveToFile(fdate + ".pdf", FileFormat.PDF); 这个用的是相对路径,和可执行文件在同一文件夹下就无需路径,只输入文件名就可...

雪兰灵莹的小窝 1451

Benchmark系列——UnixBench测试项深度解析与性能优化指南

本文深度解析UnixBench基准测试套件的各项测试原理,包括Dhrystone、Whetstone、系统调用、进程管理、IPC及文件I/O等核心测试项。通过详细的测试项分析,指导用户解读测试报告,并提供针对性的内核参数调整、编译优化及系统配置实战指南,帮助用户精准定位并优化系统性能瓶颈。

weixin_29230901的博客 276

c#操作excel写入和读取

生活中我们或多或少要接触excel,那么怎样将excel集成到程序呢?下面我将做一个小demo来实现。 在c#中我们在Nuget包管理器中搜索NPOI,这是一个操作excel插件,它能够实现不需要借助office就可以生成excel文件,更轻便。 首先我们需要了解一下excel的一些细节, 1.workbook:代表excel的工作簿 2.sheet:代表excel的工作表,一个工作簿包含多个工作表。 3.Columns:代表excel表格的列 4...

浩瀚与渺小 2491

2025数学建模美赛C题完整建模思路——奥运会奖牌榜的模型

2025数学建模美赛C题完整建模思路——奥运会奖牌榜的模型

Yilu264的博客 1万+

YOLOv11【第六章:模型压缩与极致优化篇·第15节】YOLOv11 专用剪枝工具库使用指南!

🏆 本文收录于专栏 《YOLOv11实战:从入门到深度优化》。本专栏围绕 YOLOv11 的改进、训练、部署与工程优化 展开,系统梳理并复现当前主流的 YOLOv11 实战案例与优化方案,内容目前已覆盖 分类、检测、分割、追踪、关键点、OBB 检测 等多个方向。

**My Coding Family** 1312

C#实现excel 文件导出

实现方式:可以采用模板文件导出也可以采用代码生成文件, 将文件转化为字节流,然后用File()方法输出即可。

jjy17337774210的博客 2138

RK3588开发板NPU加速YOLO目标检测完整实战教程

🚀 RK3588开发板NPU加速YOLO目标检测实战 本文详细介绍了如何在瑞芯微RK3588开发板上利用内置NPU加速YOLO目标检测的全流程: 1️⃣ 环境准备:配置RKNPU2 SDK和aarch64交叉编译器,搭建Ubuntu开发环境 2️⃣ 模型转换:从ONNX格式转换为专用RKNN模型,适配NPU硬件特性 3️⃣ 性能对比:NPU推理将处理时间从833ms降至50ms以下,帧率提升16倍 4️⃣ 实战应用:支持图像/视频流/摄像头实时检测,提供完整编译和运行命令 关键优势:专为边缘AI设计的6T

FJN110的博客 931

excel range 判断日期型_C# Excel访问(Com操作)

最近用到了,共享下1:引用设置引用设置2:类内usingusing Excel = Microsoft.Office.Interop.Excel;//因为该命名空间内,有很多名称与Forms内的相同,为了区分3.最基本的访问代码using System; using System.Collections.Generic; using System.ComponentModel; using Sys...

weixin_42516119的博客 301

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

用C#生成Excel文件的方法,Excel.dll组件生成的方法和设置用ASP.NET操作访问权限

一个示例:class AppTest {  private Excel.ApplicationClass _x;  public static void Main0()  {   AppTest a = new AppTest();   a._x = new Excel.ApplicationClass();   a._x.UserControl = false;   for (int i = 0

wang8712的专栏 5397

深度学习工具包 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")

后台C#中操作Excel访问被拒

错误信息:检索 COM 类工厂中 CLSID 为{00024500-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误:80070005 拒绝访问。 (异常来自HRESULT:0x80070005 (E_ACCESSDENIED))。 解决方式:   1.输入命令mmc comexp.msc /32   2.依次双击【组件服务】-->【计算机】-...

weixin_30684743的博客 572

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

C#笔记17 DataTime类型、断言、internal关键字、GUID、Excel操作、正则表达式、访问剪贴板、设计模式、版本控制

在实践中学习。

记录学习痕迹的公众号:Piper蛋窝 599

C#以操作数据库方式访问EXCEL文件的几个常见问题及解决方法

除了像sql server,access常见的数据库,其实Excel文件也可以做为数据库访问。ado.net访问excel的实例:OleDbConnection cn = new OleDbConnection(); cn.ConnectionString = @"provider=Microsoft.jet.oledb.4.0;data source=[excel文件路径];Extended P...

weixin_30709809的博客 500

C#操作Excel,权限问题

当我们导出的Excel文件要求严格的格式时,就需要把Excle做成模板,在导出时首先复制原来做好的模板,然后在模板上操作Excel就会保留原来的格式,但是在C#操作文件时会遇到一些权限上的问题,我们这里以操作Excel为例说明一下: 首先配置DCOM:解决操作权限问题,具体步骤如下: 1:在服务器上安装office的Excel软件. 2:在"开始"->"运行"中输入dcomcnfg...

weixin_34162629的博客 105

C#如何在Form中嵌入并且操作Excel表格

 网上比较多讲述如何操作excel表的文章,但都是启动excel的窗口来打开excel数据文件。有时候需要把excel表嵌入到自己程序的form中,给客户一个不用切换窗口的操作界面,似乎更好。这在vc中用ole技术很容易实现,但是在c#中方法就不一样啦。下面将就此进行阐述。 一、首先简要回顾一下如何操作excel表  先要添加对Excel的引用。选择项目-〉添加引用-〉COM-〉添加Mic

肖大宝产品之路 580

C#对EXCEL的读写操作

using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;usi

swort_177的专栏 2712

c# 操作excel

查看文章     c# excel2008-03-12 11:14

szg3827的专栏 1620

C#.Net操作Excel

首先将excel.exe copy 到 ../Microsoft Visual Studio .NET 2003/SDK/v1.1/Bin目录下利用.net 中带的工具在命令提示符下执行tlbimp excel.exe.这样就不会因为你的Excel是xp或2000的不同要去找不同的*.olb文件,还有一点就是因为在2000以后的版本中没有了excel9.olb这个文件了。通过执行tlbimp ex

netjxz的专栏 1211

Oracle简单导出Excel

1.新建一个工程,需要添加引用Microsoft.Office.Interop.Excel.dll 2.usingSystem.Data;    usingSystem.Data.OleDb;

大猴子的专栏 854
上一篇: 网络验证码的生成
下一篇: VB代码片段
bytesoon
博客等级 码龄25年 3粉丝 5原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值