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春节优惠:$149/月10Gbps圣何塞服务器-2*E5-2630Lv3 CPU,256G内存,2*1.6T SSD硬盘

spinservers是Majestic Hosting Solutions LLC旗下站点,商家提供国外服务器租用和Hybrid Dedicated等产品,数据中心包括美国达拉斯和圣何塞机房,机器默认10Gbps端口带宽,高配置硬件,支持使用PayPal、信用卡、支付宝或者微信等付款方式。农历春节之际,商家推出了几款特别促销配置,最低双路E5-2630Lv3机器每月149美元起,下面列出几款机器...

CYUN专注海外精品服务器资源 国庆钜惠 最低5折起 限量促销

国庆钜惠 最低5折起 限量促销CYUN专注海外精品服务器资源,主营香港CN2 GIA、美国CERA、美国高防服务器资源,实体公司,ISP/IDC资质齐全,客服配备齐全。本次针对国庆推出非常给力的促销活动,旗下所有平台同享,新老客户同享,限时限量,售完截止。活动截止时间:2021年10月9日官网地址:www.cyun.net参与机型:香港CN2 GIA云服务器、香港双程CN2云服...

totyun:香港cn2 vps,5折优惠,$6/月,10Mbps带宽,不限流量,2G内存/2核/20g+50g

totyun,新公司,主要运作香港vps、日本vps业务,接入cn2网络,不限制流量!VPS基于KVM虚拟,采用系统盘和数据盘分离,从4G内存开始支持Windows系统...大家注意下,网络分“Premium China”、“Global”,由于站长尚未测试,所以也还不清楚情况,有喜欢吃螃蟹的尝试过不妨告诉下站长。官方网站:https://totyun.com一次性5折优惠码:X4QTYVNB3P...

vb net 教程为你推荐
刷网站权重怎么才能提升网站百度权重呢手游运营手册2019新个税主要内容有哪些?可以简单说明一下吗?人人时光机求 《小叮当》的日语歌词。最好有片假名的邮箱打不开怎么办我的邮箱打不开怎么办公章制作如何制作公章网站运营刚创业的网站运营怎么做?arm开发板新手入门应如何选择 ARM 开发板?申请证书手机申请证书办公协同软件求一款国内知名的OA办公软件,谁知道有哪些呢?ios7固件下载ios 7及以上固件请在设备上点信任在哪点
中国域名交易中心 服务器评测 t牌 59.99美元 香港cdn 免费ftp空间 美国php主机 eq2 网盘申请 52测评网 cpanel空间 全站静态化 godaddy域名证书 河南m值兑换 me空间社区 国外代理服务器地址 美国堪萨斯 常州联通宽带 申请免费空间 免费蓝钻 更多