Aspose Number and date settings

Source: Internet
Author: User

A very powerful feature of Microsoft Excel is the ability for customers to set the display format of numbers and dates, which are known to be displayed in different value formats, including: decimals, currencies, percentages, fractions, book value, etc. The same aspose.cells provides developers with the ability to format numbers and Time. In excel, customers can right-click cells, Select cell formatting to format cells, and Aspose.cells provides GetStyle and SetStyle methods that are specifically designed to format cells.  aspose.cells also provides developers with a number of inline numeric and date formats that developers can invoke by using the number property of the style object, and the following is a list of the inline display formats provided by the Aspose.cells: Value  type  format String0  general  general1  decimal  02  decimal  0.003   Decimal  #,# #04  decimal  #,# #0.005  currency  $#,# #0; $-#,# #06  currency  $#,# #0; [red]$-#,# #07  currency  $#,# #0.00;$-#,# #0.008  currency  $#,# #0.00; [red]$-#,# #0.009  percentage  0%10  percentage  0.00%11  scientific  0.00E+0012   Fraction  #?/?13  fraction  #/14  date  m/d/yy15  date  d-mmm-yy16  Date   D-mmm17  date  mmm-yy18  time  h:mm am/pm19  time  h:mm:ss AM/PM20  Time  h:mm21  time  h:mm:ss22  time  m/d/yy h:mm37  currency  #,# #0;-#,# #038  Currency  #,# #0; [red]-#,# #039  currency  #,# #0.00;-#,# #0.0040  currency  #,# #0.00; [red]-#,# #0.0041  accounting  _ * #,# #0_; _ * "_; _ @_42  accounting  _ $* #,# #0_; _ $*" _; _ @_43 &NB Sp Accounting  _ * #,# #0.00_; _ * "?? _; _ @_44  accounting  _ $* #,# #0.00_; _ $* "?? _; _ @_45  time  mm:ss46  time  h:mm:ss47  time  mm:ss.048  Scientific  # #0.0E+0 049  text  @ We can actually see how to use these inline cell display formats using the following code://instantiating a Workbook objectworkbook Workbook = new Workbook ();//adding A new worksheet to the Workbook objectint i = Workbook. Worksheets.add ();//obtaining The reference of the newly added worksheet by passing its sheet indexworksheet worksheet = wo Rkbook. Worksheets[i];//adding the current system, date to "A1" cellworksheet. Cells["A1"]. Putvalue (datetime.now);//getting The Style of the A1CellStyle style = Worksheet. Cells["A1"]. GetStyle ();//setting The display format to number A to show date as "d-mmm-yy" Style. Number = 15;//applying The style to the A1 cellworksheet. Cells["A1"]. SetStyle (style);//adding A numeric value to "A2" cellworksheet. Cells["A2"]. Putvalue//getting the Style of the A2 CellStyle = Worksheet. Cells["A2"]. GetStyle ();//setting The display format to number 9 to show value as Percentagestyle. Number = 9;//applying The style to the A2 cellworksheet. Cells["A2"]. SetStyle (style);//adding A numeric value to "A3" cellworksheet. Cells["A3"]. Putvalue (2546);//getting The Style of the A3 CellStyle = Worksheet. Cells["A3"]. GetStyle ();//setting The display format to number 6 to show value as Currencystyle. Number = 6;//applying The style to the A3 cellworksheet. Cells["A3"]. SetStyle (style);//saving the Excel fileworkbook. Save ("c:\\book1.xls", saveformat.excel97to2003); Of course the developer can also set a custom display style for the cell, and the following code gives an example of how to set a cell custom display style://instantiating a Workbook Objectworkbook Workbook =New Workbook ();//adding A new worksheet to the Excel objectint i = Workbook. Worksheets.add ();//obtaining The reference of the newly added worksheet by passing its sheet indexworksheet worksheet = wo Rkbook. Worksheets[i];//adding the current system, date to "A1" cellworksheet. Cells["A1"]. Putvalue (datetime.now);//getting The style of A1 cellstyle style = Worksheet. Cells["A1"]. GetStyle ();//setting The custom display format to show date as "d-mmm-yy" Style. Custom = "d-mmm-yy";//applying The style to A1 Cellworksheet. Cells["A1"]. SetStyle (style);//adding A numeric value to "A2" cellworksheet. Cells["A2"]. Putvalue;//getting the style of A2 CellStyle = Worksheet. Cells["A2"]. GetStyle ();//setting The custom display format to show value as Percentagestyle. Custom = "0.0%";//applying The style to A2 Cellworksheet. Cells["A2"]. SetStyle (style);//adding A numeric value to "A3" cellworksheet. Cells["A3"]. Putvalue (2546);//getting The style of A3 CellStyle = Worksheet. Cells["A3"]. GetStyle ();//setting the Custom display format to show value as Currencystyle. Custom = "£#,# #0; [red]$-#,# #0 ";//applying The style to A3 Cellworksheet. Cells["A3"]. SetStyle (style);//saving the Excel fileworkbook. Save ("c:\\book1.xls", saveformat.excel97to2003);

Aspose Number and date settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.