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.

无忧云:服务器100G高防云服务器,bgpBGP云,洛阳BGP云服务器2核2G仅38.4元/月起

无忧云怎么样?无忧云值不值得购买?无忧云,无忧云是一家成立于2017年的老牌商家旗下的服务器销售品牌,现由深圳市云上无忧网络科技有限公司运营,是正规持证IDC/ISP/IRCS商家,主要销售国内、中国香港、国外服务器产品,线路有腾讯云国外线路、自营香港CN2线路等,都是中国大陆直连线路,非常适合免备案建站业务需求和各种负载较高的项目,同时国内服务器也有多个BGP以及高防节点。目前,四川雅安机房,4...

AkkoCloud(60元/月 ),英国伦敦CN2 1核 768 MB 内存 10 GB SSD 硬盘 600GB 流量 英国伦敦CN2 1核  1.5G  300Mbps

官方网站:https://www.akkocloud.com/AkkoCloud新品英国伦敦CN2 GIA已上线三网回程CN2 GIA 国内速度优秀.电信去程CN2 GIALooking Glass:http://lonlg.akkocloud.com/Speedtest:http://lonlg.akkocloud.com/speedtest/新品上线刚好碰上国庆节 特此放上国庆专属九折循环优惠...

提速啦(900元/月),杭州BGP E5-2665/89*2 32核 48G 100G防御

提速啦的来历提速啦是 网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑提速啦的市场定位提速啦主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。提速啦的售后保证提速啦退款 通过于合作商的友好协商,云服务器提供3天内全额退款,超过3天不退款 物理机部分支持当天全额退款提速啦提现 充...

vb net 教程为你推荐
天天酷跑刷积分教程最近一直有人说天天酷跑刷积分,怎么刷的。eset最新用户名密码eset smart security3.0.621.0最新用户名和密码怎么找公章制作word里如何制作公章?网站联盟百度网盟是什么,怎么加入iphone越狱后怎么恢复已经越狱的iphone怎么恢复到原来的系统bt封杀北京禁用BT下载,是真的吗?为什么?商标注册查询官网全国商标注册查询在哪里查呀?机械键盘轴机械键盘的轴哪种好?如何快速收录如何让百度快速收录宽带接入服务器网络已连接,可无法连接到服务器为什么?网络已连接,可无法连接到服务
最新代理服务器 域名查询软件 美国主机评测 香港加速器 wavecom Hello图床 表格样式 ev证书 太原联通测速平台 me空间社区 vip购优惠 安徽双线服务器 域名与空间 宏讯 网购分享 godaddy空间 葫芦机 hdsky 石家庄服务器 塔式服务器 更多