Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Fred12
Contributor III
Contributor III

How to skip a excel file if he doesn't have the "good sheet name"

Hello,

I did that code : 

LET vParentFolderPath = 'lib://04_D/Production/';

// Récupérer la liste des dossiers dans le chemin parent
FOR Each vFolder in DirList('$(vParentFolderPath)*')
Trace 'La première trace est ' $(vFolder);
// LET vFolderPath = '$(vParentFolderPath)$(vFolder)/';
// Trace $(vFolderPath);

// Liste tous les fichiers Excel dans le dossier
FOR Each vFile in FileList('$(vFolder)/*.xlsx')

Trace 'La deuxième trace est ' $(vFile);
// Chargez le contenu du fichier Excel dans une table temporaire
TempTable:
LOAD *
FROM [$(vFile)]
(ooxml, embedded labels, table is [RENDU]);
NEXT
NEXT

 

It works fine but the problem is that sometimes, I have excel file who has no sheet " RENDU"

So I try to find a solution to skip these file if they don't have the sheet "RENDU"

 

Somemone has an idea about how I can skip a file excel if he has not the sheet "RENDU" ?

 

Thanks !

@Kushal_Chawda

 

Labels (4)
6 Replies
srchagas
Creator III
Creator III

Hi
One Option will be move this data to ODBC so you can control more on the data.

If this is not the case Set errormode = 0 s o he will ignore the error and continue the execution

https://help.qlik.com/en-US/sense/May2023/Subsystems/Hub/Content/Sense_Hub/Scripting/ErrorVariables/...

 

you can add only in this piece of code the error mode and turn on again like

LET vParentFolderPath = 'lib://04_D/Production/';

// Récupérer la liste des dossiers dans le chemin parent
FOR Each vFolder in DirList('$(vParentFolderPath)*')
Trace 'La première trace est ' $(vFolder);
// LET vFolderPath = '$(vParentFolderPath)$(vFolder)/';
// Trace $(vFolderPath);

//Disable error mode to avoid stop execution because of excel with no  RENDU sheet

SET ErrorMode =0 ; 

// Liste tous les fichiers Excel dans le dossier
FOR Each vFile in FileList('$(vFolder)/*.xlsx')

Trace 'La deuxième trace est ' $(vFile);
// Chargez le contenu du fichier Excel dans une table temporaire
TempTable:
LOAD *
FROM [$(vFile)]
(ooxml, embedded labels, table is [RENDU]);
NEXT
NEXT

//Enable again the errormode

ErrorMode =1; 

 

Fred12
Contributor III
Contributor III
Author

Thanks it works, 

 

I 'm trying to add a new variable at my code for additionnal folder.

to explain :

my folder "Production" contains a lot of folder and these lot of folder contains xlsx that I got with that code.

But sometimes I have this : 

my folder "Production" contains a lot of folder and these lot of folder contains a lot of folders too who contains xlsx.

 

Thanks

Fred12
Contributor III
Contributor III
Author

It's ok, I found how I can do it ,

 

but can I have a solution to don't see always "error" when I load my script ?

srchagas
Creator III
Creator III

i don't think you will have an solution for that  only if crate a name conversion for you excel files and use as base like 
Sales_2021.xls
then in your code you search for Sales*.xls

Fred12
Contributor III
Contributor III
Author

Ok,   I got 7 tempory tables.

 

Can I modify code to have just 1 table with only field I need ?

 

thanks

srchagas
Creator III
Creator III

What do you mean?

could show the data model ?