我将excel文件保存为CSV并在C#中保留编码时遇到问题。具体来说,以下文件将excel文件保存为具有相同名称的csv文件,该文件将传递给loadCsvData函数,该函数的作用是以有组织的方式将数据插入数据库。我的问题是excel文件包含无法以csv格式识别的小数符号,除非我手动打开每个.xml并保存为csv(出于某种原因,这可以在Microsoft.Office.Interop.Excel.Application方法SaveAs( )不):
List<string[]> data = new List<string[]>();
string fileName = (date.ToString("MM/dd/yyyy") + ".csv").Replace("/","");
string excelFileName = (date.ToString("MM/dd/yyyy") + ".xml").Replace("/","");
System.Console.WriteLine("Processing file: " + fileName);
System.Console.ReadLine();
// Open excel and save as csv. Then process the data
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workBook = app.Workbooks.Open(@"C:\Users\TAG\Desktop\TIP holdings\" + excelFileName);
workBook.SaveAs(@"C:\Users\TAG\Desktop\TIP holdings\CSV Data\" + fileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV);
workBook.Close(false,"",true);
data = loadCsvData(fileName);
insertData(data);