CSV files not opening according to user's locale


#1

Hi,
I am using aspose.cells to generate CSV. The generated file does not open according to the user’s locale like in the case of Excel files is there a way to achieve this?

        string FileName = @"C:\Users\Ankita\Downloads\input.xlsx";

        string destFileName = @"C:\Users\Ankita\Downloads\outputaspose.csv";

       List<string> LstReportObject = new List<string>();
        LstReportObject.Add("Spend (EUR)");
       // //Load your source workbook

        Workbook workbook1 = new Workbook(FileName);

       MemoryStream msFormatting = new MemoryStream();
       workbook1.Save(msFormatting, SaveFormat.Xlsx);
        Workbook workbook = new Workbook(msFormatting);

        Worksheet ws = workbook.Worksheets[0];
        //  //ws.Cells[0,0].Value = "SEP=    ";

        // //0-byte array
        TxtSaveOptions opts = new TxtSaveOptions();
        opts.Encoding = Encoding.Unicode;
        // opts.QuoteType = TxtValueQuoteType.Always;

        opts.Separator = ',';

        byte[] workbookData = new byte[0];
        string[] columnName = new string[2];

        string[] columnHeader = new string[2];

        for (int i = 0; i < 2; i++)
        {

            columnName[i] = CellsHelper.ColumnIndexToName(i) + 4;

            Cell cell = ws.Cells[columnName[i]];

            columnHeader[i] = cell.Value.ToString();



        }

        foreach (var item in LstReportObject)
        {

            for (int i = 0; i < columnHeader.Length; i++)
            {

                if (columnHeader[i] == item)
                {



                    if (item == "Spend (EUR)")
                    {

                        StyleFlag NumberFlag = new StyleFlag();

                        NumberFlag.NumberFormat = true;

                        Style NumberStyle = workbook.CreateStyle();

                        NumberStyle.Custom = "€#,##0.00";

                        ws.Cells.Columns[i].ApplyStyle(NumberStyle, NumberFlag);

                    }
                    break;
                }
            }
        }

        workbook.Save(destFileName,SaveFormat.CSV);
    }

}
}

excelaspose2.zip (8.3 KB)


#2

@an1,

Could you please explain the problem a bit more. Mention the name of cells or values with the help of screenshots. We will reproduce the problem and provide our feedback after analysis.


#3

The spend(EUR) column even after doing text to columns does not open according to user’s locale . When the user has digit grouping 3


#4

@an1,

Seeing your code segment, i.e.,

since you are using Style.Custom attribute which won’t change formatted values according to different locales. You should use Style.Number property instead, see the sample code segment for your reference:
e.g
Sample code:

......
 if (item == "Spend (EUR)")
                    {

                        StyleFlag NumberFlag = new StyleFlag();

                        NumberFlag.NumberFormat = true;

                        Style NumberStyle = workbook.CreateStyle();

                        NumberStyle.Number = 7;

                        ws.Cells.Columns[i].ApplyStyle(NumberStyle, NumberFlag);

                    }
                    break;

#5

By using NumberStyle.Number=7 i wont be able to append euro symbol in the beginning


#6

@an1,

Aspose.Cells follows Ms Excel standards and specifications. You should try your scenario in MS Excel manually and you will find the same thing. When you open the file into MS Excel in UK or other euro supported locales, the euro symbol should be there with the numeric values. If you still find any difference, kindly do elaborate it and provide complete details, sample files, screenshots (to highlight the issue), sample code, locale settings shots, etc, we will check it soon.


#7

Actually, I have many currency fields which need to be displayed with different currency symbols so I have to append the corresponding currency symbol accordingly.


#8

@an1,

Please provide template files that explain your requirements with MS Excel so that we can check it according to Excel standards.