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.
Vinahost,这个主机商还是第一次介绍到,翻看商家的介绍信息,是一家成立于2008年的老牌越南主机商,业务涵盖网站设计、域名、SSL证书、电子邮箱、虚拟主机、越南VPS、云计算、越南服务器出租以及设备托管等,机房主要在越南胡志明市的Viettle和VNPT数据中心,其中VNPT数据中心对于国内是三网直连,速度优。类似很多海外主机商一样,希望拓展自己的业务,必须要降价优惠或者增加机房迎合需求用户...
妮妮云的知名度应该也不用多介绍了,妮妮云旗下的云产品提供商,相比起他家其他的产品,云产品还是非常良心的,经常出了一些优惠活动,前段时间的八折活动推出了很多优质产品,近期商家秒杀活动又上线了,秒杀产品比较全面,除了ECS和轻量云,还有一些免费空间、增值代购、云数据库等,如果你是刚入行安稳做站的朋友,可以先入手一个119/元季付的ECS来起步,非常稳定。官网地址:www.niniyun.com活动专区...
六一云互联六一云互联为西安六一网络科技有限公司的旗下产品。是一个正规持有IDC/ISP/CDN的国内公司,成立于2018年,主要销售海外高防高速大带宽云服务器/CDN,并以高质量.稳定性.售后相应快.支持退款等特点受很多用户的支持!近期公司也推出了很多给力的抽奖和折扣活动如:新用户免费抽奖,最大可获得500元,湖北新购六折续费八折折上折,全场八折等等最新活动:1.湖北100G高防:新购六折续费八折...
vb net 教程为你推荐
会声会影12下载哪里有会声会影12好看视频素材下载51自学网站谁能给我免费学习的网站吧 谢谢了打开网页出现错误网页上有错误怎么解决?godaddyGodaddy域名怎么接受创维云电视功能创维新出的4K超高清健康云电视有谁用过,功能效果怎么样?人人逛街人人逛街网是正品吗免费免费建站可以不用钱免费做一个网站吗ejb开发EJB是什么?电子商务网站模板我想开发一个电子商务网站,但是想加入自己设计的模板,可以吗?系统分析员系统分析员的工作内容
便宜vps 域名备案只选云聚达 kdata themeforest godaddy支付宝 七夕促销 怎样建立邮箱 双11秒杀 国外代理服务器软件 美国在线代理服务器 鲁诺 如何安装服务器系统 七夕快乐英语 电信网络测速器 全能空间 重庆联通服务器托管 privatetracker accountsuspended 建站论坛 WHMCS 更多