We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Setting the default culture setting for the excel sheet

Hi,

is it possible to set a default culture setting for the excel sheet?

what is the best way to set the format to "mm-dd-yyyy" and only "mm-dd-yyyy" even if you work on a pc with american culture or any other one without lossing the cell format which should be Date.

if i do this:

DateTime dt

sheet.Cells[1, 0].PutValue(dt.ToString("dd-MM-yyyy"));

Then i will have a sheet with the correct setting put the cell format is not date anymore but a string, and if i try this:

sheet.Cells[startrow, 0].PutValue(dt));

Style style2;

StyleFlag flag = new StyleFlag();

style2 = sheet.Cells.Columns[0].Style;

style2.Custom = "mm-dd-yyyy";

flag.NumberFormat = true;

sheet.Cells.Columns[0].ApplyStyle(style2, flag);

then i wont get the format "mm-dd-yyyy" if my current culture of my pc is set to american.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, I have tested you issue but I am getting the date custom format “mm-dd-yyyy” fine with american culture set on my PC. I don’t think, setting the Column format is actually dependent on the PC culture. May be you are using some old version of Aspoe.Cells. Please try the attached latest version of Aspose.Cells and if you still face any problem, please share your template file + generated sheet and we will look into it.

Also, following is my sample code,

Sample Code:

//Instantiating an Workbook object

Workbook workbook = new Workbook();

workbook.Worksheets.Add();

//Obtaining the reference of the newly added worksheet by passing its sheet index

Worksheet sheet = workbook.Worksheets[0];

sheet.Cells[0, 0].PutValue(DateTime.Now);

Style style2;

StyleFlag flag = new StyleFlag();

style2 = sheet.Cells.Columns[0].Style;

style2.Custom = "mm-dd-yyyy";

flag.NumberFormat = true;

sheet.Cells.Columns[0].ApplyStyle(style2, flag);

//Saving the Excel file

workbook.Save("C:\\test_format.xls");

Thank You & Best Regards,