http://www.tutorialspoint.com/vb.net/vb.net_excel_sheet.htm

vb net 教程  时间:2021-02-22  阅读:()
Copyrighttutorialspoint.
comVB.
NET-EXCELSHEETVB.
NET-EXCELSHEETVB.
NetprovidessupportforinteroperabilitybetweentheCOMobjectmodelofMicrosoftExcel2010andyourapplication.
Toavailthisinteroperabilityinyourapplication,youneedtoimportthenamespaceMicrosoft.
Office.
Interop.
ExcelinyourWindowsFormApplication.
CreatinganExcelApplicationfromVB.
NetLet'sstartwithcreatingaWindowFormsApplicationbyfollowingthefollowingstepsinMicrosoftVisualStudio:File->NewProject->WindowsFormsApplicationsFinally,selectOK,MicrosoftVisualStudiocreatesyourprojectanddisplaysfollowingForm1.
InsertaButtoncontrolButton1intheform.
AddareferencetoMicrosoftExcelObjectLibrarytoyourproject.
Todothis:SelectAddReferencefromtheProjectMenu.
OntheCOMtab,locateMicrosoftExcelObjectLibraryandthenclickSelect.
ClickOK.
DoubleclickthecodewindowandpopulatetheClickeventofButton1,asshownbelow.
'AddthefollowingcodesnippetontopofForm1.
vbImportsExcel=Microsoft.
Office.
Interop.
ExcelPublicClassForm1PrivateSubButton1_Click(senderAsObject,eAsEventArgs)HandlesButton1.
ClickDimappXLAsExcel.
ApplicationDimwbXlAsExcel.
WorkbookDimshXLAsExcel.
WorksheetDimraXLAsExcel.
Range'StartExcelandgetApplicationobject.
appXL=CreateObject("Excel.
Application")appXL.
Visible=True'Addanewworkbook.
wbXl=appXL.
Workbooks.
AddshXL=wbXl.
ActiveSheet'Addtableheadersgoingcellbycell.
shXL.
Cells(1,1).
Value="FirstName"shXL.
Cells(1,2).
Value="LastName"shXL.
Cells(1,3).
Value="FullName"shXL.
Cells(1,4).
Value="Specialization"'FormatA1:D1asbold,verticalalignment=center.
WithshXL.
Range("A1","D1").
Font.
Bold=True.
VerticalAlignment=Excel.
XlVAlign.
xlVAlignCenterEndWith'Createanarraytosetmultiplevaluesatonce.
Dimstudents(5,2)AsStringstudents(0,0)="Zara"students(0,1)="Ali"students(1,0)="Nuha"students(1,1)="Ali"students(2,0)="Arilia"students(2,1)="RamKumar"students(3,0)="Rita"students(3,1)="Jones"students(4,0)="Umme"students(4,1)="Ayman"'FillA2:B6withanarrayofvalues(FirstandLastNames).
shXL.
Range("A2","B6").
Value=students'FillC2:C6witharelativeformula(=A2&""&B2).
raXL=shXL.
Range("C2","C6")raXL.
Formula="=A2B2"'FillD2:D6values.
WithshXL.
Cells(2,4).
Value="Biology".
Cells(3,4).
Value="Mathmematics".
Cells(4,4).
Value="Physics".
Cells(5,4).
Value="Mathmematics".
Cells(6,4).
Value="Arabic"EndWith'AutoFitcolumnsA:D.
raXL=shXL.
Range("A1","D1")raXL.
EntireColumn.
AutoFit()'MakesureExcelisvisibleandgivetheusercontrol'ofExcel'slifetime.
appXL.
Visible=TrueappXL.
UserControl=True'Releaseobjectreferences.
raXL=NothingshXL=NothingwbXl=NothingappXL.
Quit()appXL=NothingExitSubErr_Handler:MsgBox(Err.
Description,vbCritical,"Error:"&Err.
Number)EndSubEndClassWhentheabovecodeisexecutedandrunusingStartbuttonavailableattheMicrosoftVisualStudiotoolbar,itwillshowthefollowingwindow:ClickingontheButtonwoulddisplaythefollowingexcelsheet.
Youwillbeaskedtosavetheworkbook.

CheapWindowsVPS:7个机房可选全场5折,1Gbps不限流量每月4.5美元

CheapWindowsVPS是一家成立于2007年的老牌国外主机商,顾名思义,一个提供便宜的Windows系统VPS主机(同样也支持安装Linux系列的哈)的商家,可选数据中心包括美国洛杉矶、达拉斯、芝加哥、纽约、英国伦敦、法国、新加坡等等,目前商家针对VPS主机推出5折优惠码,优惠后最低4GB内存套餐月付仅4.5美元。下面列出几款VPS主机配置信息。CPU:2cores内存:4GB硬盘:60G...

日本vps云服务器选择指南。

日本vps云服务器怎么选择?很多人都会遇到日本vps和日本云服务器怎么选择的问题,日本云服务器具有免备案的特点。小编今天就分析一下日本云服务器价格多少钱,以方便大家选购的时候有个更加合适的取舍。日本云服务器租用前比较选择,高性能、安全、高效、免备案日本云服务器是很关键的因素。那么,日本云服务器该怎么选择呢?日本作为我们的邻国,与其贸易、文化往来是比较多的。日本云服务器价格多少钱一年?一、日本·CN...

柚子互联(34元),湖北十堰高防, 香港 1核1G 5M

柚子互联官网商家介绍柚子互联(www.19vps.cn)本次给大家带来了盛夏促销活动,本次推出的活动是湖北十堰高防产品,这次老板也人狠话不多丢了一个6.5折优惠券而且还是续费同价,稳撸。喜欢的朋友可以看看下面的活动详情介绍,自从站长这么久以来柚子互联从19年开始算是老商家了。六五折优惠码:6kfUGl07活动截止时间:2021年9月30日客服QQ:207781983本次仅推荐部分套餐,更多套餐可进...

vb net 教程为你推荐
可以发外链的论坛发外链的论坛哪个比较好,哪个论坛能发外链,能发广告急求。。。。博客外链外链都要怎么做?博客外链有没有效果?快速美白好方法有什么快速美白的好办法吗?申请证书申请毕业证书直播加速有没有软件使已经下载好了的视频播放加速,例如30分钟的视频15分钟或者20分钟播放完qq怎么发邮件qq怎么发文件和邮件qq怎么发邮件用QQ怎样发送文件怎么点亮qq空间图标如何点亮QQ空间图标xp系统停止服务Windowsxp系统为什么停止服务lockdowndios8.1怎么激活内置卡贴
山东vps 最新代理服务器ip x3220 美元争夺战 rak机房 Hello图床 万网优惠券 地址大全 web服务器架设软件 合肥鹏博士 韩国网名大全 bgp双线 域名接入 nerds t云 免费私人服务器 万网主机 镇江高防服务器 windowsserver2008r2 此网页包含的内容将不使用安全的https 更多