vb匯出到excel的方法

2021-07-24 15:14:48 字數 1848 閱讀 9967

//匯出

private sub command5_click()

if adodc2.recordset.recordcount = 0 then

msgbox "沒有資料可匯出!", vbexclamation, "匯出"

else

msgbox "將把資料匯出到excle裡,請稍等.......", vbexclamation, "匯出"

screen.mousepointer = vbhourglass

dim i as integer

dim j as integer

' xlsheet.cells.columns.  '.autofit

screen.mousepointer = 11

with xlsheet

'excle第一列的寬度

.columns(1).columnwidth = 9.15

.columns(2).columnwidth = 14.13

.columns(3).columnwidth = 14.63

.columns(4).columnwidth = 6.5

.columns(5).columnwidth = 12.5

'字型 邊框  居中

.cells.font.size = 9

.cells(1, 1).borders.linestyle = 1 '邊框

.cells(1, 2).borders.linestyle = 1

.cells(1, 3).borders.linestyle = 1

.cells(1, 4).borders.linestyle = 1

.cells(1, 5).borders.linestyle = 1

.cells.horizontalalignment = xlcenter

.cells.wraptext = true  '自動換行

.cells.entirecolumn.autofit  '行高根據內容自動調整

.cells.entirerow.autofit

'檔名稱

.name = cstr(date)  '時間為名稱

'標題列名稱

.cells(1, 1) = "t1"

.cells(1, 2) = "t2"

.cells(1, 3) = "t3"

.cells(1, 4) = "t4"

.cells(1, 5) = "t5"

end with

for i = 1 to vsflexgrid5.rows - 1 '遍歷vsflexgrid5的所有行數

for j = 1 to vsflexgrid5.cols - 1 '遍歷vsflexgrid5所有的列數

str = trim(vsflexgrid5.textmatrix(i, j))

'去掉空格 回車符

str = replace(str, vbcr, "")

str = replace(str, vblf, "")

xlsheet.cells(i + 1, j) = trim(str)

'加邊框

xlsheet.cells(i + 1, j).borders.linestyle = 1

'內容靠底部

'  xlsheet.range(xlsheet.cells(i + 1, j), xlsheet.cells(i + 1, j)).verticalalignment = 3

'  xlsheet.range(xlsheet.cells(i + 1, j), xlsheet.cells(i + 1, j)).horizontalalignment = 3

end if

end sub

DataGridView匯出到Excel的三個方法

region datagridview資料顯示到excel 開啟excel並將datagridview控制項中資料匯出到excel datagridview物件 是否顯示excel介面 add com microsoft excel 11.0 object library using excel m...

匯出到excel類

using system using system.data using system.configuration using system.web using system.web.security using system.web.ui using system.web.ui.webcontro...

資料匯出到excel

一 加上表頭後變成亂碼 要匯出的datatable 型別 excel的檔名 匯出的檔案中不帶表頭 二 使用wps開啟正常 匯出到excel 已經實現效果 資料表 檔名 列名 需要查詢幾列 else else resp.write ls item resp.write resp.end 三 目前用著感...