QlikView bietet eine Reihe von Funktionalitäten an, wie man xml-, Excel-, csv-,txt-Dateien, usw. strukturiert einlesen kann.
Dieser Tip zeigt, wie man auch .ini-Dateien sinnvoll auslesen kann.
“Typische” Ini-Dateien haben folgende Struktur (siehe auch http://en.wikipedia.org/wiki/INI_file):
[Section1] Name1=Value1 Name2=ValueXX Name3=ValueYY [Section2] Name4=Value3
Nachfolgender Code ladet eine beliebige Ini-Datei und bringt diese in strukturierte Form:
// **************************************************************
// this assumes that the ini-file defined below is located in the
// same folder as the qvw-file.
// **************************************************************
SET vIniFilePath = 'Test4.ini';
// **************************************************************
// Create a temporary table
// Note when reading the data-transformation:
// You have to read the load-statements bottom-up !!!
// **************************************************************
Temp_Ini:
Load
// get the name
if(_FlagSection = 0,left(FullField, index(FullField,'=')-1)) as Name,
// get the value
if(_FlagSection = 0,mid(FullField, index(FullField,'=')+1)) as Value,
*
;
Load
// just again a load to fill up the blank rows with the corresponding section
if(_FlagSection = 0, text(peek('Section',RecNo()-2)),Section) as Section,
FullField,
Id,
_FlagSection
;
Load
// if we are dealing with a section (see below) we cut the string inside
// the '[' and ']' characters
if (left(FullField,1) = '[' and right(FullField,1) = ']',purgechar((FullField),'[]')) as Section,
// if we have a '[' character at the beginning and a ']' character at the end of
// the string we are dealing with a section, so flag the record as section
if (left(FullField,1) = '[' and right(FullField,1) = ']',1,0) as _FlagSection,
*;
LOAD
RecNo() as Id,
@1 as FullField
FROM $(vIniFilePath)
(txt, codepage is 1252, no labels, delimiter is ',', msq);
// **************************************************************
// Load the values again to 'drop' the rows with sections in it.
// **************************************************************
Ini:
LOAD
Id as LineNo,
Section,
Name,
Value,
FullField as LineString // just for testing and review,
RESIDENT Temp_Ini
WHERE (_FlagSection = 0)
// prevent comments
and (left(Value,1) <> ';')
// prevent comments
and (left(Name,1) <> ';')
// prevent selecting empty-lines
and ((len(Name) > 0) and (len(Value) > 0))
Order BY Id
;
//drop the temporary table which is not used anymore
Drop TABLE Temp_Ini;
Damit lassen sich die Daten in strukturierter Form an der Oberfläche anzeigen:
Verbesserungen:
Dinge, die ich in meinem Script nicht beachtet habe:
- Escape Character
- Kommentare am Ende einer Zeile
- usw.
Downloads
QlikView-Applikation mit Beispiel-Dateien (.zip, 1.2 MB)
Possibly related posts:
- QlikTip #4: Nicht benötigte Felder in QlikView löschen (Dynamic Reduce)
Wie löscht man in einer QlikView-Applikation nicht benötigte Felder um Ressourcen zu sparen. Die Ausgangssituation: Sie haben Ihre QlikView-Applikation oder QVDs erstellt, mit denen Sie Daten aus Ihrem Quellsystem, Ihrer Datenbank laden. Nun haben Sie... - QlikTip #12: Erweiterung des Store Into-Befehls in QlikView 9
STORE INTO konnte bis dato zur Speicherung einer Tabelle in eine QVD-Datei verwendet werden. // Store table Customers into Qvd-file STORE Customers INTO Customers.qvd (qvd); Dabei ist (auch in vorherigen Versionen) der Parameter nach dem... - QlikTip #7: Überprüfen, ob eine Tabelle existiert
Im QlikTip #3 habe ich ja bereits ausgeführt, wie man im Load-Script überprüfen kann, ob ein Feld existiert oder nicht. Wie kann man nun aber überprüfen, ob eine Tabelle existiert oder nicht, dies habe ich...


Mag. Stefan WALTHER
One Comment
… das habe ich gesucht, danke für die detailliere Beschreibung und die Lösung meines Problems
Gruss
H. Dollinger