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

Create txt files without the header using the script.

Hi, everyone!

How are you? I am new with QlikView, but I already have a doubt. I'd appreciate if someone could help me.

I need to convert a txt file into another txt file. No problems with it. I can inform the directory, read all the input files, process the information and generate the new formatted output files. I am doing it in the script level. The problem is that the output files are created with the first line containing a header. I don't want the header. I am using the STORE command. Is there any way to store my data without the header?

I can do it using a buttom with a export action. There is a setup to do it. But I can't use this buttom because there won't be a user to do it. The idea is to have the script run automatically every evening. Can I "hit" the buttom at the script level?

Tks in advance,

Marcelo - from Brazil

1 Solution

Accepted Solutions
Not applicable
Author

Hi, all!

I solved my problem but with a different solution. I used the first line of the file as the label of my table, that will be exported. And loaded to table from second line to the end of the file. The firs line was used by a variable and used to name the unique column of my table. Sorry my english. I don't know if it is clear for you what I did.

Tks,

Marcelo

View solution in original post

13 Replies
Not applicable
Author

Hello Marcelo !

Take a look at the STORE statement. You can dump a table as a plain TXT file.

(

Marcelo :

Dá uma olhada no comando STORE . Vc consegue jogar uma tabela pra um arquivo texto. Fala de onde ? Eu Piracicaba/interior de Sampa.

Abraço e boa sorte com o QV ! Ótimo produto !

)

mantaq10
Contributor III
Contributor III

Hi,

You can use a macro to do this, press CTRL+M to invoke the macro editor.

Then do something like this:


Sub Foo
ActiveDocument.GetSheetObject("BU01").Press
End Foo


You can get the ObjectId of the button from Document Properties->Sheets.

However, macros slows down the application. If you share your script which exports the text file(s)., a direct resolution could be presented.

Not applicable
Author

Hi, Adriano!

The Store statement creates a header line, this is my problem. I can't have it.

Tks,

Marcelo

"Estou em São Paulo. Entro em contato contigo em private".

Not applicable
Author

Hi Rahman,

I have the following macro that works fine running from Excel. But when I try to use it from Qlikview, it gives me an error at the statement CreateObject("Scripting.FileSystemObject").
I am still working on it, but if you have a tip, please, tell me, because my deadline is near.

Function RemoveHeader()

Dim oFSO, oFSO2, sText, oFile, oFile2, Count
Dim sFile, sFile2

sFile = "c:/temp/temp1.txt"
sFile2 = "c:/temp/temp2.txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFSO2 = CreateObject("Scripting.FileSystemObject")

Set oFile2 = oFSO2.CreateTextFile(sFile2)

Count = 1
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
if Count > 1 then
oFile2.WriteLine (sText)
end if
Count = Count + 1
Loop
oFile.Close
oFile2.Close
End If
End Function

Tks,

Marcelo

Not applicable
Author

Hello Marcelo

As a matter of fact STORE does generate a header. It is supposed to be like that.

It's cumbersome, I know.

Take a look a this post :

http://community.qlik.com/forums/t/22658.aspx

Why dont you do a program that cleans up the header ? Read the file as a string, strip the header and save it back again.

What language do you work with ?

See ya !

Not applicable
Author

Hi, all!

I solved my problem but with a different solution. I used the first line of the file as the label of my table, that will be exported. And loaded to table from second line to the end of the file. The firs line was used by a variable and used to name the unique column of my table. Sorry my english. I don't know if it is clear for you what I did.

Tks,

Marcelo

fernandotoledo
Partner - Specialist
Partner - Specialist

Nice!

Not applicable
Author

Sorry,

not exactly clear on how you managed to get this working

Do you have an example to upload or some code?

Just ran in to the same problem.

Not applicable
Author

Hi,

I presume he's done something along these lines as the below seems to work for me.

------------------------------------------------------------------

Temp:
LOAD * INLINE [
    Number, Letter, Group
    1, a, x
    2, b, x
    3, c, x
    4, d, x
    5, e, x
    1, f, y
    2, g, y
    3, h, y
    4, i, y
    5, j, y
];


let vLabelColumn1 = peek('Number',0,'Temp');
let vLabelColumn2 = peek('Letter',0,'Temp');
let vLabelColumn3 = peek('Group',0,'Temp');

Table:
LOAD Number as '$(vLabelColumn1)',
Letter as '$(vLabelColumn2)',
[Group] as '$(vLabelColumn3)'
RESIDENT Temp
WHERE recno()>1;


DROP TABLE Temp;

STORE Table into [Table.csv] (txt);