Not getting excel data

248 views Asked by At

I need to format excel data and then add it to database. I have file in xls format and direct importing it to database is returning date/time column in wrong format. After converting into xlsx its format is in correct format. But when i convert xls to xlsx from my code . It is returning null in stream. Any idea? Here is my code

var path = String.Format("{0}\\attendance", System.Environment.CurrentDirectory);

        Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
        excelApp.Visible = false;

        Microsoft.Office.Interop.Excel.Workbook eWorkbook = excelApp.Workbooks.Open(path+".xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

        eWorkbook.SaveAs(path+".xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

        eWorkbook.Close(false, Type.Missing, Type.Missing);

        FileStream stream = File.Open(path+".xlsx", FileMode.Open, FileAccess.Read);

        IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
      //  stream.Close();

        excelReader.IsFirstRowAsColumnNames = true;
        DataSet _ds = excelReader.AsDataSet();
0

There are 0 answers