ImportDataGridView turns string into date

Hello,

i'm using ImportDataGridView to write a DataGridView to xlsx.

                        using (ExcelEngine excelEngine = new ExcelEngine())
                        {
                            //Initialize Application
                            IApplication application = excelEngine.Excel;

                            //Set default version for application
                            application.DefaultVersion = ExcelVersion.Excel2013;

                            //Create a new workbook
                            IWorkbook workbook = application.Workbooks.Create(1);

                            //Accessing first worksheet in the workbook
                            IWorksheet worksheet = workbook.Worksheets[0];

                            //Import data from DataGridView control
                            worksheet.ImportDataGridView(dataGridView, 1, 1, true, true);

                            //Save the workbook
                            workbook.SaveAs(sfd.FileName);

                        }

All columns are type of string.

How can I prevent conversion to date?

ImportDataGridView.jpg

Best Regards

Christoph



3 Replies

CH Christoph February 8, 2025 08:35 AM UTC

Sorry for asking ;-) It was a Globalization issue. csv from Switzerland (Point as delimiter) to Datagridview to xlsx on a German Windows (Comma!). So 22.6 was turned into 22.06.2025 (Point is Date separator. Sometimes .ToString(InvariantCulture) can be a bad habbit.



AS Atchaya Sekar Syncfusion Team February 11, 2025 05:15 PM UTC

Hi Christoph,

 

We are currently checking this scenario and will share further details by tomorrow (February 12, 2025).

 

Regards,

Atchaya S.



AH Alex Harson James Henso Syncfusion Team February 12, 2025 04:19 PM UTC

Hi Christoph,

 

We were unable to identify the exact issue based on the provided details. We have attached a simple sample for your reference. Could you kindly share the input file to help us better understand and illustrate the scenario.

 

Regards,

Alex Harson James H


Attachment: DataGridView_to_Worksheet_1bf2f706.zip

Loader.
Up arrow icon