Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Ribeiro
Specialist
Specialist

Exportar txt com cabeçalho e data no arquivo via macro

Lembrando que este exemplo abaixo: já está funcionando é da comunidade,

E gostaria de inserir o cabeçalho nele.

Cabeçalho,

Exemplo como eu gostaria:

Certo:

1-Cabeçalho

Volume;Atual;Vendas;Saldo

1;2;3;4

2-Data no arquivo

Hoje é e salvo

C:\exportar\test2.txt

Eu gostaria:

C:\exportar\exportar14032017.txt



Alguma dica?

Sem título.png

Como está a macro hoje: funciona 100%

sub ExportChartToCustomDelimitedFile 

'exports a chart to a semicolon or other user specified delimited file

'removing as many headers as specified at the same time

'constants

output_dir="C:\exportar\"

FileType=".txt" 'csv or txt has been tested and works correctly

Filename1="test1" & FileType

Filename2="test2" & FileType

HeaderRows=2

Delimiter=";"

StartDateTime=now()

'exporting chart to file with headers

set obj = ActiveDocument.GetSheetObject("CH06")

obj.Export (output_dir & Filename1) , Delimiter

'opening chart file with headers

Set objFSO1 = CreateObject("Scripting.FileSystemObject")  

set textFile1 = objFSO1.GetFile(output_dir & Filename1)

set textStream1 = textFile1.OpenAsTextStream(1)

'opening or creating chart file with no headers

Set objFSO2 = CreateObject("Scripting.FileSystemObject")  

If not objFSO2.FileExists (output_dir & Filename2) then

  Set newTextFile = objFSO2.CreateTextFile(output_dir & Filename2, True)

  newTextFile.Close

  Set newTextFile = nothing

End if

set textFile2 = objFSO2.GetFile(output_dir & Filename2)

set textStream2 = textFile2.OpenAsTextStream(2)

'removing header rows

for i = 1 to HeaderRows

  textStream1.SkipLine()

Next

'read lines from file 1 and write them to file 2

do while textStream1.AtEndOfStream = false

  textStream2.WriteLine(textStream1.ReadLine())

loop

'clean up

textStream1.Close

textStream2.Close

textFile1.Delete

Set objFSO1 = nothing

set textFile1 = nothing

set textStream1 = nothing

Set objFSO2 = nothing  

set textFile2 = nothing

set textStream2 = nothing

msgbox("Start Time : " & StartdateTime & chr(13) & "End Time   : " & now())

end sub

Neves
1 Solution

Accepted Solutions
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Nome = "Arquivo" & replace(date(),"/","") & ".txt"

2017-03-14 21_25_51-QlikView x64 - [C__tmp_Parcela.qvw_].png

furtado@farolbi.com.br

View solution in original post

3 Replies
Ribeiro
Specialist
Specialist
Author

Na parte do cabeçalho conseguir resolver,

Onde está

HeaderRows=2 

passar:

HeaderRows=0 


Agora vou atrás de colocar a data no arquivo exportar01011980.txt

Que fica aqui:

Filename1="test1" & FileType


Alguma dica:

Neves
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Nome = "Arquivo" & replace(date(),"/","") & ".txt"

2017-03-14 21_25_51-QlikView x64 - [C__tmp_Parcela.qvw_].png

furtado@farolbi.com.br
Ribeiro
Specialist
Specialist
Author

Obrigado Pelo Alessandro,

Beleza 100%

Neves