Formatting the Report Based on Page Styles

[Previous] [Next]

In the previous chapter, I showed you how to format the Chart control based on the formatting encoded into the containing page's style sheet. This solution uses that same code for the chart and uses the sister function FormatPivotFromStyles to format the PivotTable control with the style sheet information. I will not discuss this function in detail because it is similar to the FormatChartFromStyles function covered in Chapter 6.

Note that the FormatPivotFromStyles function will look for a few extra selectors and attributes in the style sheet that you might want set. For example, it is often useful to format total values with a nice number format. You can apply these number formats in code, or you can use the FormatPivotFromStyles function and encode them in your style sheet like so:

 Store Sales {     number-format: $#,##0.00 } Unit Sales {     number-format: $#,##0.00 } Sales Count {     number-format: #,##0 } 

The function will look for selectors of the same name or unique name as the total. You can also use selectors such as PivotTable, PivotTitlebar, PivotFields, and PivotMembers to format the various PivotTable control elements. For more details on which selectors are supported, see the FormatPivotFromStyles function in the FormatControls.scp file in the Scripts directory on the companion CD.

The other interesting formatting function is FormatPivotSubtotalsFromStyles, also in the FormatControls.scp file on the CD. This function runs through the various fields on the Row and Column axes and sets the SubtotalBackColor and SubtotalFont properties based on the GrandTotals and SubtotalsLevelN selectors in the style sheet. N is the subtotal level in your report starting at 1. For example, suppose you have the following code in your style sheet:

 GrandTotals {     color: White;     background-color: #9faccb;     font-family: Verdana;     font-size: 9pt;     font-weight: bold; } SubtotalsLevel1 {     color: Black;     background-color: White;     font-family: Verdana;     font-size: 9pt;     font-weight: bold; } SubtotalsLevel2 {     color: Black;     background-color: White;     font-family: Verdana;     font-size: 8pt;     font-weight: bold; } 

In this example, the FormatPivotSubtotalsFromStyles function would set the background color of the report's grand totals to #9faccb (a pleasant baby blue) and the font to bold, white, 9-point Verdana. The function would format the subtotals in the next level as bold, black, 9-point Verdana and the subtotals in the following level as bold, black, 8-point Verdana. If you call this function from the PivotTable component's QueryComplete event handler, you can emulate automatic formatting so that the grand total and each level of subtotals appears in a particular way, regardless of which fields are located on which axes.



Programming Microsoft Office 2000 Web Components
Programming Microsoft Office 2000 Web Components (Microsoft Progamming Series)
ISBN: 073560794X
EAN: 2147483647
Year: 1999
Pages: 111
Authors: Dave Stearns

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net