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.
spinservers是Majestic Hosting Solutions LLC旗下站点,商家提供国外服务器租用和Hybrid Dedicated等产品,数据中心包括美国达拉斯和圣何塞机房,机器默认10Gbps端口带宽,高配置硬件,支持使用PayPal、信用卡、支付宝或者微信等付款方式。农历春节之际,商家推出了几款特别促销配置,最低双路E5-2630Lv3机器每月149美元起,下面列出几款机器...
特网云特网云为您提供高速、稳定、安全、弹性的云计算服务计算、存储、监控、安全,完善的云产品满足您的一切所需,深耕云计算领域10余年;我们拥有前沿的核心技术,始终致力于为政府机构、企业组织和个人开发者提供稳定、安全、可靠、高性价比的云计算产品与服务。官方网站:https://www.56dr.com/ 10年老品牌 值得信赖 有需要的请联系======================特网云美国高防御...
物语云计算(MonogatariCloud)是一家成立于2016年的老牌国人商家,主营国内游戏高防独服业务,拥有多家机房资源,产品质量过硬,颇有一定口碑。本次带来的是美国圣何塞 Equinix 机房的高性能I9-10980XE大带宽VPS,去程CN2GIA回程AS9929,美国原生IP,支持解锁奈飞等应用,支持免费安装Windows系统。值得注意的是,物语云采用的虚拟化技术为Hyper-V,资源全...
vb net 教程为你推荐
ghostxp3ghost xp sp3 和 windows xp3有啥区别1433端口怎么去看1433端口arm开发板新手入门应如何选择 ARM 开发板?手机区号手机电话号码开头95共15位号码是什么手机号码?唱吧电脑版官方下载电脑怎么安装唱吧,要能用的,请教教程,谢谢网管工具网吧管理软件都有哪些?网站优化方案网站优化方案如何写?怎么上传音乐如何上传音乐怎么在图片上写文字怎么才能在图片上写字呢如何修改ie主页怎么修改IE首页
美国和欧洲vps 云网数据 edgecast oneasiahost 光棍节日志 qq数据库下载 web服务器架设 申请个人网站 百兆独享 jsp空间 免费智能解析 息壤代理 免费网页空间 789电视剧 空间首页登陆 免费ftp 后门 cdn服务 hdroad 美国主机侦探 更多