我有下一个将excel文件转换为csv文件的代码:
Microsoft.Office.Interop.Excel.Application reportExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks reportBooks = null;
Microsoft.Office.Interop.Excel.Workbook reportBook = null;
Microsoft.Office.Interop.Excel.Sheets reportSheets = null;
Microsoft.Office.Interop.Excel._Worksheet reportSheet = null;
try
{
reportBooks = reportExcel.Workbooks;
reportBook = reportBooks.Open(excelFilePath);
reportSheets = reportBook.Sheets;
reportSheet = reportSheets.get_Item(1);
if (File.Exists(csvtempFile))
{
File.Delete(csvtempFile);
}
reportBook.SaveAs(csvtempFile, Microsoft.Office.Interop.Excel.XlFileFormat.xlCSVWindows, Type.Missing, Type.Missing, false, false);
...
}
catch (Exception ex)
{
...
}
finally
{
...
}
我在csv文件中获得下一个文本:
...
"Some strings","309,145","4,964,398",,"1,194,780",,
...
如您所见,数字中包含额外的逗号。请告诉我如何删除额外的逗号以获取下一个值:
"Some strings","309,145","4964,398",,"1194,780",,
答案 0 :(得分:0)
查看此帖子:Set data type like number, text and date in excel column using Microsoft.Office.Interop.Excel in c#
您可以检查列类型,在每个要更改的列表上设置范围,然后在导出之前设置数字格式。
我知道它不漂亮,但如果你找不到更漂亮的东西,它可能有用。