Hallo,
ich habe mir eine Methode geschrieben, um einen Crystal Report in eine "CSV"-txt-Datei zu wandeln.
// neue instanz für CSV Export erstellen
CharacterSeparatedValuesFormatOptions csvformat = ExportOptions.CreateCharacterSeparatedValuesFormatOptions();
// nutze ; als trennzeichen
csvformat.SeparatorText = ";";
// Fuß- und Kopfzeile nur 1 mal ausgeben
csvformat.ReportSectionsOption = CsvExportSectionsOption.ExportIsolated;
//Exportoptionen auf Standard setzen
csvformat.ExportMode = CsvExportMode.Standard;
DiskFileDestinationOptions exportpfad = new DiskFileDestinationOptions();
// den Dateiname übergeben
exportpfad.DiskFileName = open1.FileName;
ExportOptions exportEinstellung = new ExportOptions();
// welches format soll erstellt werden(csv)
exportEinstellung.ExportFormatType = ExportFormatType.CharacterSeparatedValues;
// wohin soll der export abgelegt werden (DiskFile)
exportEinstellung.ExportDestinationType = ExportDestinationType.DiskFile;
// Exportpfad übergeben
exportEinstellung.ExportDestinationOptions = exportpfad;
exportEinstellung.ExportFormatOptions = csvformat;
// export an dokument übergeben
rpdokument.Export(exportEinstellung);
string meldung_lieferant = MsgCommon.ExportFileSavedTarget + "\n" + open1.FileName;
MessageBox.Show(meldung_lieferant, "", MessageBoxButtons.OK);
}
catch (Exception ex)
{
EdLog.DoLog("Fehler beim Export von Lieferant", ex);
MessageBox.Show(MsgCommon.CSVExportError);
}
Die Textdatei sieht gut aus, aber in der CSV-Datei habe ich(ich habe einfach die *.txt in *.csv umbenannt),
wenn ich die mit Excel öffne, immer statt "Strasse" -> "Straße" zu stehen.
Kann Crystal das automatisch wandeln oder liegt das an den Einstellungen in Excel ?
Hallo,
danke für die Antwort.
Das mit dem Encoding hat nicht geholfen, ich habe alle Encodings getestet.
in der *.txt sehe ich "Straße" korrekt.
Speichere ich die txt-Datei unter test.csv und öffne die dann mit Excel, dann habe ich wieder 1"Straße" zu stehen.
string path = @"C:\lief1.csv";
string content = File.ReadAllText(path, Encoding.Default);
MessageBox.Show(content);
MessageBox.Show(Encoding.Default.ToString());
string path2 = @"C:\lief2.csv";
File.WriteAllText(path2, content, Encoding.Utf8);
folgende Umwandlung hat geholfen...
Ich öffne die txt-Datei mit UTF8-Encoding und speichere dann die Datei mit Encoding.Default ab.
Das ist zwar keine elegante Lösung, hat aber geholfen.
// Textdatei formatieren,um auch Umlaute in Excel darzustellen
string path = open1.FileName;
string content = File.ReadAllText(path, Encoding.UTF8);
MessageBox.Show(content);
MessageBox.Show(Encoding.Default.ToString());
string path2 = open1.FileName;
File.WriteAllText(path2, content, Encoding.Default);
MessageBox.Show(content);