Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

silambarasan130
Contributor II

How to use loop concept in Script

I have 3 excel files, that is 2700,2701,2702. How can i load these files using loop concept.

Could anyone pls help me.

7 Replies

Re: How to use loop concept in Script

MVP
MVP

Re: How to use loop concept in Script

Hi,

You can load all the files using wildcard characters like below, no need of loops here

Data:

LOAD

*,

FileName() AS ExcelFileName

FROM *.xlsx

-----------------;

Hope this helps you.

Regards,

jagan.

silambarasan130
Contributor II

Re: How to use loop concept in Script

I'm not getting clear explanation. Could u pls try to explain me in some other way. Beca i have multiple excel files. not excel sheets.

balrajahlawat
Esteemed Contributor

Re: How to use loop concept in Script

Why not run this script?

I am hoping you r having same fields in all the excel files......

Test:

Load

*

From ExcelFielName27*;   // * is here a wild card char and load all the files starting with '27' into one file, say Test

ian_t_jones
New Contributor

Re: How to use loop concept in Script

Hi,

As   

You can load all the files using wildcard characters like below, no need of loops here

Data:     //This is the name of the table you will create

LOAD   // This lets qlikview know you are loading new data

*,          // The * means load all the fields in the spreadsheet

FileName() AS ExcelFileName   // This statement will let you know which spreadsheet the data came from

FROM *.xlsx // this will load all the spreadsheets (Excel Files) in the folder

If you use the "load table" wizard then everything should be straight forward

reddys310
Honored Contributor II

Re: How to use loop concept in Script

Hi Silambarasan,

Try something like this:

Set vConcatenate = ;

sub ScanFolder(Root)

          for each FileExtension in 'csv'

                    for each FoundFile in filelist( Root & '\*.' & FileExtension)

                              FileList:

                              $(vConcatenate)

                              LOAD *, '$(FoundFile)' as SourceFile

                              FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is ',', msq, header is 2 lines);

                              Set vConcatenate = Concatenate;

                    next FoundFile

          next FileExtension

          for each SubDirectory in dirlist( Root & '\*' )

                    call ScanFolder(SubDirectory)

          next SubDirectory

end sub

Call ScanFolder('C:\Users\hic\Documents\2012\Work\QV Apps\DoDir') ;

Thanks,

Sangram.