Click to See Complete Forum and Search --> : Exporting RPT to CSV
zusulik
March 18th, 2008, 12:48 PM
Hello gurus,
I'm having a problem exporting an RPT file to CSV.
The data arrangement is fairly straignt forward:
<Type1> <Value1>
<Type2> <Value2>
<Type3> <Value3>
...
Each <Type> is a group and <Value> is a count of certain elements in that gorup. There is no 'Details' or 'Footer' section.
When I export this to CSV I get:
<Type1> <Value1>
<Type1> <Value1>
<Type1> <Value1>
<Type1> <Value1>
... repeated value1 times...
<Type2> <Value2>
<Type2> <Value2>
... etc
What am I doing wrong?
HairyMonkeyMan
March 18th, 2008, 12:59 PM
What I do is create the datatable and bind it to the report. Then when I need a csv, I just passthe datatable to the following routine:
Public Sub ConvertToCSV(ByVal ConvertDataTable As DataTable, ByVal FileName As String, _
Optional ByVal Append As Boolean = False)
Dim swConvert As New System.IO.StreamWriter(FileName, Append)
Dim strRow As String = ""
If Not Append Then
For count As Integer = 0 To ConvertDataTable.Columns.Count - 2
strRow += """" & ConvertDataTable.Columns(count).ColumnName & ""","
Next
strRow += """" & ConvertDataTable.Columns(ConvertDataTable.Columns.Count - 1).ColumnName & """"
swConvert.WriteLine(strRow)
strRow = ""
End If
For Each row As DataRow In ConvertDataTable.Rows
For count As Integer = 0 To ConvertDataTable.Columns.Count - 2
If ConvertDataTable.Columns(count).DataType.Name = "String" Then
strRow += """" & row(count).ToString & ""","
Else
strRow += row(count).ToString & ","
End If
Next
strRow += row(ConvertDataTable.Columns.Count - 1).ToString
swConvert.WriteLine(strRow)
strRow = ""
Next
swConvert.Close()
End Sub
zusulik
March 18th, 2008, 01:07 PM
Thanks for your reply.
I'm not big on programming in CR... is ther an easier way?
HairyMonkeyMan
March 18th, 2008, 01:07 PM
which way are you doing it at present?
zusulik
March 18th, 2008, 01:08 PM
File->Export
Choose CSV format follow instructions.
HairyMonkeyMan
March 18th, 2008, 01:17 PM
Maybe someone with more experience could offer some better advice..
To me, it sounds like it is printing out the right number of elements (1 per row from your datasource). I would get your dbms to do the counting and only pass in the distinct rows with counted the values. Maybe there is some way to group your results by distinct values inside crystal.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.