VB操作Excel報(bào)表(實(shí)例、圖例、源碼、注釋).doc_第1頁
VB操作Excel報(bào)表(實(shí)例、圖例、源碼、注釋).doc_第2頁
VB操作Excel報(bào)表(實(shí)例、圖例、源碼、注釋).doc_第3頁
VB操作Excel報(bào)表(實(shí)例、圖例、源碼、注釋).doc_第4頁
VB操作Excel報(bào)表(實(shí)例、圖例、源碼、注釋).doc_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

VB操作Excel報(bào)表(實(shí)例、圖例、源碼、注釋)用Excel報(bào)表非常方便,而用VB操作Excel更能延長VB的功能范圍。對于重復(fù)生成的表格更是非常方便。字體,行高,列寬,合并單元格,排版等功能都有。供大家學(xué)習(xí)研究。 VB中使用Excel控件要先引用哦。要不你錯(cuò)都不知道哪錯(cuò)了。郁悶吧! 一、報(bào)表預(yù)覽如下 1、無內(nèi)容報(bào)表如下: 2、填表后預(yù)覽如下:測試內(nèi)容,隨便填的。二、界面預(yù)覽如下:打印記錄按鈕為Command3三、源碼如下:Private Sub Command3_Click()聲明一個(gè)新的Excel對象 Set winkexcel = New Excel.Application該對象可見 winkexcel.Visible = True選擇第一張表為操作表 winkexcel.SheetsInNewWorkbook = 1表添加內(nèi)容 Set winkworkbook = winkexcel.Workbooks.Add 設(shè)置指定單元格行高列寬 Set xlsheet = winkworkbook.Worksheets(1) xlsheet.Rows(1).RowHeight = 45 xlsheet.Rows(2).RowHeight = 33 xlsheet.Rows(3).RowHeight = 33 xlsheet.Rows(4).RowHeight = 33 xlsheet.Rows(5).RowHeight = 33 xlsheet.Rows(6).RowHeight = 300 xlsheet.Rows(7).RowHeight = 100 xlsheet.Rows(8).RowHeight = 45 xlsheet.Rows(9).RowHeight = 45 xlsheet.Rows(10).RowHeight = 26 xlsheet.Columns(1).ColumnWidth = 14 xlsheet.Columns(2).ColumnWidth = 24 xlsheet.Columns(3).ColumnWidth = 14 xlsheet.Columns(4).ColumnWidth = 24 設(shè)置表格內(nèi)容的對齊方式winkexcel.ActiveSheet.Rows.HorizontalAlignment = xlVAlignCenter 水平居中winkexcel.ActiveSheet.Rows.VerticalAlignment = xlVAlignCenter 垂直居中 With winkexcel.ActiveSheet.Range(A1:D1) 合并單元格 .Merge End With With winkexcel.ActiveSheet.Range(B6:D6) 合并單元格 .Merge End With With winkexcel.ActiveSheet.Range(B7:D7) 合并單元格 .Merge End With 畫邊框線,細(xì)線,黑。 With winkexcel.ActiveSheet.Range(A3:D9).Borders 邊框設(shè)置 .LineStyle = xlBorderLineStyleContinuous .Weight = xlThin .ColorIndex = 1 End With 為單元格添加內(nèi)容,請注意數(shù)字索引順序。行在前,列再后。 With winkexcel.ActiveSheet .Cells(2, 1).Value = 檢修部位: 第1行第2列 .Cells(2, 4).Value = 編號: 第2行第2列 .Cells(3, 1).Value = 設(shè)備型號 .Cells(3, 3).Value = 入庫檢修時(shí)間 .Cells(4, 1).Value = 設(shè)備編號 .Cells(4, 3).Value = 檢修完工時(shí)間 .Cells(5, 1).Value = 修 程 .Cells(5, 3).Value = 檢 修 單 位 .Cells(6, 1).Value = 檢 修 主 要 項(xiàng) 目 .Cells(7, 1).Value = 更換主要部件 注意添加空格,使自動換行后內(nèi)容都居中。 .Cells(8, 1).Value = 檢修班長 (簽字) .Cells(8, 3).Value = 檢修人 (簽字) .Cells(9, 1).Value = 主管部長 (簽字) .Cells(9, 3).Value = 驗(yàn)收員 (簽字) .Cells(10, 1).Value = 鐵路運(yùn)輸部 .Cells(3, 4).Value = DTPicker1.Value .Cells(4, 4).Value = DTPicker2.Value .Cells(10, 4).Value = DTPicker3.Value .Cells(2, 2).Value = + Combo7.Text .Cells(2, 4).Value = 編號: + Text2.Text .Cells(3, 2).Value = + Text3.Text .Cells(4, 2).Value = + Text1.Text .Cells(5, 2).Value = + Text4.Text .Cells(5, 4).Value = + Combo6.Text .Range(A1:D1) = 內(nèi)燃機(jī)車檢修驗(yàn)收單 這個(gè)區(qū)域的值 .Range(B6:D6) = + Text7.Text .Range(B7:D7) = + Text8.Text End With With winkexcel.ActiveSheet 設(shè)置自動換行 .Cells(6, 1).WrapText = True 設(shè)置文字方向?yàn)樨Q版 .Cells(6, 1).Orientation = xlVertical .Cells(7, 1).WrapText = True .Cells(7, 1).Orientation = xlVertical .Cells(8, 1).WrapText = True .Cells(9, 1).WrapText = True .Cells(8, 3).WrapText = True .Cells(9, 3).WrapText = True End With 設(shè)置范圍單元格內(nèi)的字體 With winkexcel.ActiveSheet.Range(A1:D1).Font 字體設(shè)置 .Bold = True .Size = 20 .ColorIndex = 1 End With With winkexcel.ActiveSheet.Range(A2:D10).Font 字體設(shè)置 .Size = 12 .ColorIndex = 1 End With 設(shè)置上下左右邊距。 winkexcel.ActiveSheet.PageSetup.TopMargin = 2 / 0.035 winkexcel.ActiveSheet.PageSetup.BottomMargin = 2 / 0.035 winkexcel.ActiveSheet.PageSetup.LeftMargin = 1.4 / 0.035 winkexcel.ActiveSheet.PageSetup.RightMargin = 1.4 / 0.035 設(shè)置頁眉頁腳距離 winkexcel.ActiveSheet.PageSetup.CenterHorizontally = 2 / 0.035 winkex

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論