Layouts
Introduction
The Layouts feature in Formatted Reports allows you to combine multiple formatted reports into a single, cohesive report. This feature offers flexibility by enabling different sections of a larger report to adjust dynamically based on changes in the data. Using layouts, you can organize information in a structured way, making complex reports easy to navigate and interpret.
Example Script for Layouts
The following IronPython script demonstrates how to set up a report layout that combines fund-level data, sector summary data, and additional notes into a single report.
# IronPython
# Fund level data
data = Qx.ToMatrix([
["Fund Code", "Instrument", "Sector", "Holding", "Price", "Market Value", "Weight"],
# Fund 1 - "AlphaFund"
["AlphaFund", "AAPL", "Technology", 50, 150, 7500, 0.04424],
["AlphaFund", "GOOGL", "Technology", 30, 2800, 84000, 0.4955],
["AlphaFund", "AMZN", "Consumer Discretionary", 20, 3300, 66000, 0.3893],
["AlphaFund", "MSFT", "Technology", 40, 300, 12000, 0.0707],
# Fund 2 - "BetaFund"
["BetaFund", "TSLA", "Automotive", 10, 900, 9000, 0.2346],
["BetaFund", "NFLX", "Communication Services", 15, 540, 8100, 0.2112],
["BetaFund", "NVDA", "Technology", 12, 500, 6000, 0.1564],
["BetaFund", "ADBE", "Technology", 25, 610, 15250, 0.3976]
])
funds = Qx.MakeStyleSheet(data)
# Summary data
summary_data = Qx.ToMatrix([
["Sector", "Total Market Value", "Total Weight"],
# Summarized data by sector
["Technology", 124750, 0.7214],
["Consumer Discretionary", 66000, 0.2212],
["Automotive", 9000, 0.0301],
["Communication Services", 8100, 0.0271]
])
summary = Qx.MakeStyleSheet(summary_data)
# Additional comments or notes
sidenote_data = Qx.ToMatrix([
["Example comment 1"],
["Example comment 2"]
])
sidenotes = Qx.MakeStyleSheet(sidenote_data)
Defining the Report Layout
The layout combines the three sections—fund data, summary data, and sidenotes—into a single report. Each row in the layout can contain multiple style sheets that expand over multiple rows and columns within Excel.
# Combine the style sheets into a single report using layout
# The layout is constructed as an array of "rows".
# Each row can contain an array to represent multiple "columns".
# If the first element of one of these arrays contains an integer, it will be interpreted as the spacing between elements.
report_layout = [
1, # Spacing between row elements in this example
[funds], # Fund data occupies the first row
[2, [summary], [sidenotes]] # Summary and sidenotes side-by-side with spacing between columns in this example
]
report = Qx.BuildLayoutSheet(report_layout)
report
Explanation of the Layout Structure
- Spacing Between Elements: In this example, specific integers are used to define spacing within the layout:
1
specifies spacing between row elements within the row array for this particular layout.2
specifies spacing between column elements within the column array in this layout. These numbers control how much space appears between sections, helping to visually separate different parts of the report.- Row Structure in Layout vs. Excel: Each “row” in the layout array often expands to occupy multiple rows in Excel, depending on the data it contains. For instance, the
funds
section, represented as a single row in the layout, will expand into several rows in Excel to display detailed information for each instrument in the fund. - Fund Data: The fund data occupies the first row, displaying detailed holdings information for each fund.
- Summary and Sidenotes: The second row contains both the sector summary data and sidenotes, arranged side-by-side in separate columns within the same row. This layout keeps related information organized and accessible.
Summary
Layouts in Formatted Reports provide flexibility in arranging multiple data sections within a single report. By controlling row and column spacing and arranging data across rows that can expand dynamically, you can create adaptable reports that are organized and easy to read.