vb.net 教程 10-2 Excel操作5 单元格的高、宽和颜色

vb.net与excle表格操作 自己从网上整理的vb.net与excle表格操作 并且应用在项目上,对新手有帮助 立即下载

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。

调整某一列的宽度:Worksheet.Columns(要调整的列数).ColumnWidth
调整某一行的高度:Worksheet.Rows(要调整的行数).rowHeight
调整单元格的颜色:Worksheet.Cells(行号,列号).Interior.Color

这里有个具体的示例,以前发过的《Excel做图像》,这里把具体代码列出来:

设计界面:

载入按下:

    Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
        Dim filename As String
        If ofdImg.ShowDialog = DialogResult.OK Then
            filename = ofdImg.FileName
        Else
            Exit Sub
        End If
        pbShow.Image = Image.FromFile(filename)
    End Sub

输出按下:

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Dim timestart, timeend As DateTime
        timestart = Now()

        Dim pImageWidth, pImageHeight As Integer
        pImageWidth = 300
        pImageHeight = 200

        Dim pImage As New Bitmap(pImageWidth, pImageHeight)
        Dim g As Graphics = Graphics.FromImage(pImage)
        g.DrawImage(pbShow.Image, New Rectangle(0, 0, pImageWidth, pImageHeight))
        g.Dispose()

        Dim xls As New Excel.Application
        Dim Wbook As Excel.Workbook
        Wbook = xls.Workbooks.Add()

        Dim Wsheet As Excel.Worksheet
        Wsheet = Wbook.Worksheets.Add()
        Wsheet.Name = "图画"

        Dim picW, picH As Integer
        picW = pImage.Width
        picH = pImage.Height

        For i As Integer = 1 To picW
            Wsheet.Columns(i).ColumnWidth = 0.2
        Next

        For j As Integer = 1 To picH
            Wsheet.Rows(j).rowHeight = 2
        Next

        Dim picColor As Color

        For k As Integer = 0 To picW - 1
            For l As Integer = 0 To picH - 1
                picColor = pImage.GetPixel(k, l)
                Wsheet.Cells(l + 1, k + 1).Interior.Color = RGB(picColor.R, picColor.G, picColor.B)
            Next
        Next

        Wbook.SaveAs("d:\aa.xls")
        xls.Quit()

        timeend = Now()
        MessageBox.Show("转换完毕。" & ControlChars.CrLf & "图片大小:" & pImage.Width & "*" & pImage.Height & ControlChars.CrLf & "转换耗时:" & (timeend - timestart).TotalSeconds)
    End Sub

最后的效果:

就是需要的时间太长了:

不知道可以用来做十字绣的底稿不。。。呵呵呵呵

 

由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看vb.net 教程 目录

vb.net表单设计 vb.net写的表单 看代码 改连库代码 就可使用 立即下载

相关推荐

用vb语言输出excel并设置自动调整各列宽度

用vb语言输出excel并设置自动调整各列宽度

vb.net设置单元格的颜色

一学就用!最近为硬件部搞测试软件,用VB.NET,需要把测试结果保存到excel文档。 其中某个功能是EXCEL 的单元格需要设置颜色。         Dim oExcel As New Microsoft.Office.Interop.Excel.Application         Dim obook As Microsoft.Office.Interop.Excel.Workboo

一天到晚游泳的鱼 8192

VB调用Excel设置居中、自动调整列宽和合并单元格

这是我自己编写的,绝对能用,可以使Excel表格自动设置居中、自动调整列宽和合并单元格,根据自己需求稍修改下,需要的朋友可以用下

VB.net调用Excel怎样设定列的列宽?

见标题,我在Excel宏里看到VBA是这么写的:Columns(A:A).ColumnWidth = 22.25可是在VB.net里引用(WorkSheet).Columns(A:A)返回的是一个object类型,没法使用它的列宽属性,该怎么做呢? 强制的类型转换一下就可以了,就算是不转换 其实也是可以写的, CType(objtargetcol, Excel.Range).ColumnWid...

weixin_30572613的博客 710

大数据之父_BIM先驱Charles (Chuck) M. Eastman逝世——致敬“BIM之父”

原标题:BIM先驱Charles (Chuck) M. Eastman逝世——致敬“BIM之父”BIM研究的先驱、佐治亚理工教授Charles (Chuck) M. Eastman于本周一(11月9日)在其Atlanta家中逝世。特转韩国Yonsei大学Ghang Lee教授的讣文以作纪念。过世原因未说明。BIM的出现是与当今时代科技的发展分不开的。在信息时代建筑发展面临的挑战巨大:建筑物越建越高...

weixin_39941262的博客 3307

导数在工程与AI中的12个实战应用解析

导数作为数学中的基本概念,本质是描述变化率的工具,其核心价值在于将非线性问题局部线性化处理。从原理上看,通过极限过程捕捉函数瞬时变化特性,使工程师能精确控制系统动态行为,帮助科学家量化自然规律变化速率。在技术实现层面,现代符号计算(如Mathematica)、数值计算(如MATLAB)和自动微分(如PyTorch)工具链的发展,大幅提升了导数计算的效率与精度。典型应用场景涵盖机械控制(如ABS防抱死系统)、金融工程(如期权希腊值计算)、医疗影像(如Canny边缘检测)等领域。特别在机器学习中,反向传播算法依

weixin_35509395的博客 324

Office(Excel、PPT、Word) VBA(宏)常用代码

Excel合并单元格的自动调整行高当有合并单元格的时候,自动调整行高失效,这时可用如下代码:Sub My_MergeCell_AutoHeight() Dim rh As Single, mw As Single Dim rng As Range, rrng As Range, n1%, n2% Dim aw As Single, rh1 As Single Dim...

Circle-C的博客 2万+

数学概念 | 旋转矩阵、欧拉角、四元数

旋转矩阵、欧拉角、四元数概念及相关运算;

NapoleonCoder的博客 774

Excel行高与像素值,列宽与像素值之间的转换,绘制Excel像素画。

private static float GetDpiX() { try { using (Bitmap image = new Bitmap(1, 1)) { using (Graphics graphics = Graphics.FromImage(image)) { ...

chenxiaotao22的专栏 5507

Android音频学习(一)——音频基础

在系统的学习Android音频之前,先了解音频的基础知识。

miemie2014的博客 1487

KVM — 与 QEMU 和 Libvirt 的关系

目录目录 前言 KVM QEMU KVM 与 QEMU qemu-kvm Libvirt Libvirt 在 OpenStack 中的应用前言如果是刚开始接触虚拟机技术的话, 对上述的概念肯定会有所混淆, 傻傻的分不清. 尤其在看虚拟化技术文档时导致理解能力下降, 所以在开始学习虚拟化技术之前对这些概念有一个整体的认识和清晰的理解, 就显得很有必要了.KVMKVM(Kernel-basedVirtu

烟云的计算 5743

VB.NET—DataGridView控件教程详解

DataGridView是.NET FormK中的一个Windows窗体控件,它提供了一个可视化的表格控件,允许用户以表格形式显示和编辑数据。它通常用于显示和编辑数据库中的数据,也可以用于显示和编辑其他数据的数据。DataGridView控件可以显示单行和多行数据,并允许用户对数据进行排序、过滤和编辑。用户可以使用鼠标和键盘对表格进行导航和编辑,也可以使用代码对表格进行编程控制DataGridView控件提供了许多自定义选项和事件,使开发人员能够轻松地实现自定义表格行为和外观。

weixin_59272777的博客 6747

SAP Joule for Developers 全景解析:从 ABAP 到 SAP Build 的一体化开发者 AI 能力

SAP Joule for Developers是一套内嵌于SAP开发工具的设计时AI能力,专为提升SAP开发者效率而设计。它支持自然语言生成应用与自动化流程,帮助理解优化代码,并嵌入单元测试和质量保障功能。Joule深度集成ABAP开发环境,同时服务于Java、JavaScript和低代码开发,覆盖CAP数据模型、UI5/Fiori生成、ABAP代码补全与重构等场景。通过斜杠命令和上下文操作,开发者可在不改变现有平台的前提下,显著提升开发效率和质量。典型案例包括快速构建CAP应用和ABAP Cloud迁移

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 505

【vba】【excel】 设置行高和列宽

主要关键字, RowHeight 和 ColumnWidth。

weixin_61256014的博客 2152

弱小目标检测跟踪算法研究(5) 基于顶帽变换(Top_hat)算法的红外弱小目标检测之背景抑制

基于顶帽变换(Top_hat)算法的红外弱小目标检测之背景抑制1. 前言2. 顶帽变换(Top_hat)算法3. Matlab仿真4. 小结 1. 前言 红外图像中的弱小目标,目标属性包涵“弱"和“小’’两个方面:“弱’’是指目标在红外波长上所表现出来的强度,具体反映到所拍摄的红外图像上,就是指目标的灰度值;而“小’’是指目标的尺寸大小,也就是前面所述的成像面积很小,反映到红外图像上就是指目标所占的像素数目很少。 SPIE国际光学工程学会(Societyof Photo一0ptical Instrument

sinat_34897952的博客 5296

深度拆解 ‘High-Frequency Trading’ (HFT) 系统:解析如何在 100 纳秒内完成从网卡到 C++ 策略的响应

在100纳秒内完成从网卡到C++策略的响应,这是一项对技术栈每一个层面都进行极限优化的系统工程。它要求我们深入理解计算机体系结构、操作系统、网络协议和C++语言的底层机制。从物理距离的极致缩短,到高性能网卡和内核旁路技术,再到C++代码中每一个字节、每一个CPU周期的精打细算,HFT系统展现了人类对计算速度的永恒追求。这项技术不仅仅应用于金融交易,其背后的低延迟理念和实现方法,如DPDK、无锁编程、硬件加速等,正在逐渐渗透到其他对延迟敏感的领域,例如电信网络、边缘计算和工业自动化。

weixin_41455464的博客 1044

VB.net小技巧——使用DataGridView显示EXECL表格内容

VB.net小技巧——使用DataGridView显示EXECL表格内容 直接上代码 Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click Dim fileDialog As OpenFileDialog = New OpenFileDialog() fileDialog.InitialDirectory

gzy0506的博客 8595

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

vb.net 教程 10-2 Excel操作4 比较完整的工作表操作

版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。 前面几篇教程已经讲述了如何载入excel工作表中的数据,本节内容将讲述如何实现工作表数据的增、改、删,并实现对工作表操作比较完整的代码。 数据的增加和删除都可以使用 sheet.Cells(Row, Column).Value = 值 来实现。 数据的删除可以使用 Wsheet.Rows...

学习微软 .net 技术开发 3034

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

vbs设置Excel表格格式

Set ExcelApp = CreateObject("Excel.Application")    Set ExcelBook = ExcelApp.Workbooks.Open (filepath) '指定sheet Set ExcelSheet = ExcelApp.Sheets.Item(1)    With ExcelSheet               

shililu的专栏 2951

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

如何通过VB合并Excel单元格以及设置Excel行高?VB创建Excel表格,合并单元格,生成图形等操作

如何通过VB合并Excel单元格以及设置Excel行高? 例如:我想把第一列的第4,5,6,7行合并。。。我在怎样让合并单元格里的字居中,怎样改变字体。 请不吝赐教。。。 ========================================================== 首先在VB中引用microsoft excel object library 假设c盘根目录下...

hljqfl的专栏 5785
上一篇: vb.net 教程 10-5 拓展:ppt转换
下一篇: vb.net 教程 3-10 窗体编程 datagridview控件 1 初步
.Net学习
博客等级 码龄21年 5551粉丝 992原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

.Net学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值