Kbase P140714: 4GL/ABL: How to CenterHeader in Microsoft Excel?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  03/01/2011 |
|
Status: Verified
GOAL:
4GL/ABL: How to CenterHeader in Microsoft Excel?
GOAL:
How to programmatically create a multiple line Microsoft Excel CenterHeader using 4GL/ABL?
GOAL:
How to Print Preview the Microsoft Excel selected sheets using 4GL/ABL?
GOAL:
How to include Page Number and Date formatting codes in a Microsoft Excel Header?
GOAL:
What are the formatting codes that can be included in Excel Headers and Footers?
FACT(s) (Environment):
Windows
Progress 8.x
Progress 9.x
OpenEdge 10.x
FIX:
The following code sample shows how to create a Microsoft Excel CenterHeader using 4GL/ABL. It also demonstrates how to use the CHR(13) to generate a multiple line Microsoft Excel Center Header. The code also uses the special formatting codes $D (date) , &P(Page) and &N (Number of Pages) to insert that information in the CenterHeader. A complete list of these formatting codes is included in the note below:
/************** Define variables ***********/
DEFINE VARIABLE hExcel AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hWorkbook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hWorksheet AS COM-HANDLE NO-UNDO.
define variable hPageSetup as com-handle no-undo.
/*** Open Excel and initialize variables ***/
CREATE "Excel.Application" hExcel.
ASSIGN
hWorkBook = hExcel:WorkBooks:Add()
hWorkSheet = hWorkBook:WorkSheets(1)
hPageSetup = hWorkSheet:PageSetup
hWorkSheet:Cells(1,1 ) = "Test data"
hPageSetup:CenterHeader = "First Header Line" + chr(13) + "Second Header Line" + chr(13) + "&D page &P of &N &"
hExcel:visible = true.
/****** Print Preview Selected Sheets ******/
hExcel:Application:ActiveWindow:SelectedSheets:PrintPreview.
/* Close Workbooks & Quit Excel Application */
hExcel:Application:Workbooks:CLOSE() NO-ERROR.
hExcel:Application:QUIT NO-ERROR.
/********* Delete All Object Handles *********/
IF VALID-HANDLE(hPageSetup) THEN
RELEASE OBJECT hPageSetup.
IF VALID-HANDLE(hWorksheet) THEN
RELEASE OBJECT hWorksheet.
IF VALID-HANDLE(hWorkbook) THEN
RELEASE OBJECT hWorkbook.
IF VALID-HANDLE(hExcel) THEN
RELEASE OBJECT hExcel.