C# 操作Excel

【xlwings api语言参考】Range.CopyPicture 方法 功能: 将所选单元格区域作为图片复制到剪贴板。 语法: rng.CopyPicture (Appearance,Format) rng是一个表示 Range 对象的变量。 参数: 名称 必需/可选 数据类型 说明 Appearance 可选 XlPictureAppearance 指定图片的复制方式。 Format 可选 XlCopyPictureFormat 图片的格式。 XlPictureAppearance 枚举 (Excel) 指定图片的复制方式。 名称 值 说 阅读详情

合并单元格

Excel.Range rHA = worksheet.get_Range(rowAFrom,rowATo);

rHA.Merge(0); 


自动列宽

worksheet.Cells.EntireColumn.AutoFit();


设置字体

worksheet.Cells.Font.Name="Arial";
worksheet.Cells.Font.Size=10;
myExcel.Cells.Font.Bold = false;

对其方式

  _excelRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;//水平居中  
   _excelRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;//垂直居中


单元格边框

myExcel.Cells.Borders.LineStyle = 1;

保存和释放

//保存和退出
worksheet.SaveAs(strName,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing); 
myExcel.Quit();


//释放
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);

//杀死进程
System.Diagnostics.Process[] excelProc = System.Diagnostics.Process.GetProcessesByName("EXCEL");

//垃圾回收
GC.Collect ();

单元格的值可以通过代码加入公式

 mySheet.Cells[1,4]= ”IF(ISERROR(SUM(F{0},K{0})/D{0}*100),\"\",SUM(F{0},K{0})/D{0}*100)“;

拷贝内容到剪贴板

_excelRange.Copy(Type.Missing);
_excelRange.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
C#读写Excel文件(五) 下面Demo展示了将excel内容保存成图片, 使用名字空间: using MSExcel = Microsoft.Office.Interop.Excel; using Microsoft.Office.Core; using System.Runtime.InteropServices; using System.Drawing.Imaging; using System.Drawing;... 阅读详情

相关推荐

EXCEL VBA 导出高清图片方法

EXCEL VBA 导出高清图片方法 将EXCEL表格内容另存为图片的方法有很多种,简单的比如“复制为图片格式并另存”,“打印成XPS”等等,本文着重的是利用VBA实现的方法。 该方法适合用于中大型图文表格输出为图片格式,方便传阅,在office2010及以上版本最为流畅。 具体看代码: Sub printA4() Dim rng As Range '定义截图范围变量 'm = 20...

nfser_burn7的专栏 1万+

【ArcGIS Pro二次开发】(51):Excel表格内容导出图片

这里的宽度和高度最后乘的那个系数其实我也不太明白为什么是1.3333,这是自己慢慢测试出来的,反正最后刚好可以截到边界,我就不深究了,有知道的望告知。首先要确定你的VS已经安装了【Interop.Microsoft.Office.Interop.Excel】。估计这会是一个相对通用的需要,于是就专业做了这样一个方法,也顺便水一篇。然后就是创建图片对象,然后保存到剪贴板,再粘贴保存。

规划GIS会 1756

C#操作Excel表

本文主要介绍一下c#来操作excel表格,主要介绍我使用的,我是使用第三方提供的函数库(NPOI)来进行excel的操作,而NPOI库函数在其官网下,我这里就不拿出来了。1:NPOI库函数NPOI库函数下载后,解压出来有一下几个DLL文件,我们就是通过这几个DLL库文件中提供的函数来操作2:介绍一下excel表格    2.1: excel表格有两种后缀名 .xls 和 ....

love_kevin的博客 3万+

C#控制台程序中使用剪贴板将Excel的单元格区域保存为图片

using System; using System.IO; using System.Windows; using System.Windows.Media.Imaging; using System.Drawing.Imaging; using Excel = Microsoft.Office.Interop.Excel; public class Program { [ST

kirawoo的专栏 3483

C#操作Excel文件~创建Excel文件

PanPen120出品,必是验证过,必是注释详细

Eden's space 8523

excel转图片

* 功能:将 excel的每个sheet页转换为图片 * 如果excel中有图片,那么会遇到Range.CopyPicture抛异常,请检查电脑是否启用了tfs_officeintegration: * 在excel中检查是否加载了该插件,文件->选项->加载项 的活动应用程序加载项中是否有Team Foundation Add-in * 如果没有,则在下方【管理】的下拉列表中选择【COM加载项】,点击【转到】,在 弹出对话框中选择“Team Foundation Add-in” * 如果没有该选项,那么 搜索tfs_officeintegration下载安装

C#编程学习27: C#操作Excel从入门到精通

C#操作EXCEL的基本操作和海量数据导出优秀代码集锦

m1m2m3mmm的博客 3万+

Windows下Python多版本共存与切换的终极指南(含环境变量详解)

本文详细解析了在Windows系统下实现Python多版本共存与切换的完整方案。通过深入讲解环境变量Path的底层机制,提供了从安装策略、精细化Path管理到创建快速切换脚本的实战指南,并介绍了py启动器和虚拟环境等高级技巧,帮助开发者彻底解决版本冲突问题,提升开发效率。

v6b7n8m9q0的博客 538

C# 操作EXCEL的方法

C#中要操作EXCEL 可以通过.NET组件提供的功能 在visual studio中右键单击【解决方案】中的【引用】,添加一个引用【Microsoft.Office.Interop.Excel】 只要安装了EXCEL就有这个组件 EXCEL中索引是从1开始的!  object missing = Missing.Value; // 创建Excel对象 Microsoft.Offic

iloli的专栏 2377

《中国图书馆图书分类法》(第五版)详表(中图分类号查询表)

中文法分类

记录我目之所及的世界 4万+

CocosCreator3.8实战指南:动态字体与位图字体性能优化技巧

本文深入解析CocosCreator3.8中系统字体、动态字体(TTF)与位图字体(FNT)的核心差异与性能表现。针对动态字体运行时解析开销大、内存占用高的痛点,提供了字体子集化、共享资源等优化技巧;同时详细介绍了位图字体制作流程及其在渲染速度、内存可控性上的绝对优势,并给出跨平台场景下的字体选型与优化策略,帮助开发者有效提升游戏性能。

weixin_29006701的博客 563

C#操作excel

很久之前,就像搞懂C#如何操作Excel文件,可是每次写测试程序的时候都遇到些问题,今天反复搜索终于基本解决了这个问题。以下是一段测试代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Te

Welcome to My Zone 1236

[QMT量化交易小白入门]-二、如何用miniQMT获取沪深A股的板块列表、历史行情数据和实时行情数据

本专栏主要是介绍QMT的基础用法,常见函数,写策略的方法,也会分享一些量化交易的思路,大概会写100篇左右。QMT的相关资料较少,在使用过程中不断的摸索,遇到了一些问题,记录下来和大家一起沟通,共同进步,自己淋过雨了,希望大家都有一把伞。

木头大左的博客 5659

C#操作EXCEL

C#里高效率操作EXCEL请参考:http://blog.csdn.net/linaren/archive/2009/10/28/4736637.aspx 下面代码是几年前初做项目写的代码,没加整理,仅供基础参考呵呵using System;using System.IO;using System.Reflection;using System.Collections ;using

1万+

Open3D(C++) 读取、可视化并保存点云【2025最新版】

博客长期更新,本文最近更新时间为:2025年1月6日。

点云侠的博客 4620

华为OD机试 - 物流仓储多维度成本利润综合查询系统 - 二维数组(Python/JS/C/C++ 新系统 100分)

本专栏收录于《华为OD机试真题(Python/JS/C/C++)》。刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、3个测试用例、为什么这道题采用XX算法、XX算法的适用场景,发现新题目,随时更新。某物流企业在全国多个仓库开展仓储业务,需要对不同仓库、不同时段的入库成本、出库收入和库存损耗进行综合统计分析,用于生成 日报、周报和月报。字段说明及取值范围如下:warehouses: int[] 扁平化数组 [w0d0in, w0d0out,

学Java,找哪吒 309

C#—Excel 操作

参考: https://blog.csdn.net/kevinfan2011/article/details/83958602 https://blog.csdn.net/sanjiawan/article/details/6818921 https://blog.csdn.net/fengxing11/article/details/52859894

硬核小青年的博客 1564

【GlobalMapper精品教程】006:Excel表格(.xls)或文本(.txt .csv)坐标文件生成矢量点

原始的坐标数据如下图所示,其中坐标为Lat经度,LNG纬度,均为十进制度的形式,一般软件都支持十进制度的格式,如果不支持,你可以尝试使用度分秒的形式,图中的DDMMSS-LAT为纬度,DDMMSS-LNG为经度。打开globalmapper软件,点击【打开数据文件】,选择坐标数据文件(案例中的数据位配套实验数据包中的data006.rar)气象台站分布点坐标.xls。选择坐标系:本案例数据采用的是经纬度,因此选择Geographic(Latitude/Longitude),基准选择WGS84,点击确定。

智慧空间实验室 2570

C#操作Excel总结(最全面的操作EXCEL技巧汇总)

0.导入命名空间: 1 2 3 4 usingMicrosoft.Office.Core; usingMicrosoft.Office.Interop.Excel; usingSystem.IO; usingSystem.Reflection; 1.如何打开已有excel文档,或者创建一个新的excel文档 1 2 3 Application...

weiweicuit1224的博客 1万+

【C语言】一文搞懂C语言文件操作

读写文件、文件相关库函数详解、文件缓冲区介绍

StackFrame 5661

深度学习工具包 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的互操作

通过C#代码对Excel进行操作,完成excel 工作簿(WorkBook)的新建,保存。style.NumberFormatLocal = "[DBNum2][$-804]G/通用格式";必须安装Office中的Excel,因本质是调用Excel应用完成任务,若无该Excel应用该系列操作将无法完成!调用Microsoft.Office.Interop.Excel,借助COM组件,与Excel进行互操作。range.NumberFormatLocal = "G/通用格式";

lingxiao16888的博客 1861

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

C#操作Excel总结

0. 导入命名空间:  using Microsoft.Office.Core; using Microsoft.Office.Interop.Excel; using System.IO; using System.Reflection;   1. 如何打开已有excel文档,或者创建一个新的excel文档    Application app = new Applicati...

weixin_34144450的博客 1577

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

C#操作Excel

有时,需要将软件中计算获得的数据导出保存到Excel,并支持将Excel中的数据导入到软件中,所以会利用C#操作Excel非常必要。 一、添加引用        要想用C#操作Excel,首先需要保证导入了Excel类库,具体操作如下:        解决方案选项卡下-->项目节点上右键-->添加引用-->.NET选项卡-->选择Microsoft.Office.Interop.Excel-

SunCherryDream的专栏 1472

C#操作Excel初探

                                                                                    C#操作Excel初探    最近一段时间正好在做winform导出Excel报表的问题,学习了一下C#操作Excel的一些方法(如:向Excel中插入图片;删除Excel指定sheet中的某行或某列,在Excel指定的单元格中画线

Begin Again!~~~ 2749

C#对Excel文件的操作

C#对Excel文件的操作

qq_56650103的博客 1425
上一篇: 注册表键值快速定位
下一篇: DataList的用法
eecool
博客等级 码龄18年 1粉丝 20原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值