Consultor Eletrônico



Kbase P4079: How to change the decimal format of a cell in an Excel Spreadsheet
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/03/2007
Status: Verified

GOAL:

How to change the decimal format of a cell in an Excel Spreadsheet

GOAL:

How to make an Excel cell display a decimal number with '0.00' instead of '0'

FIX:

Similarly to the Progress record buffer + screen buffer mechanism, Excel manages a NumberFormat attribute in order to display the content of a cell at the screen.

The default value of this NumberFormat attribute is 'General', which means that the format depends on the value of the cell rather than a predefined data type.

Manage the NumberFormat Attribute of the cells (range) as illustrated below:


DEFINE VARIABLE hExcel AS COM-HANDLE NO-UNDO.

CREATE "Excel.Application" hExcel.

hExcel:VISIBLE = TRUE.
hExcel:WorkBooks:Add().
hExcel:Worksheets("Sheet1"):Cells(1,1) = 0.00. /*try also with 0.01*/
hExcel:Worksheets("Sheet1"):Cells(1,1):NumberFormat = "0.000".

MESSAGE hExcel:Worksheets("Sheet1"):Cells(1,1):NumberFormat
SKIP hExcel:Worksheets("Sheet1"):Cells(1,1):NumberFormatLocal
SKIP hExcel:Worksheets("Sheet1"):Cells(1,1):VALUE
VIEW-AS ALERT-BOX INFO BUTTONS OK.

RELEASE OBJECT hExcel.