Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to read the data from multiple sheets of an excel file?

Hi All,

First, greetings to all as this is my very first day at QlikCommunity.

I have a scenario, where I need to read the data from an excel workbook, which contains multiple work sheets. Each sheets contains the data in same format, but the name of sheet is not known to me. The script should be able to read the sheet name as well as data inside the sheet dynamically.

To elaborate more on this let me use an example.

A excel workbook contain the details of student grades in a excel workbook (student.xlsx). Lets say, this excel file contains the data of 10 students. Each sheet is saved as students name for example, sheet name 'bob' contains the grade transcript of student bob. Apart from this the student name is not mentioned anywhere in the sheet.

Currently, I am using a for loop with the names of students as hardcoded, but now I need to read it dynamically.

Please let me know, how can I acheive this. I hope I am making sense.

It looks like an interesting problem, hope to get a solution soon. Thanks

Regards

UT

1 Solution

Accepted Solutions
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Have a look in to the attached file it will help you.

Celambarasan

View solution in original post

7 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Have a look in to the attached file it will help you.

Celambarasan

Not applicable
Author

Thanks Celambarasan,

Thanks for your help. I really appreciated the same.

This solution looks close but in this script you look for all worksheet starting with Sales*. But, I have no clues about the nature of names.

I think we can use the same logic with some custamization.

CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     In your case don't use If Statement apply directly.

     Remove this

     IF wildmatch('$(sheetName)', 'Sales*') THEN  // Only sheetNames that begin "Sales"

     END IF                    // End of optional sheet filtering

     Use the following alone

    

   Sales:   

                    LOAD *,

                              '$(sheetName)' as Student

                    FROM workbook.xls (biff, embedded labels, table is [$(sheetName)]);

Celambarasan

Not applicable
Author

Thanks a lot

I will try it and let you know.

Anonymous
Not applicable
Author

Note: If you are using a 64-bit system then you should use

Provider=Microsoft.ACE.OLEDB.12.0;

instead of

Provider=Microsoft.Jet.OLEDB.4.0;

The following is a modified 64-bit example for loading workbook.xls which is put in C:\qv_data folder:

/* Connect using the Jet provider. Specify the workbook path in the "Data Source" spec below. */

CONNECT TO [Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\qv_data\workbook.xls;Extended Properties="Excel 8.0;"];

/*

The SQLtables statement will load the "tables" table with a set of fields

describing the tables in the ODBC datasource. For Excel, each sheet is a table.

*/

tables:      // Name the table that will be created by SQLTables stmt

SQLtables;

DISCONNECT;     // Don't need ODBC connection anymore

/*

One of the fields loaded by SQLtables is "TABLE_NAME". This field will contain the sheet name.

We will loop through this set of sheet names.

*/

FOR i = 0 to NoOfRows('tables')-1

    /*

    Assign the TABLE_NAME to the variable "sheetName".

    TABLE_NAMEs that contain spaces will be enclosed in single quotes.

    The purgeChar function will remove any quotes.

    */

    LET sheetName = purgeChar(peek('TABLE_NAME', i, 'tables'), chr(39));

    // Optional filtering logic to select certain sheets

    IF wildmatch('$(sheetName)', 'Sales*') THEN  // Only sheetNames that begin "Sales"

        Sales:   

        // Now that we have a sheet name, a standard biff (Excel) load can be used.

        LOAD *,

            '$(sheetName)' as Sheet  // Optionally, the sheetName value may be loaded as a field

        FROM C:\qv_data\workbook.xls (biff, embedded labels, table is [$(sheetName)]);

    END IF        // End of optional sheet filtering

NEXT

DROP TABLE tables;   // The table list is no longer needed

Not applicable
Author

Hello Quan,

The script is working fine when I reload the report manually

But when I reload using qlikview publisher, I am getting below error:

CONNECT*Provider*

Error: ErrorSource: Microsoft OLE DB Service Components, ErrorMsg: Class not registered

General Script Error

Execution Failed

Execution finished.

What can be the reason?

Not applicable
Author

Same issue here. My QV version is 11.20

Any hints?