I have this python script to update page of confluence with csv file.
```
#!/usr/bin/env python import requests import pandas as pd import json import os # Confluence credentials EMAIL = "user@domain.com" API_TOKEN = os.environ.get('CONFLUENCE_TOKEN') CONFLUENCE_BASE_URL = "https://domain.atlassian.net/wiki/rest/api/" PAGE_ID = "3462135953" PAGE_TITLE = "Legacy Application List" SPACE_KEY = "CP1" # Read CSV file def read_csv(file_path): df = pd.read_csv(file_path) return df.to_html(index=False) # Convert CSV data to HTML # Get current page version def get_page_version(): url = f"{CONFLUENCE_BASE_URL}content/{PAGE_ID}?expand=version" response = requests.get(url, auth=(EMAIL, API_TOKEN)) if response.status_code == 200: return response.json()["version"]["number"] else: print("Error fetching page version:", response.text) return None # Update Confluence page def update_page(csv_html): version = get_page_version() if version is None: return url = f"{CONFLUENCE_BASE_URL}content/{PAGE_ID}" headers = { "Content-Type": "application/json" } data = { "id": PAGE_ID, "type": "page", "title": PAGE_TITLE, # Ensure this is the correct title "space": {"key": SPACE_KEY}, "body": { "storage": { "value": csv_html, "representation": "storage" } }, "version": {"number": version + 1} } response = requests.put(url, headers=headers, auth=(EMAIL, API_TOKEN), data=json.dumps(data)) if response.status_code == 200: print("Page updated successfully!") else: print("Error updating page:", response.text) if __name__ == "__main__": file_path = "test.csv" # Replace with actual CSV file path csv_html = read_csv(file_path) update_page(csv_html)
```
The test.csv content is this,
```
Name,Website
Google,"=HYPERLINK(""https://www.google.com"",""Google"")" OpenAI,"=HYPERLINK(""https://www.openai.com"",""OpenAI"")"
```
Opening the csv and copying the csv manually works fine and the hyperlink is working on Confluence page but using the python script update the page but url doesn't work. Output would be.
```
Name,Website
Google,=HYPERLINK("https://www.google.com","Google")
OpenAI,=HYPERLINK("https://www.openai.com","OpenAI")
```
Please help. Is this possible without excel macro? There's a free macro called "
csv file to table for confluence" not sure how to use it in the pythonscript.
Or use html page instead with lines.
Hi @venerari ,
welcome to the community!
The reason for this different behaviour is, that when you paste text in the Confluence editor using your browser, it parses this text, detects URLs and adds them as hyperlinks.
When you create the page using Python, this processing doesn't happen.
To achieve that you've described, you will have to do the processing in your Python script and add the URLs as HTML hyperlinks (e.g. <a href="https://www.openai.com">https://www.openai.com</a>) to the Confluence page.
Unfortunately, I'm not sure whether HTML code will do or you need to use Atlassian Document Format (https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/) instead. If you want to make sure, you'd built it with ADF.
I hope that helps!
Greetings
Philipp
Thanks! I got the solutionl.
Another problem is to control that width of the table columns.
Any idea? The style won't work. I"ll probably post another one for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @venerari ,
excellent. If my answer was helpful, I would appreciate if you could set it as solution, so that others in the future will know it solved your issue.
As for the table width: You could have a look at a page that contains a table with the desired with and check its source code to hopefully see how it's set up. And then use that source code in your python script.
Greetings
Philipp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.