简体   繁体   English

如何设置aspose单元格以从OS中获取日期格式的语言环境?

[英]How can I set aspose cells to take the locale for date format from OS?

I am creating an excel with Aspose. 我正在用Aspose创建一个Excel。 I would like that the date will be formatted according to the OS's Locale, meaning that if the excel will be open in US or Europe the dates will appear in a different format, like if you select the format with asterisk in excel: printscreen of "Format Cells" screen in Excel 我想根据操作系统的区域设置的日期将被格式化,这意味着如果Excel将在美国或欧洲开放的日期将出现在不同的格式,就像如果你选择在Excel星号的格式为: 的“PRINTSCREEN在Excel中设置单元格格式”屏幕

This is my code: 这是我的代码:

style.setCustom(????);
cell.setStyle(style);

String date ="2/23/2015";
DateTime myDate = new DateTime(new Date(date));
cell.setValue(myDate);

How shall I set the cell style? 如何设置单元格样式?

thanks :) 谢谢 :)

In order to make the format adaptable to the operating system's locale, you have to use the built-in number formats. 为了使格式适合操作系统的语言环境,您必须使用内置的数字格式。 Please review the detailed article on setting date & number formats using Aspose.Cell s for Java APIs and check the built-in number formats from 14 to 17 for date literals. 请查看有关使用 Java API的Aspose.Cell设置日期和数字格式的详细文章,并检查14到17之间的内置数字格式以获取日期文字。 See the sample code below: 请参见下面的示例代码:

Workbook book = new Workbook();
Worksheet sheet = book.getWorksheets().get(0); 
Cells cells = sheet.getCells(); 
Style style = book.createStyle(); 
//style.setCustom("m/d/yyyy");
style.setNumber(14); 
Cell cell = cells.get("A1"); 
cell.setStyle(style); 
String date = "2/23/2015"; 
DateTime myDate = new DateTime(new Date(date));
cell.setValue(myDate); 
book.save("output.xlsx");

I am working as Support developer/ Evangelist at Aspose. 我在Aspose担任技术支持/开发人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Aspose.cells自定义日期格式,与操作系统日期格式无关 - Aspose.cells custom date formatting irrespective of OS date format 如何在计算出的像元(Aspose Cells)中防止“#Div / 0!”? - How can I prevent “#Div/0!” in calculated cells (Aspose Cells)? Stringtemplate - 如何将日期格式设置为区域设置格式 - Stringtemplate - How to set date format to locale format 如何将电子表格中的列宽设置为特定的像素数(Aspose Cells)? - How can I set the column width in a spreadsheet to a specific pixel count (Aspose Cells)? 将图像放在电子表格(Aspose Cells)上时,如何防止图像尺寸改变? - How can I prevent my image from changing size when placing it on a spreadsheet (Aspose Cells)? 如何在电子表格范围(Aspose Cells)周围添加边框? - How can I add borders around a spreadsheet range (Aspose Cells)? C#Aspose.Cells将数据设置为具有格式的Excel文件 - C# Aspose.Cells set data to Excel file with format 如何确定数据透视表生成多少行(Aspose Cells)? - How can I determine how many rows a PivotTable generates (Aspose Cells)? 如何覆盖数据透视表(设置单元格)上的列标签文本? - How can I override the column label text on a Pivot Table (Aspose Cells)? 如何用不同的值代替自动生成的总计值(Aspose Cells)? - How can I replace automatically-generated grand total values with different ones (Aspose Cells)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM