Read Excel and pass it to a datatable keeping format

0

Dear, I have a query, I am trying to read an excel but the file is corrupt with a specific format but I do not have an office installed on the server, so I have to read it with closed xml and pass it to a datatable (For that reason I can not instantiate it directly from oledb because it tells me that the table is not in the expected format) this is solved by opening the excel and closing it with interop I have it ready it opens and I save it in excel format and then I can read it without problems with oledb. but when I open it with closedxml and I do a SaveAs () exactly as I do in interop to stop being corrupt, this file remains corrupt (The message of excel is enable editing) and when I save it with interop this message appears in the top part disappears and I can work without problems with it. The issue is that nose if closedxml has the option to open it and make a SaveAs () making this message disappear. or finally pass it to a datatable but keeping its format that is keeping the empty columns etc that is exactly the same because the reading is already programmed and would change everything.

My C # code

// Con ClosedXML

 if (File.Exists(path + "\" + nombre_punto.ToString().ToUpper() + nombre_archivo.ToString()))
                {
                    //string fileName = "C:\Folder1\Prev.xlsx";
                    var wb = new XLWorkbook(path + "\" + nombre_punto.ToString().ToUpper() + nombre_archivo.ToString());
                   // Workbook wb = excel.Workbooks.Open(path + "\" + nombre_punto.ToString().ToUpper() + nombre_archivo.ToString());
                    wb.SaveAs(@"C:\Users\Archivos\" + nombre_punto.ToString() + ".xlsx");
                    wb.Dispose();
                    break;
                }

//Con interop



if (File.Exists(path + "\" + nombre_punto.ToString().ToUpper() + nombre_archivo.ToString()))
                    {
                        ExcelPackage wb = new ExcelPackage(new FileInfo(path + "\" + nombre_punto.ToString().ToUpper() + nombre_archivo.ToString()));
                        wb.Workbook.Worksheets.Add("Sheet1");


                        wb.Save(@"C:\Users\Archivos\" + nombre_punto.ToString() + ".xlsx");
                        wb.Dispose();
                        break;
                    }

Message protected view

File to keep format

    
asked by Joel Baez 05.12.2018 в 14:03
source

0 answers