private void BtnImport_Click(object sender, EventArgs e)
        {
            var ds = default(DataSet);

            dgWorkbook.DataSource = ds;
            try
            {
                if (ofdExcel.ShowDialog() == DialogResult.OK)
                {
                    switch (ofdExcel.SafeFileName.Substring(ofdExcel.SafeFileName.IndexOf(".") + 1).ToLower())
                    {
                    case "xls":      //ds = DataSetHelper.CreateDataSet(ofdExcel.FileName); break;
                    case "xlsx": ds = ExcelImportExport.ImportExcelODBC(ofdExcel.FileName); break;

                    default:
                        Stream ss = File.OpenRead(ofdExcel.FileName);
                        ds = ExcelImportExport.ImportExcelXML(ss, true, false); break;
                    }
                    foreach (DataTable tabela in ds.Tables)
                    {
                        foreach (DataRow red in tabela.Rows)
                        {
                            string sred = string.Empty;
                            foreach (object polje in red.ItemArray)
                            {
                                sred = sred + polje.ToString().Trim();
                            }
                            foreach (DataColumn kolona in tabela.Columns)
                            {
                                if (red[kolona].ToString() == string.Empty)
                                {
                                    switch (kolona.DataType.Name)
                                    {
                                    case "String":  red[kolona] = ""; break;

                                    case "DateTime": red[kolona] = DateTime.Today; break;

                                    case "Boolean": red[kolona] = false; break;

                                    default: red[kolona] = 0; break;
                                    }
                                }
                            }
                            if (sred.Trim() == string.Empty)
                            {
                                red.Delete();
                            }
                        }
                    }
                    ds.AcceptChanges();
                    dgWorkbook.DataSource = ds;
                    ofdExcel.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void brnLoadExcel_Click(object sender, EventArgs e)
 {
     using (var ofd = new OpenFileDialog())
     {
         try
         {
             if (ofd.ShowDialog() == DialogResult.OK)
             {
                 ds                       = ExcelImportExport.ImportExcelODBC(ofd.FileName);
                 ds.DataSetName           = ofd.SafeFileName.Split('.')[0];
                 ds                       = ObradiDataSet(ds);
                 dgImportExcel.DataSource = ds;
                 rtbJSON.Text             = JsonConvert.SerializeObject(ds, Formatting.Indented);
                 rtbJSON.Text             = rtbJSON.Text.Replace("\\n", "<br/>");
                 rtbJSON.Text             = "var " + ds.DataSetName + "_data=" + rtbJSON.Text + ";";
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }