level 12
henryAlice
楼主
Imports Excel = Microsoft.Office.Interop.Excel ‘最开头引用
private sub CZexcel()
System.Windows.Forms.Application.DoEvents()
Dim str As String = ComboBox1.Text & ComboBox2.Text
Dim SaveFileDialog1 As New SaveFileDialog()
With SaveFileDialog1
.Filter = "EXCEL文件格式(*.xls)|*.xls"
.Title = "请选择保存文件的路径..."
.FilterIndex = 1
.FileName = str & "对账单"
End With
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel _
OrElse SaveFileDialog1.FileName = "" Then Exit Sub
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
If xlApp Is Nothing Then xlApp = CreateObject("Excel.application")
xlApp.Application.DisplayAlerts = False
xlBook = xlApp.Workbooks.Add
xlBook.Worksheets.Add()
xlSheet = xlBook.Worksheets(1) : xlSheet.Name = str & "明细"
'以下的用来画框
With xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(5, 5))
.Borders(7).LineStyle = 1 '左
.Borders(8).LineStyle = 1 '顶
.Borders(9).LineStyle = 1 '底
.Borders(10).LineStyle = 1 '右
.Borders(11).LineStyle = 1 '垂直
.Borders(12).LineStyle = 1 '水平
.HorizontalAlignment = 3
End With
xlSheet.Cells.EntireColumn.AutoFit()‘这条语句自动调整列宽
’这段是合并A1:A5 并将字上下左右居中
With xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 5))
.Merge()
.HorizontalAlignment = 3
.VerticalAlignment = 3
End With
xlSheet.Range("A1").FormulaR1C1 = str & "对账单" ‘将A1填入字条
xlSheet.Range("A1").Font.Size = 20 ’设定字体大小
xlSheet.Cells(2, 5) = "备注" '在B5填入字条
xlBook.Close(True, SaveFileDialog1.FileName)‘保存EXCEL文件
xlBook = Nothing
xlApp.Quit()
xlApp = Nothing
end sub
2015年05月31日 04点05分
1
private sub CZexcel()
System.Windows.Forms.Application.DoEvents()
Dim str As String = ComboBox1.Text & ComboBox2.Text
Dim SaveFileDialog1 As New SaveFileDialog()
With SaveFileDialog1
.Filter = "EXCEL文件格式(*.xls)|*.xls"
.Title = "请选择保存文件的路径..."
.FilterIndex = 1
.FileName = str & "对账单"
End With
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel _
OrElse SaveFileDialog1.FileName = "" Then Exit Sub
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
If xlApp Is Nothing Then xlApp = CreateObject("Excel.application")
xlApp.Application.DisplayAlerts = False
xlBook = xlApp.Workbooks.Add
xlBook.Worksheets.Add()
xlSheet = xlBook.Worksheets(1) : xlSheet.Name = str & "明细"
'以下的用来画框
With xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(5, 5))
.Borders(7).LineStyle = 1 '左
.Borders(8).LineStyle = 1 '顶
.Borders(9).LineStyle = 1 '底
.Borders(10).LineStyle = 1 '右
.Borders(11).LineStyle = 1 '垂直
.Borders(12).LineStyle = 1 '水平
.HorizontalAlignment = 3
End With
xlSheet.Cells.EntireColumn.AutoFit()‘这条语句自动调整列宽
’这段是合并A1:A5 并将字上下左右居中
With xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 5))
.Merge()
.HorizontalAlignment = 3
.VerticalAlignment = 3
End With
xlSheet.Range("A1").FormulaR1C1 = str & "对账单" ‘将A1填入字条
xlSheet.Range("A1").Font.Size = 20 ’设定字体大小
xlSheet.Cells(2, 5) = "备注" '在B5填入字条
xlBook.Close(True, SaveFileDialog1.FileName)‘保存EXCEL文件
xlBook = Nothing
xlApp.Quit()
xlApp = Nothing
end sub