Export CSV with specific delimiters
We are currently using the export functionality of the SfGrid and are doing a CSV export with ExcelExportProperties.
Is there any way to select which delimiter is used between fields? It seems the export is always using commas and I can't find a way to change this to semicolons.
How can I do this?
SIGN IN To post a reply.
10 Replies
1 reply marked as answer
VN
Vignesh Natarajan
Syncfusion Team
June 19, 2020 07:34 AM UTC
Hi Andreas,
Thanks for contacting Syncfusion support.
Query: “Is there any way to select which delimiter is used between fields?”
As we are quite unclear about your requirement, we need some more details about your requirement. So kindly share the following details
- You have mentioned that delimiter between fields. Can you please more details about your requirement.
- Share your Grid code example along with your CSV export codes.
- Can you please share the your requirement with help of a screenshot
- If possible try to reproduce the existing behavior in below sample
Above requested details will be helpful for us to validate the reported issue at our end and provide solution as soon as possible.
Regards,
Vignesh Natarajan
AO
Andreas Oelke
June 19, 2020 09:45 AM UTC
Well, I don't think it's that complicated.
Currently our csv export file looks like this:
Landes-ID,Lieferanten-Nr.,Zähler,Bestellferien von,Bestellferien bis,Lieferantenferien von,Lieferantenferien bis
6,2137,5397,01.06.2020,15.06.2020,01.01.2021,15.01.2021
6,2137,5559,01.12.2020,15.12.2020,16.12.2020,28.12.2020
but we want to have it like this:
Landes-ID;Lieferanten-Nr.;Zähler;Bestellferien von;Bestellferien bis;Lieferantenferien von;Lieferantenferien bis
6;2137;5397;01.06.2020;15.06.2020;01.01.2021;15.01.2021
6;2137;5559;01.12.2020;15.12.2020;16.12.2020;28.12.2020
So just a ";" where there's a "," delimiter.
We are using the CsvExport method of the SfGrid.
DA
Dan
June 21, 2020 06:40 PM UTC
I saw the headline and knew exactly what the OP was talking about. It really is not that complicated. Not impressed at all with support here.
VN
Vignesh Natarajan
Syncfusion Team
June 23, 2020 02:23 AM UTC
Hi Andreas,
Thanks for the update.
Query: “Is there any way to select which delimiter is used between fields?”
No, we do not have support to change the delimiter used between fields while exporting the Grid data to CSV format.
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
AO
Andreas Oelke
June 23, 2020 05:45 AM UTC
Well that's not a very helpful feature to just be able to export one static CSV without the possibility to modify its details.
What about the advertised Blazor Excel Framework? I'm sure this can be done with that if not with the integrated Grid-functionality?
So how do I go about exporting to CSV with my own delimiters using your Excel Framework?
VN
Vignesh Natarajan
Syncfusion Team
June 24, 2020 10:58 AM UTC
Hi Andreas,
Thanks for the update.
Query: “Well that's not a very helpful feature to just be able to export one static CSV without the possibility to modify its details”
As a workaround to your requirement, we have achieved your requirement by exporting the Grid data to csv with different delimiter. We have used Syncfusion ASP.NET Core method to export the data to CSV file with (;) semicolon delimiter.
Refer the below code example.
|
@using Syncfusion.XlsIO;
@using System.IO;
@inject IJSRuntime Runtime;
<SfButton OnClick="CsvExport" Content="CSV Export"></SfButton>
<SfGrid @ref="DefaultGrid" DataSource="@Orders" AllowSorting="true" AllowExcelExport="true" AllowPaging="true">
. .. .. . . . .
</SfGrid>
@code{
private SfGrid<Order> DefaultGrid;
public List<Order> Orders { get; set; }
public async void CsvExport()
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Import the data to worksheet
IList<Order> reports = Orders; // pass the datasoruce to csvexport
worksheet.ImportData(reports, 2, 1, true);
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream,";"); // save the workbook with different delimiter
//to download the memory stream as file
await Runtime.InvokeVoidAsync("exportSave", new object[] { "export.csv", Convert.ToBase64String(stream.ToArray()) });
}
}
}
[export.js]
|
Note: above solution is a workaround so that is has some limitations.
Kindly download the sample from below
Refer the below UG documentation for your reference
Please get back to us if you have further queries.
Regards,
Vignesh Natarajan
Marked as answer
AO
Andreas Oelke
June 30, 2020 11:46 AM UTC
Thanks for your example.
This works so far but when using a datasource with more than 18 fields worksheet.ImportData throws an ArgumentOutOfRangeException.
We can use it fine with under 18 fields. So this is probably a bug on your side.
VN
Vignesh Natarajan
Syncfusion Team
July 1, 2020 08:24 AM UTC
Hi Andreas,
Thanks for the update.
Query: “This works so far but when using a datasource with more than 18 fields worksheet.ImportData throws an ArgumentOutOfRangeException.”
As per your suggestion, we have prepared a sample with 20 columns and we are not able to reproduce the reported issue at our end. Kindly download the sample from below
After referring the sample, if you are still facing the issue. kindly get back to us with following details.
- Share the Grid rendering code example.
- Share the details about your Datasource (columns and records count).
- If possible share the issue reproducible sample or reproduce the reported issue in provided sample.
- Share the exception details with screenshot.
- Share your Syncfusion Nuget package version.
Above requested details will be helpful for us to validate the reported issue at our end and provide solution as soon as possible.
Regards,
Vignesh Natarajan
AO
Andreas Oelke
July 6, 2020 05:28 AM UTC
Your example works and I found out that it seems the reason for the Exception is because we're using a list of Expando objects which we pass to the ImportData method to make it dynamic for every of our grid lists..
This works fine as long as no value is null. We worked around this now by setting null values to empty strings.
This works fine as long as no value is null. We worked around this now by setting null values to empty strings.
VN
Vignesh Natarajan
Syncfusion Team
July 7, 2020 04:29 AM UTC
Hi Andreas,
Thanks for the update.
We are glad to hear that you have resolved your issue on your own.
Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 10 Replies
- 3 Participants
- Marked answer
-
AO Andreas Oelke
- Jun 18, 2020 12:01 PM UTC
- Jul 7, 2020 04:29 AM UTC