tags:

views:

51

answers:

1

Hello,

I am using syncfusion to import excel to datattable.when the datat is imported to datatable the columns are all strings .how to convert these columns to specific datatype?how do i validate the column data type?

using Syncfusion.XlsIO;

private void btnImport_Click(object sender, EventArgs e)
        {
            ImportExcelFile();
        }
 private void ImportExcelFile()
        {
            try
            {
                string strFileName = "";
                OpenFileDialog openFileDialog = new OpenFileDialog();

                openFileDialog.Filter = "Files (*.xls)|*.xls|(*.xlsm)|*.xlsm";
                openFileDialog.DefaultExt = ".xls";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    strFileName = openFileDialog.FileName;
                    #region Get Correct Worksheet in excel file
                    DateTime dtStart = DateTime.Now;
                    ExcelEngine excelEngine = new ExcelEngine();
                    IApplication application = excelEngine.Excel;
                    IWorkbook workbook = application.Workbooks.Open(strFileName);
                    IWorksheet sheet = workbook.Worksheets[0];
                    #endregion                


                    DataTable dt = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames);

                  dgIDCImport.GridDataSource(dt,ucGrid.GridTypes.IDCImport);

                    //Close the workbook.
                    workbook.Close();

                    //No exception will be thrown if there are unsaved workbooks.
                    excelEngine.ThrowNotSavedOnDestroy = false;
                    excelEngine.Dispose();



                }
            }

            catch (Exception err)
            {
                base.DisplayError(err);
            }
        }
A: 

Instead of ColumnNames use DetectColumnTypes like below.

ExcelExportDataTableOptions.DetectColumnTypes

HTH

Avatar
we are using the following version 4.102.0.58 and DetectColumnTypes is not added in this version.Is there nay other way to do this?
xrx215
Ho. I'm afraid. Try checking with them. I used very recent version of their product. So, no clue!
Avatar