When using VB, VBA, or other forms that support creating and exporting Excel files, you usually need to typeset and beautify the file format. There are two ways to do this: first, use an Excel file with a well-designed format to open it and pay for it. 2. Use Ole's own dashes and border adjustment tools. Next, let's take a look at the code for several operations under this practice.
1. draw borders
Xlsheet. Range ("A1: F4"). Select
With xlapp. Selection
. Font. Name = ""
. Font. size = 18
. Font. Bold = true
'. Columns. autofit
. Columns. columnwidth = 13
'. Background = 0
. Borders. linestyle = xlcontinuous 'continuous line
. Borders. colorindex = 1' black
. Borders. Weight = xlthin 'slim line
End
2. When you draw some lines in the border
'. Borders (xlinsidevertical). linestyle = xlcontinuous
'. Borders (xlinsidevertical). colorindex = 1
'. Borders (xlinsidevertical). Weight = xlthin
8 lines in totalXldiagonaldown,Xldiagonalup,Xledgebottom,Xledgeleft,Xledgeright, OrXledgetop,Xlinsidehorizontal, OrXlinsidevertical.
3. Merge Cells
XlSheet. Range ("A1: F4"). Select
With xlApp. Selection
. MergeCells = True
. HorizontalAlignment =-4108 'horizontal residence
. Verticalignment =-4108 'vertical residence
. Font. name = ""
. Font. Size = 18
. Font. Bold = True
'. Columns. AutoFit
. Columns. ColumnWidth = 13
End
4. The best way to export an excel file is to directly display the file in excel, so that you can save or close it yourself.
Dim xlApp As Excel. Application
Dim xlBook As Object
Dim xlSheet As Object
Screen. MousePointer = vbHourglass
Set xlApp = CreateObject ("Excel. Application ")
Set xlbook = xlapp. workbooks. Add
Set xlsheet = xlbook. worksheets (1)
'Processing
Xlapp. Visible = true
Screen. mousepointer = vbdefault
Set xlapp = nothing
Set xlbook = nothing
Set xlsheet = nothing
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 477480