Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EPPlus转换csv并从双精度中缺少逗号_C#_C# 4.0_Cultureinfo_Epplus - Fatal编程技术网

C# EPPlus转换csv并从双精度中缺少逗号

C# EPPlus转换csv并从双精度中缺少逗号,c#,c#-4.0,cultureinfo,epplus,C#,C# 4.0,Cultureinfo,Epplus,我正在尝试使用以下代码将CSV文件转换为xlsx文件: string csvFileName = path; string nomeArquivo = Path.Combine(serverpath, RandomString(10) + ".xlsx"); string worksheetsName = "b2w"; bool firstRowIsHeader = false; var format = new

我正在尝试使用以下代码将CSV文件转换为xlsx文件:

        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


我做错了什么?

看起来像是
CultureInfo
问题。例如,在美国,我们使用
而不是
来标记双精度的十进制值。因此,如果导入这样的数字,逗号将被忽略。如果您使用的区域性将
NumberDecimalSeparator
设置为逗号,则该区域性应该可以工作。例如:

format.Culture = new CultureInfo("de-DE"); //Using German cultureinfo
应该解决这个问题。您可以从这里获得一个很好的文化列表: