Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 909
  • Last Modified:

How to export to CSV file from Crystal Report 2008

I have a CR 2008 report which selects a record for 'parents contact details' from a SQL view. Details section Da will display father details and details section Db will display mother details from the one record in the view. Detail section a or b are conditionally suppressed if there are no details for either father or mother so no blank records are exported to the CSV file.
Two problems here, when I export to CSV file the Db section will be on the same line as the Da section instead of on the next line. Also for each section that has been suppressed I still get the comma seperators eg:  ,,,,   for each field on that suppressed record. I rushed out to buy CR 2008 because I was told this would do the export to CSV much better than CR10, this is becoming critical and I still have problems .
thanks for any assistance you can give.....
0
judeb1397
Asked:
judeb1397
  • 2
1 Solution
 
mfhorizonCommented:
Hi judeb1397,

CVS is a good format for different puposes but most of the time user need to do some formatting for it.
I have designed couple of software products where we need to customize same report in direct excel. You can find a very good VB 6 or .Net code to generate direct excel report from your software.
The code is available in a Tutorial at http://www.codeguru.com/vb/gen/vb_misc/tips/article.php/c8227

Hope it will help you out for this kind of problem.
Regards

Public Sub GenerateReport(prmTemp As ADODB.Recordset, _
                          prmPage As String, prmCol  As String, _
                          prmRow  As String, prmData As String, _
                          prmFile As String)
 
On Error GoTo Err_GenerateReport
   'VARIABLE DECLARATION
   Dim xlApp    As Excel.Application
   Dim xlBook   As Excel.Workbook
   Dim xlSheet  As Excel.Worksheet
   Dim xlSheet1 As Excel.Worksheet
   Dim rstemp   As ADODB.Recordset
   Dim intX     As Integer
   Dim intY     As Integer
   Set xlApp    = New Excel.Application
   Set xlBook   = xlApp.Workbooks.Add
   Set xlSheet  = xlBook.Worksheets.Add
   xlSheet.Name = "Pivot"
 
   Set rstemp = prmTemp
 
   'DUMP THE RECORDSET TO EXCEL
   For intY = 0 To rstemp.Fields.Count - 1
      xlSheet.Cells(intX + 1, intY + 1).Value = _
         rstemp.Fields(intY).Name
   Next intY
 
 
   intX = intX + 1
   While Not rstemp.EOF
      For intY = 0 To rstemp.Fields.Count - 1
         xlSheet.Cells(intX + 1, intY + 1).Value = _
            rstemp.Fields(intY).Value
      Next intY
      rstemp.MoveNext
      intX = intX + 1
   Wend
 
   'DATA DUMPED, SO WE HAVE THE DATA ON WHICH TO PIVOT
 
   'ADDING A NEW WORKSHEET FOR THE PIVOT TABLE
   Set xlSheet1  = xlBook.Worksheets.Add
   xlSheet1.Name = "Report"
 
   'CREATING THE PIVOT TABLE
   xlBook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
      "Pivot!R1C1:R" & rstemp.RecordCount + 1 _
      & "C" & rstemp.Fields.Count).CreatePivotTable _
      TableDestination:=xlSheet1.Range("A9"), _
      TableName:="PivotTable1"
 
   xlSheet1.PivotTables("PivotTable1").SmallGrid = False
 
   'SETTING THE PAGE LEVEL FIELDS FROM THE PARAMETERS PASSED
   If Len(prmPage) > 0 Then
      For intX = 1 To Len(prmPage)
         With xlSheet1.PivotTables("PivotTable1").PivotFields( _
            rstemp.Fields(CInt(Mid$(prmPage, intX, 1))).Name)
            .Orientation = xlPageField
            .Position = intX
         End With
      Next intX
   End If
 
   'SETTING THE COL LEVEL FIELDS FROM THE PARAMETERS PASSED
   If Len(prmCol) > 0 Then
      For intX = 1 To Len(prmCol)
         With xlSheet1.PivotTables("PivotTable1").PivotFields( _
            rstemp.Fields(CInt(Mid$(prmCol, intX, 1))).Name)
            .Orientation = xlColumnField
            .Position = intX
         End With
      Next intX
   End If
 
   'SETTING THE ROW LEVEL FIELDS FROM THE PARAMETERS PASSED
   If Len(prmRow) > 0 Then
      For intX = 1 To Len(prmRow)
         With xlSheet1.PivotTables("PivotTable1").PivotFields( _
            rstemp.Fields(CInt(Mid$(prmRow, intX, 1))).Name)
            .Orientation = xlRowField
            .Position = intX
         End With
      Next intX
   End If
 
   'SETTING THE DATA FIELDS FROM THE PARAMETERS PASSED
   If Len(prmData) > 0 Then
      For intX = 1 To Len(prmData)
         With xlSheet1.PivotTables("PivotTable1").PivotFields( _
            rstemp.Fields(CInt(Mid$(prmData, intX, 1))).Name)
            .Orientation = xlDataField
            .Position = 1
         End With
      Next intX
   End If
   'HIDING THE PIVOTTABLE COMMANDBAR
   xlApp.CommandBars("PivotTable").Visible = False
 
   xlSheet1.Cells.EntireColumn.AutoFit
   xlSheet1.Range("A1").Select
   xlApp.DisplayAlerts = False
   'DELETING THE SHEET WITH THE SOURCE DATA - SO THAT NO ONE
   'CAN MODIFY
   xlSheet.Delete
   xlApp.DisplayAlerts = True
   xlSheet1.Range("A1").Select
 
   'SAVING THE EXCEL SHEET
   xlBook.SaveAs prmFile
   xlApp.Visible = True
 
 
Exit_GenerateReport:
   'xlBook.Close
   Set xlApp    = Nothing
   Set xlBook   = Nothing
   Set xlSheet  = Nothing
   Set xlSheet1 = Nothing
   Set rstemp   = Nothing
   Exit Sub
 
Err_GenerateReport:
   xlBook.Close
   Set xlApp    = Nothing
   Set xlBook   = Nothing
   Set xlSheet  = Nothing
   Set xlSheet1 = Nothing
   Set rstemp   = Nothing
   Err.Raise vbObjectError + 1500, "modReport.GenerateReport", _
      Err.Description
 
End Sub

Open in new window

0
 
peter57rCommented:
I don't see anything wrong with what CR is doing- indeed it seems to me that it is behaving exactly as it should be.
In creating the output file it is preserving the true record structure and ensuring that there is a placeholder for every field in the record.  For most situations these would be pretty fundamental requirements.

 I guess that means you will have to do some additional work to get the file you require. One option would be to export the data to Excel - which will preserve the layout- and then create your text file from Excel.

0
 
judeb1397Author Commented:
Thanks mfhorizon/peter57r, I was going to use VisualCUT to automate this export to CSV as I need it to be automated and I need it to be in CSV format with not blank records for an automated upload. You are correct when it is exported to Excel first then the data is fine. I am getting a little out of my depth with the VB 6 & .NET code option but I will explore this further..
0
 
judeb1397Author Commented:
I am sorry for the delay getting back to this, I have been on leave. I have managed to find my own solution using Visual CUT to export to seperate files, one for the father details and one for the mother details and then using the Visual CUT command line argument (TXT_Merge) to append the export from the 2nd report to the export from the first report. This may be a little clunky but more within my capabilities. Thank you very much for your suggestions
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now