on 2016 Feb 18 3:28 PM
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 |
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 ("").
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
User | Count |
---|---|
71 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.