Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Impromptu to CSV with no Column Headers

Status
Not open for further replies.

AndyFreeman

IS-IT--Management
Mar 22, 2004
70
GB
Hi

Hi i am trying to create a Macro to save a imprumptu report out to a CSV format file.
I then want to exclude column headers. Within Imp. i would go into the save as "options" box and un-tick the box

Is there anyway to do this via Macro's

Thanks in advance

Andy
 
This Macro will


- create an instance of Impromptu
- open the catalog
- open the report
- export the report to ASCII (csv file)
- close the report
- close Impromptu
- Open the CSV file
- Read the contents of the CSV file and write out all lines except line 1 (titles)

=============================================================

Sub Main()

Dim objImpApp As Object
Dim objImpRep As Object
Dim textfile As String
Dim Targetfile as String
Dim X as Integer
Dim aline as String

Set objImpApp = CreateObject("CognosImpromptu.Application")

objImpApp.OpenCatalog "C:\Cognos\Catalogs\Test_Catalog_1.cat", "Creator"

Set objImpRep = objImpApp.OpenReport("C:\Cognos\Reports\Test_Report_1.imr")

objImpRep.Export "C:\Cognos\CSV Files\Test_CSV_Output.csv", "x_ascii.flt"

objImpRep.CloseReport
objImpApp.Quit

Set objImpRep = Nothing
Set objImpApp = Nothing


txtfile="C:\Cognos\CSV Files\Test_CSV_Output.csv"
Open txtfile For Input As #1

targetfile="C:\Cognos\CSV Files\Target_CSV_Output.csv"
Open targetfile For Append As #2

x = 0

Do while not eof(1)
Line input #1, aline
x=x+1
if x <> 1 then
write #2, aline
endif


Loop

close #1
close #2

EndSub


Think this should work - can't check systax since I'm not on a machine with the macro editor installed
 
Most of what goldsmt is fine - but there is a function .ExportASCII
So instead of:
objImpRep.Export "C:\Cognos\CSV Files\Test_CSV_Output.csv", "x_ascii.flt"

use:
ObjImpRep.ExportASCII "C:\Cognos\CSV Files\Test_CSV_Output.csv", False
If you use Help, you'll see that there are 3 other parameters available : [,UseQuotes] [,Delimiter] [,EOL]

This means the code can stop at
Set objImpApp = Nothing

Simon Rouse

 
Thanks DrSimon

Nice call, have not come accross the function before, you learn somthing every day

Regards

Tony Goldsmith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top