How to beautify excel when OEL exports an excel file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.