VB 内容导出excel 如何设置居中
Private Sub Command5_Click()Dim A1, A2, A3, A4, A5, A6
Dim Row, Col, xlApp
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
On Error Resume Next
Set xlApp = New Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Dim strSource, strDestination As String
strSource = "\\192.168.1.168\D$\Excels\MadeDepart\OutSuperSelllM.xls"
strDestination = "\\192.168.1.168\D$\Excels\MadeDepart\OutSuperSelllMTemp.xls"
FileCopy strSource, strDestination
Set xlbook = xlApp.Workbooks.Open("\\192.168.1.168\D$\Excels\MadeDepart\OutSuperSelllMTemp.xls")
Set xlsheet = xlbook.Worksheets("OutSuperSell")
xlsheet.Activate
If adoCon.State = adStateClosed Then adoCon.Open
Set adoRs.ActiveConnection = adoCon
adoRs.Open "select * from SuKiGuestInforGong where 编号='" & MSFlexGrid2.TextMatrix(1, 8) & "' order by 编号"
If Not adoRs.EOF Then
xlsheet.Cells(2, 5).Value = adoRs("名称")
xlsheet.Cells(3, 5).Value = adoRs("联系人")
xlsheet.Cells(4, 5).Value = adoRs("电话")
xlsheet.Cells(5, 5).Value = adoRs("传真")
End If
adoRs.Close
If Text5.Text <> "" Then
adoRs.Open "select * from SuKiGuestInforGong where 编号='" & Text5.Text & "' order by 编号"
If Not adoRs.EOF Then
' xlsheet.Cells(2, 2).Value = adoRs1("名称")
xlsheet.Cells(3, 2).Value = adoRs("联系人")
xlsheet.Cells(4, 2).Value = adoRs("电话")
xlsheet.Cells(5, 2).Value = adoRs("传真")
End If
adoRs.Close
End If
xlsheet.Cells(6, 2).Value = Text1.Text
'xlsheet.Cells(4, 2).Value = MSFlexGrid2.TextMatrix(1, 9)
xlsheet.Cells(6, 6).Value = format(Date, "yyyy-mm-dd")
Row = 8
Col = 1
i = 1
Do While i < MSFlexGrid2.Rows
Col = 1
A1 = ""
A2 = ""
A3 = ""
A4 = ""
A5 = ""
A6 = ""
A1 = MSFlexGrid2.TextMatrix(i, 1) '类型
A2 = MSFlexGrid2.TextMatrix(i, 2) '材料名称
A3 = MSFlexGrid2.TextMatrix(i, 3) '规格
A4 = MSFlexGrid2.TextMatrix(i, 4) '单位
A5 = MSFlexGrid2.TextMatrix(i, 5) '数量
A6 = MSFlexGrid2.TextMatrix(i, 6) '单位
xlsheet.Cells(Row, Col).Value = A1
Col = Col + 1
xlsheet.Cells(Row, Col).Value = A2
Col = Col + 1
xlsheet.Cells(Row, Col).Value = A3
Col = Col + 1
xlsheet.Cells(Row, Col).Value = A4
Col = Col + 1
xlsheet.Cells(Row, Col).Value = A5
Col = Col + 1
xlsheet.Cells(Row, Col).Value = A6
Row = Row + 1
i = i + 1
Loop
End Sub