How to Display an Attached CSV File as a Confluence Table
Recipe overview
This recipe provides step-by-step instructions on how to display an attached CSV file as a table on a Confluence page. Because this recipe is using a very large (3,000 record) CSV file, it will leverage the Cache for Confluence add-on to ensure the rendering of the page occurs as quickly as possible. This add-on features these macros:
The Cache macro, which allows a page to be saved in a cache after being rendered so that subsequent users viewing the page benefit from a much faster page rendering. The Cache macro "wraps around" the page content to be cached, and its parameters allow you to control the length of time the data is cached or optionally allow the user to manually refresh the cache.
The Future macro, which allows the page to be rendered as it becomes available. This allows the user to see quickly rendered content immediately, while the output of longer running macros is being rendered in the background. This macro also "wraps around" the content it controls. The list of macros that work with the Future macro, including the Cache macro, is listed here.
Please read Page display performance tips and techniques to learn more about what can affect the performance of a Confluence page.
It will take you approximately 4 minutes to complete this recipe.
Recipe level
Ingredients
Preparation
Download the attached to your computer. The file contains contact information for 3,000 potential sales leads. It was randomly generated using an online tool called Mockaroo so it does not reflect real people or companies. Here is an excerpt from that file, with the first row identifying each field.
Steps
Create Confluence page and add the CSV macro
Estimated Time: 2 min
Create a Confluence page that will display the SalesLeads.csv file in a table so that others can easily review it.
You should see the page in the second screenshot shown to the right, after a few seconds delay.
Other Ways to Supply the CSV File You can also reference a CSV file that is stored on an external server or web site, by using the CSV macro's URL parameter. You can also leverage the power of the Run CLI Actions in Confluence add-on and other Command Line Interface (CLI) add-ons to have your CSV file created and attached to the desired Confluence page automatically or on a scheduled basis. The How to Monitor Language in Public Chat Rooms (Advanced) recipe provides an example of this.
| CSV Macro parameters:
Sales Leads page, in Edit mode: Sales Leads page, in View mode: | |||||||||||||
Tune performance by adding the Cache macro
Estimated Time: 2 min
If this Sales Lead page is used heavily, any performance penalty associated with showing such a large amount of data can be costly since it is incurred by each visit to the page. Therefore, you're now going to add the Cache macro of the Advanced Tables for Confluence add-on to speed up the page rendering and reduce the page's use of system resources. Edit the Sales Leads page, and do the following:
| Cache Macro parameters:
Sales Leads page, in Edit mode:
| |||||||||||||
Bonus Tip
OPTIONAL Estimated Time: 2 min
If you have a very complex page or one that is using many macros, you may find the use of the Cache macro helps considerably but the user still has to wait a while to see the full page rendered. This is where the Future macro can help. As explained here, the Cache macro can be enclosed within the Future macro to allow some of the page rendering to occur while the rest of the page is rendered in the background. The user will then see content as soon as it is available, making the page's full rendering time less noticeable. To continue with our example above, edit the Sales Leads page and do the following:
If your Confluence instance is using the Macro Security for Confluence add-on and your Confluence Administrator has restricted use of a macro security managed macro such as Future or Cache, you may see an error after saving the page. If this is the case, you will need to add a page-level Edit restriction that conforms to the restriction implemented in the Macro Security configuration. More information is available in the Macro Security User's Guide. | Future macro parameters:
Sales Lead page, in Edit mode: Excerpt of Sales Lead page, while the page is being rendered:
| |||||||||||||
