2016-04-28 40 views
1

我想轉換一個CSV文件中使用下面的代碼XLSX文件中缺少逗號:EPPlus將CSV和雙

 string csvFileName = path; 

     string nomeArquivo = Path.Combine(serverpath, RandomString(10) + ".xlsx"); 

     string worksheetsName = "b2w"; 
     bool firstRowIsHeader = false; 
     var format = new ExcelTextFormat(); 
     format.Delimiter = ';'; 
     format.EOL = "\n";    // DEFAULT IS "\r\n"; 
              // format.TextQualifier = '"'; 

     using (ExcelPackage package = new ExcelPackage(new FileInfo(nomeArquivo))) 
     { 
      ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(worksheetsName); 
      worksheet.Cells["A1"].Value = "Status Pedido"; 
      worksheet.Cells["B1"].Value = "Site Origem"; 
      worksheet.Cells["C1"].Value = "Número Pedido"; 
      worksheet.Cells["D1"].Value = "Número Entrega"; 
      worksheet.Cells["E1"].Value = "Total Pedido"; 
      worksheet.Cells["F1"].Value = "CPF"; 
      worksheet.Cells["G1"].Value = "Nome Completo"; 
      worksheet.Cells["H1"].Value = "Endereço"; 
      worksheet.Cells["I1"].Value = "Número"; 
      worksheet.Cells["J1"].Value = "Complemento"; 
      worksheet.Cells["K1"].Value = "Referencia"; 
      worksheet.Cells["L1"].Value = "Bairro"; 
      worksheet.Cells["M1"].Value = "CEP"; 
      worksheet.Cells["N1"].Value = "Estado"; 
      worksheet.Cells["O1"].Value = "Cidade"; 
      worksheet.Cells["P1"].Value = "Merda1"; 
      worksheet.Cells["Q1"].Value = "Telefone Fixo"; 
      worksheet.Cells["R1"].Value = "Telefone Celular"; 
      worksheet.Cells["S1"].Value = "Merda2"; 
      worksheet.Cells["T1"].Value = "Sku Lojista"; 
      worksheet.Cells["U1"].Value = "Merda3"; 
      worksheet.Cells["V1"].Value = "Quantidade"; 
      worksheet.Cells["W1"].Value = "Valor unitário"; 
      worksheet.Cells["X1"].Value = "Valor Frete"; 
      worksheet.Cells["Y1"].Value = "Data Entrega"; 
      worksheet.Cells["Z1"].Value = "Valor Adicional"; 
      worksheet.Cells["A2"].LoadFromText(new FileInfo(csvFileName), format, OfficeOpenXml.Table.TableStyles.Medium27, firstRowIsHeader); 
      package.Save(); 

      B2wExcelInsertPrimeiro InsertData = new B2wExcelInsertPrimeiro(nomeArquivo); 
      InsertData.Insert(); 
     } 

皈依後,保存文件,但雙值像319,98正在保存爲31998.

我在做什麼錯?

回答

1

看起來像一個CultureInfo問題。例如,在美國,我們使用.而不是,來標記雙精度的十進制值。所以如果你輸入一個這樣的數字,逗號將被忽略。如果您使用將NumberDecimalSeparator設置爲逗號的文化,它應該可以工作。例如:

format.Culture = new CultureInfo("de-DE"); //Using German cultureinfo 

應該解決問題。你可以從這裏得到一個良好的文化清單:

http://www.csharp-examples.net/culture-names/

+0

就是這樣!不斷變化的文化就像一個魅力。 –