Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel header fonts
Message
 
 
À
20/06/2007 11:48:14
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01234511
Message ID:
01234517
Vues:
10
>The macro yields kind of a funky command line.
>
>What would be the correct syntax for
>
>  oExcel.ActiveSheet.PageSetup.CenterHeader = "&""Arial,Bold""&14 2006 TRP Year"
>
>
>Thanks

This is a code by Daniel Gramunt member #021103:
*--------------------------------------------------------------------------------------------------
*-- VBA Formatting Codes for Headers and Footers (from VBA help file)
*--------------------------------------------------------------------------------------------------
*-- The following special formatting codes can be included as a part of the header and footer
*-- properties (LeftHeader, CenterHeader, RightHeader, LeftFooter, CenterFooter, RightFooter).
*--
*-- Format code Description
*-- &L          Left aligns the characters that follow.
*-- &C          Centers the characters that follow.
*-- &R          Right aligns the characters that follow.
*-- &E          Turns double-underline printing on or off.
*-- &X          Turns superscript printing on or off.
*-- &Y          Turns subscript printing on or off.
*-- &B          Turns bold printing on or off.
*-- &I          Turns italic printing on or off.
*-- &U          Turns underline printing on or off.
*-- &S          Turns strikethrough printing on or off.
*-- &D          Prints the current date.
*-- &T          Prints the current time.
*-- &F          Prints the name of the document.
*-- &A          Prints the name of the workbook tab.
*-- &P          Prints the page number.
*-- &P+number   Prints the page number plus the specified number.
*-- &P-number   Prints the page number minus the specified number.
*-- &&          Prints a single ampersand.
*-- &"fontname" Prints the characters that follow in the specified font.
*--             Be sure to include the double quotation marks.
*-- &nn         Prints the characters that follow in the specified font size.
*--             Use a two-digit number to specify a size in points.
*-- &N          Prints the total number of pages in the document.

*!*	   #DEFINE ccHeaderFont  [&"Arial,Regular"&09] && Arial, Regular, Size=9
*!*	   #DEFINE ccFooterFont  [&"Arial,Regular"&09] && Arial, Regular, Size=9
	#DEFINE ccHeaderFont  [&B &"Tahoma" &14] && Tahoma, Bold, Size=14
	#DEFINE ccFooterFont  [&"Tahoma" &10] && Tahoma, Regular, Size=10
*-- set pageSetup properties
	WITH oXLS.APPLICATION.ActiveSheet.PageSetup
*.LeftHeader  = ""
		.CenterHeader = ccHeaderFont + THIS.GetSourceType() + " - " + m.lcAlias && e.g. "Remote View - Customers"
*.CenterHeader = This.GetSourceType() + " - " + lcAlias && e.g. "Remote View - Customers"
		.RightHeader  = ccFooterFont + NiceFormatDate(DATE())
		.LeftFooter   = ccFooterFont + m.lcVersion
		.RightFooter  = ccFooterFont + "&P of &N"
		IF m.pnAnswer = 6 && Yes && Stop by ESC
			oXLS.APPLICATION.QUIT()
			RETURN - 20
		ENDIF

		.LeftMargin   = cnCentimetersToPoints * 1.9
		.RightMargin  = cnInchesToPoints * 0.27244094488189
		.TopMargin    = cnInchesToPoints * 0.47244094488189
		.BottomMargin = cnInchesToPoints * 0.47244094488189
		.HeaderMargin = cnInchesToPoints * 0.236220472440945
		.FooterMargin = cnInchesToPoints * 0.236220472440945
		.PrintHeadings = .F. && Don't want to print Excel Headings
		.PrintGridlines = .T.
*.PrintHeadings = .f.
*.PrintGridlines = .f.
*.PrintComments = xlPrintNoComments
*.PrintQuality = 600
		.CenterHorizontally = .T.
*.CenterVertically = .t.
		.ORIENTATION = xlLandscape
*.Draft = .f.
*.PaperSize = xlPaperA4
*.FirstPageNumber = xlAutomatic
*.Order = xlDownThenOver
*.BlackAndWhite = .f.
		.ZOOM           = .F.
		.FitToPagesWide = 1
		.FitToPagesTall = .F.
		.PrintTitleRows = "$1:$1"    && repeats header on each page
	ENDWITH

	IF m.pnAnswer = 6 && Yes && Stop by ESC
		oXLS.APPLICATION.QUIT()
		RETURN - 20
	ENDIF
*-- format column headings

*-- change column captions
	FOR i = 1 TO m.lnFields
		IF m.pnAnswer = 6 && Yes && Stop by ESC
			oXLS.APPLICATION.QUIT()
			RETURN - 20
		ENDIF
		oXLS.Worksheets(1).RANGE(oXLS.Worksheets(1).Cells(1, i), oXLS.Worksheets(1).Cells(1, i)).SELECT
		oXLS.SELECTION.VALUE = laFields[i]
	ENDFOR

*-- select first row
	oXLS.Worksheets(1).RANGE(oXLS.Worksheets(1).Cells(1, 1), oXLS.Worksheets(1).Cells(1, lnFields)).SELECT

	oXLS.SELECTION.AutoFormat(1)

	IF m.pnAnswer = 6 && Yes && Stop by ESC
		oXLS.APPLICATION.QUIT()
		RETURN - 20
	ENDIF

*-- format header row
	WITH oXLS.SELECTION.FONT
*.Name = "Arial"
*.Size = 12
		.Bold = .T.
		.Italic = .F.
		.SHADOW = .F.
	ENDWITH

	WITH oXLS

*-- set width of each column to fit content
		.COLUMNS().EntireColumn.AutoFit

		.SELECTION.Interior.ColorIndex = 15      && grey background
		.SELECTION.HorizontalAlignment = xlLeft

	ENDWITH
I posted the relevant code from Output program written by Daniel I used several years ago in my application.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform