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

Displaying an unstructured plain text document

Hi All,

I'm trying to write a report which allows the user to view the contents of a plain text document. I have a table with two columns: document title; file location. What I want is when the user has selected only one document it displays this. The closest I have found is the president picture in the US presidents example.

My attempts so far has not been too successful; I can display the contents of a file that I have hardcoded the location of and I can display paths both loaded from the filesystem and matched up to the contents of my table but I cannot complete the circle.

Here is what I have written:

LOAD
A as Title,
B as Name
FROM

(ooxml, no labels);

LOAD @1
FROM
[1.txt]
(txt, codepage is 1252, no labels);

for each File in filelist ('*.txt')
Load '$(File)' as Name,
FileSize( '$(File)' ) as Size,
FileTime( '$(File)' ) as FileTime autogenerate 1;
next File

for each File in filelist ('*.txt')
INFO LOAD * inline [
Name, Body
$(File), $(File)
];
next File

Does anyone know how I can get the actual body of the text file into "Body" on the last line? Then I can load that into a text object and, with any luck, Bob will be my uncle.

Thanks - Christopher

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

To get the contents to display in a text box, use script something like this:

FOR EACH file in filelist('*.txt')
Contents:
LOAD '$(file)' as filename,
@1:n as TextLine,
RecNo() as LineNo
FROM [$(file)]
(fix, codepage is 1252);
;
NEXT file

In your textbox use the expression:

=if(GetPossibleCount(filename)=1, concat(TextLine,chr(10), LineNo), '')

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

To get the contents to display in a text box, use script something like this:

FOR EACH file in filelist('*.txt')
Contents:
LOAD '$(file)' as filename,
@1:n as TextLine,
RecNo() as LineNo
FROM [$(file)]
(fix, codepage is 1252);
;
NEXT file

In your textbox use the expression:

=if(GetPossibleCount(filename)=1, concat(TextLine,chr(10), LineNo), '')

Not applicable
Author

Rob, you are a magic man! That works a treat; many thanks.

Now to get it to work in the context of my wider project!

- Christopher