2014-11-05 64 views
1

我有下面的代碼轉換用於把Excel文件CSV文件後刪除在CSV文件編號額外的逗號:如何從Excel

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

你的意思是你想'',「309145」,「4964398」,,「1194780」,,'而不是? – 2014-11-05 15:04:28

+2

*哪些*額外的逗號?指示數千的指示符,還是指示空列的指示符? – 2014-11-05 15:05:15

+0

我寫道:「正如你看到的數字包含一個額外的逗號」,所以:表示數千。 – tlecka 2014-11-05 15:09:32

回答