[英]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.