I believe that there is a lot of discussion on this issue. but I read all the messages and try, but it never works with C #. my goal is simple that I have an existing csv file. just want to convert exel file and do. many have said that using spire.xls is something, but I believe that MS.office.interop.excel can handle this.
Convert Excel file from .csv to .xlsx
I read above and this is the same as my problem. but the above code does not work on my pc .. i need to import another dll to use this. I am just copying the code from this site. copy again ...
currently im using lib as MS.office.interop.excel and MS.office.interop.core
Application app = new Application(); Workbook wb = app.Workbooks.Open(@"C:\testcsv.csv", 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); wb.SaveAs(@"C:\testcsv.xlsx", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); wb.Close(); app.Quit();
here are a lot of mistakes. change the code below and now im only using MS.office.interop.excel and MS.office.interop.core in my link. it seems i need to use another dll file. anyway I made this code and am creating new code. this reduces the error, but I do not know what is the right approach. below is what i tried now.
Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkBook = xlApp.Workbooks.Open(@"C:\testcsv.csv", 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); xlWorkBook.SaveAs(@"C:\testcsv.xlsx", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); xlWorkBook.Close();
and here is the error message
// Error 3 The name 'XlFileFormat' does not exist in the current context C:\Users\jochoi\Desktop\joseph_BT_μ λ₯_code\DC_Test - ver01\DC_Test\DC.cs 528 54 DC_Test // Error 4 The name 'XlSaveAsAccessMode' does not exist in the current context C:\Users\jochoi\Desktop\joseph_BT_μ λ₯_code\DC_Test - ver01\DC_Test\DC.cs 528 142 DC_Test // Error 4 No overload for method 'Close' takes '0' arguments C:\Users\jochoi\Desktop\joseph_BT_μ λ₯_code\DC_Test - ver01\DC_Test\DC.cs 525 13 DC_Test
My goal is to just grab the existing csv file and just modify the excel file. someone has a different solution because this answer does not work on my computer. (FROM#)