问题
Scope of Platforms Tested: Oracle 11g XE, Oracle APEX Versions 4.0.2 and 4.2.5
I don't like the column headers assigned to my APEX report after I assign my source query or table/view association. How do I change them? Can I add special formatting and embedded codes (e.g. HTML hex, decimal or short codes)?
Additional Question: How do I keep these formatting codes out of the text values that are exported when I run a "download" or "save to csv" operation?
回答1:
Conditional and Special Formatting for Oracle APEX Report Headers
This is a generalized expansion of another SO post which asks: How do I conditionally change the field (column) names on an APEX report. This Q&A explanation talks more generally about dynamic assignments of object items and attributes found on Oracle APEX reports. This example does this by embedding HTML codes within the text of report column headers. This should be searchable and more helpful to a wider audience.
Issues Resolved
- How to change REPORT output headers if you don't like what you got initially.
- How to bypass the APEX report design page's initial limitation: Show HTML codes and other special text formatting commands.
- How to keep these formatting codes from showing up in a text-formatted (ascii, utf-8, etc) .csv (comma separated value) export.
... let's get going!
Changing APEX Report Output Headers: Text Only
Try editing the report region definition:
Notice that I can also define a substitution value populated from a defined page item.
For example, page item =
P2_MY_TITLE
would be represented by:&P2_MY_TITLE.
Changing APEX Report Output Headers: HTML Format with CSV Output Toggle
I encountered some problems with getting both Interactive and Classic reports to show HTML formatted text on Version 4.0.2... The rest of this example was done using a newer instance on APEX Version 4.2.5. This example was done using Interactive reports.
I Defined two page ITEMS: PX_DISPLAY_FORMAT
and PX_ID_COLUMN_HEADER
. The former is just a convenience that allows users to define if their intent is to "VIEW ONLY" or to "EXPORT TO CSV". Choosing the appropriate option will dynamically set the format of the report displayed.
The latter item: PX_ID_COLUMN_HEADER
is for the ID column. I defined a short PL/SQL function output to decide what to display.
BEGIN
if :P6_DISPLAY_FORMAT = 'html-coded'
then return 'à © æ';
else return 'MY_ID_COLUMN';
end if;
END;
I used these codes to test:
- à (greek letter alpha) -- Decimal Value
- (space - formatting)
- © (copyright symbol)
- æ (that cool a + e symbol as in aesop, aeneid, faeroes...)
It's probably noticeable that there is a next step:
This function can be generalized, the column header choices kept as table driven data, etc.
PX_ID_COLUMN_HEADER
pulls from thePX_DISPLAY_FORMAT
item value as could other items defined for the other columns.
And now screen-pics of the final product in the two modes:
VIEW ONLY (With Special HTML Characters and Formatting)
Hint: Look for ID Column at the last column on the left.
CSV EXPORT FORMAT (With Text Only Values)
[cross-refs: #csv, #delimited reports, #column headers, #html formatting]
来源:https://stackoverflow.com/questions/24156968/how-do-i-customize-column-headers-with-html-in-a-report-region-of-an-oracle-apex