How can I import all sheet from an Excel file to a able?

Source: Internet
Author: User

If you want to store test data files from external storage, such
Excel
Import
Sheet
Page
Datatable
And Judge
Datatable
Whether the specified
Sheet
If not, add
Sheet
. For example
Datatable
Object
Getsheet
,
Addsheet
And
Excel
Of
Com
Object programming:

 

Function importallsheets (byval filename)


Dim
Oexcel, obook

 


'Launch
Excel


Set
Oexcel = GetObject ("", "Excel. application ")

 


'Open
The file in Read Only Mode


Set
Obook = oexcel. workbooks. Open (filename, true)

 


'Enumerate
Through all the sheets present in the file


For
Each osheet in obook. worksheets

 


'Check
If a datatable with current name already exists


If
Not ifdatasheetexist (osheet. Name) then


'Able able
Cannot be imported if the sheet does not exist


Datatable. addsheet
Osheet. Name


End
If

 


'Import
The sheet


Datatable. importsheet
Filename, osheet. Name, osheet. Name


Next

 


Set
Obook = nothing

 


'Quit
Excel


Oexcel. Quit


Set
Oexcel = nothing

End Function

 

 

Function ifdatasheetexist (byval sheetname)


Ifdatasheetexist
= True


On
Error resume next


Dim
Otest


Set
Otest = datatable. getsheet (sheetname)


If
Err. number then ifdatasheetexist = false


On
Error goto 0

End Function

 

 

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.