How to Display an Attached CSV File as a Confluence Table
Unable to render {include} The included page could not be found.

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.

  1. Type in an introductory paragraph that describes the purpose of the page or anything else the viewer ought to know.

  2. Click the toolbar button (or choose Ctrl-M for Windows or Command-M for Mac) so that you can attach the SalesLeads.csv file to this page.

    1. On the Attached to this page tab, click Upload files.

    2. Navigate to the location to which you downloaded the SalesLeads.csv file, select  the file and click Open to complete the upload.

    3. Click Cancel since you don't want to insert the file. (You'll be using the CSV macro to display it instead.)

  3. With the cursor positioned after your introductory paragraph, insert the CSV macro, which is part of the Advanced Tables for Confluence add-on.

    1. Click on the CSV macro container and configure with the parameters shown on the right.

    2. Click Save to save your changes to the CSV macro parameters.

    3. The page should look like the first screenshot shown to the right.

  4. Click Save the page.

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:

Columns to show

country,state_province,job_title,first_name,last_name,email,phone

Location of CSV data

^salesleads.csv

Auto number each row

selected

Show sort icon

selected

Auto sort column

country

Column types

S,S,M,S,S,S,S,S,S,S,S,S

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:

  1. With the cursor positioned at the end of the introductory paragraph, press Enter a few times to add some blank lines above the CSV macro.

  2. Move to the second blank line and insert the Cache macro.

    1. Click on the Cache macro container and adjust its parameters as shown to the right.

    2. Click Save to save your changes to the Cache macro parameters.

  3. Click on the CSV macro container and drag it into the Cache macro container.

  4. Your screen should look like the first screenshot shown to the right.

  5. Click Save to save the page.

  6. It should now look like the second screenshot shown to the right and should render more quickly. More importantly, each subsequent user should see the page render nearly instantaneously as it will be be loaded from the cache until its reaches the end of its 2-day refresh period.

  7. The Cache macro is displaying the Refresh icon along with the date the cache was last refreshed. A user can click the refresh icon to force the cache to be immediately refreshed.

 

Cache Macro parameters:

Cache refresh period

2d

Check attachments

selected

Show refresh icon

selected

Show date

selected

Date format

EEE, MMM d, YYYY

Sales Leads page, in Edit mode:


Sales Lead page, in View 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:

  1. With the cursor positioned above the Cache macro container, press Enter to add another blank line above the Cache macro container.

  2. Move to that new blank line and insert the Future macro.

    1. Click on the Future macro container and adjust its parameters as shown to the right.

    2. Click Save to save your changes to the Future macro parameters.

  3. Click on the Cache macro container and drag it into the Future macro container.

  4. Your screen should look like the first screenshot shown to the right.

  5. Click Save to save the page.

  6. When the page is in the process of being rendered, you will see the "Loading" message shown in the second screenshot to the right. This is the Future macro doing its job. (wink)

  7. When the rendering is complete, you will see the Refresh icon and the date on which the cache was last refreshed… courtesy of the Cache macro.

 

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:

Delay in seconds

5

Sales Lead page, in Edit mode:

Excerpt of Sales Lead page, while the page is being rendered:


Sales Lead page, after page is fully rendered:

Unable to render {include} The included page could not be found.