![]() ![]() Usage : var excelFilePath = Console.ReadLine() StreamWriter csv = new StreamWriter(destinationCsvFilePath, false) Var ds = reader.AsDataSet(new ExcelDataSetConfiguration()ĬonfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()įor (int i = 0 i < ds. i )Īrr.Add(ds.()) ĬsvContent = string.Join(",", arr) "\n" Reader = ExcelReaderFactory.CreateOpenXmlReader(stream) Reader = ExcelReaderFactory.CreateBinaryReader(stream) Įlse if (excelFilePath.EndsWith(".xlsx")) Using (var stream = new FileStream(excelFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) Public static bool SaveAsCsv(string excelFilePath, string destinationCsvFilePath) ThisCell.Value2 = "This is a .XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, .XlSaveAsAccessMode.xlShared, Type.Missing, Type.Missing, Type.Missing, Type.Missing, .XlFileFormat.xlCSVWindows, Type.Missing, Type.Missing, Type.Missing, Type.Missing, .XlSaveAsAccessMode.xlShared, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing) Range thisCell = (.Range)CurSheet.Cells Worksheet CurSheet = (.Worksheet)wsSheet Application app = new .ApplicationClass() Or following: public static void SaveAs() wbWorkbook.SaveAs("c:\yourdesiredFilename.csv", .XlFileFormat.xlCSV) static void ConvertExcelToCsv(string excelFilePath, string csvOutputFile, int worksheetNumber = 1) \"", data)) Ĭheckout the. You can overload the method if you need to support earlier versions. It's 4.0 framework only, but that's mostly because of the optional worksheetNumber parameter. Remember to add your own error handling - this mostly assumes that things work for the sake of brevity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |