'**********************************连接数据库************************
con.cursorlocation = aduseclient
con.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" & strconnection & ";persist security info=false"
con.open
rst_tsf.open "tdefeiyong", con, adopenkeyset, adlockoptimistic, adcmdtable
if not (rst_tsf.bof and rst_tsf.eof) then
rst_tsf.movefirst
end if
rst_qm.open "qianming", con, adopenkeyset, adlockoptimistic, adcmdtable
rst_qm.movefirst
'*********************************工作表初使化**********************************
dim xlsheet as excel.worksheet
set xlsheet = xlbook.sheets.add
xlsheet.name = "机械台时、组时费汇总表"
xlsheet.columns(1).columnwidth = 5
xlsheet.columns(2).columnwidth = 20
xlsheet.columns(3).columnwidth = 7
xlsheet.columns(4).columnwidth = 7
xlsheet.columns(5).columnwidth = 7
xlsheet.columns(6).columnwidth = 7
xlsheet.columns(7).columnwidth = 7
xlsheet.columns(8).columnwidth = 7
xlsheet.columns(9).columnwidth = 7
xlsheet.columns("a:i").font.size = 9
xlsheet.columns("a:i").verticalalignment = xlvaligncenter '垂直居中
xlsheet.columns(1).horizontalalignment = xlhaligncenter '1列水平居中对齐
xlsheet.columns(2).horizontalalignment = xlhalignleft '2列水平左对齐
'******************************写入标头************************************
xlsheet.rows(1).rowheight = 35
xlsheet.range(xlsheet.cells(1, 1), xlsheet.cells(1, 9)).mergecells = true
xlsheet.cells(1, 1).font.size = 14
xlsheet.cells(1, 1).font.bold = true
xlsheet.cells(1, 1).value = "机械台时、组时费汇总表"
xlsheet.cells(2, 9).value = "单位:元"
xlsheet.range(xlsheet.cells(3, 1), xlsheet.cells(5, 1)).mergecells = true
xlsheet.cells(3, 1).value = "编号"
xlsheet.range(xlsheet.cells(3, 2), xlsheet.cells(5, 2)).mergecells = true
xlsheet.cells(3, 2).value = "机械名称"
xlsheet.range(xlsheet.cells(3, 3), xlsheet.cells(5, 3)).mergecells = true
xlsheet.cells(3, 3).value = "台时费"
xlsheet.range(xlsheet.cells(3, 4), xlsheet.cells(3, 9)).mergecells = true
xlsheet.cells(3, 4).value = "其 中"
xlsheet.range(xlsheet.cells(3, 3), xlsheet.cells(5, 3)).mergecells = true
xlsheet.cells(3, 3).value = "台时费"
xlsheet.range(xlsheet.cells(4, 4), xlsheet.cells(5, 4)).mergecells = true
xlsheet.cells(4, 4).value = "折旧费"
xlsheet.range(xlsheet.cells(4, 5), xlsheet.cells(5, 5)).mergecells = true
xlsheet.cells(4, 5).value = "修理替换费"
xlsheet.range(xlsheet.cells(4, 6), xlsheet.cells(5, 6)).mergecells = true
xlsheet.cells(4, 6).value = "安拆费"
xlsheet.range(xlsheet.cells(4, 7), xlsheet.cells(5, 7)).mergecells = true
xlsheet.cells(4, 7).value = "人工费"
xlsheet.range(xlsheet.cells(4, 8), xlsheet.cells(5, 8)).mergecells = true
xlsheet.cells(4, 8).value = "燃料费"
xlsheet.range(xlsheet.cells(4, 9), xlsheet.cells(5, 9)).mergecells = true
xlsheet.cells(4, 9).value = "其他费"
xlsheet.range(xlsheet.cells(1, 1), xlsheet.cells(5, 9)).horizontalalignment = xlhaligncenter
xls.activesheet.pagesetup.printtitlerows = "$1:$5" '固定表头
'****************************************写入内容*************************************
dim i as integer
i = 6
do while not rst_tsf.eof
xlsheet.cells(i, 1).value = rst_tsf.fields("nn")
xlsheet.cells(i, 2).value = rst_tsf.fields("name")
xlsheet.cells(i, 3).value = rst_tsf.fields("price")
xlsheet.cells(i, 4).value = rst_tsf.fields("zhejiu")
xlsheet.cells(i, 5).value = rst_tsf.fields("xiuli")