cancel
Showing results for 
Search instead for 
Did you mean: 

How to used a blank delimiter when exporting CSV

Former Member
0 Kudos
712

Hello,

I would like to export crystal report into csv but withouter a delimter character around fields,

here is a snipper of my code:


ExportOptions exportOpts = new ExportOptions();

exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;

exportOpts.ExportFormatType = ExportFormatType.CharacterSeparatedValues;

DiskFileDestinationOptions DiskFileDestinationOpt = ExportOptions.CreateDiskFileDestinationOptions();

DiskFileDestinationOpt.DiskFileName = filename;

exportOpts.ExportDestinationOptions = DiskFileDestinationOpt;

CharacterSeparatedValuesFormatOptions csvOptions = new CharacterSeparatedValuesFormatOptions();

csvOptions.Delimiter = "";

csvOptions.SeparatorText = "";

exportOpts.ExportFormatOptions = csvOptions;

crystalReportDoc.Export(exportOpts);

the problem is whenever I use an empty string for the delimiter property, crystal report will use the default double quote character in the result csv file.

can someone please assist on how to export a csv document with a blank delimiter?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Toto,

If you export from the viewer is it capable?

And if you set the export options for the report does that work:

You can then get/set those options as well

if (ExportTypeSelected == "crReportExportFormatCharacterSeparatedValues")

#region CSV

{

    // This works do not alter

    // this gets the report name and sets the export name to be the same less the extension

    string outputFileName = "";

    string MyRptName = rpt.FileName.ToString();

    outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);

    outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "csv";

    try

    {

        if (File.Exists(outputFileName))

        {

            File.Delete(outputFileName);

        }

        //CrystalDecisions.ReportAppServer.ReportDefModel. RasRTFExpOpts = new RTFWordExportFormatOptions();

        CrystalDecisions.ReportAppServer.ReportDefModel.CharacterSeparatedValuesExportFormatOptions RasCSVExpOpts = new CharacterSeparatedValuesExportFormatOptions();

        try

        {

            RasCSVExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatCharacterSeparatedValues);

        }

        catch (Exception ex)

        {

            btnSQLStatement.Text = "ERROR: " + ex.Message;

            //return;

        }

        // Set them now:

        RasCSVExpOpts.Delimiter = ",";

        //RasCSVExpOpts.ReportSectionsOption

        // Save the udpated info

        if (RasCSVExpOpts != null)

            rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatCharacterSeparatedValues, RasCSVExpOpts);

        CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();

        exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatCharacterSeparatedValues;

        exportOpts1.FormatOptions = RasCSVExpOpts;

        // And Export

        rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);

        MessageBox.Show("Export to CSV Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    catch (Exception ex)

    {

        btnSQLStatement.Text = "ERROR: " + ex.Message;

        return;

    }

}

#endregion CSV

Don

Former Member
0 Kudos

Hi Don, thank you for your reply, unfortunately I don't have access to SAP designer (I sue the visual studio version)

I very much appreciate it if you can send me the rpt file you created with those exports settings.

Toto

0 Kudos

Did you try the code?

RasCSVExpOpts.Delimiter = "#$%";

or

RasCSVExpOpts.Delimiter = null;

or

RasCSVExpOpts.Delimiter = "";

Don

Former Member
0 Kudos

RasCSVExpOpts.Delimiter = "#$%";


the above do replaces the string fields delimiter with #$%


I tried everything else to remove the default doublel quote and nothing worked:


RasCSVExpOpts.Delimiter = null;

RasCSVExpOpts.Delimiter = "";

RasCSVExpOpts.Delimiter = "\0";


I am stuck !!

0 Kudos

Hi Toto,

I tried exporting from CR Designer using nothing for the Delimiter and Separator by hitting the backspace key to remove the character. Problem is the data becomes unusable.

Open the CSV file in notepad:

1003Order IDOrder AmountCustomer IDEmployee IDOrder DateRequired DateShip Via1$41.901112/2/2000  12:00:00AM12/15/2000  12:00:00AMUPS

So this request is not correct... You must use a separator of some kind...

So how about this:

RasCSVExpOpts.Delimiter = " "; // space bar between double quotes

RasCSVExpOpts.Separator = " "; // space bar between double quotes
Former Member
0 Kudos

Hey Don

The space bar character does work. unfortunately what I want is to completely remove any character  (including spaces) around the csv fields (which seems possible through the designer interface)

anyone think this could be a bug in the SAP sdk ?

ido_millet
Active Contributor
0 Kudos

There's at least one 3rd-party Crystal Reports desktop scheduler (see list at http://kenhamady.com/bookmarks.html) that allows you to automatically export and also search & replace characters in the resulting file. 
You can do the same in your own code (use a special character for your delimiter, and replace it with a blank ("").

0 Kudos

Hi Toto,

Yes there is a difference and it appears to be ignoring the "", I'll have to check with DEV to find out why it is different than CRD and escalate for a fix in SP 17.

Thanks again

Don

UPDATE:

Case - Incident 124684 / 2016 / Exporting to CSV in .NET app wrong

KBA - 2283350 - Exporting to CSV in .NET application and setting the delimiter and separator to nothing defaults to a comma and double quote

Former Member
0 Kudos

Thank you.

Answers (0)