Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Update Confluence Table Inside Table Excerpt Using Python

Tola I'm New Here Jun 01, 2021

I can update a table on a confluence page using something like this:


from atlassian import Confluence
import pandas as pd

conf_site = 'https://your-domaine.com/'
conf_user = {username}
conf_pass = {password}

page_title = {pageTitle}
page_space = {pageSpace}
page_id = {pageID} 

# connect to Confluence
conf = Confluence(url=conf_site, username=conf_user, password=conf_pass)

# get current page content
page = conf.get_page_by_id(page_id, expand='body.view')
page_content = page['body']['view']['value']

#get table
table = pd.read_html(page_content)
table = table[0] #Only one table on the page

#add new column to table
table['D'] = ''

#convert table to HTML
newHTML = table.to_html(index=False)

#new page content
page_content = newHTML

# update page with new content
conf.update_page(page_id, page_title, page_content)

 

However, what do I do when I want to update a table inside a Table Excerpt?

I have tried to modify the entire page_content including <div> , classes etc. and send it back to confluence. However the table I end up with is no longer inside a Table Excert. 

Any suggestions how to do this? 

1 answer

1 accepted

Hi @Tola,

Yes, it is possible to do. The only thing you need to change is the page body type from view to storage.

Pages are stored in the storage (XHTML) format in Confluence. It differs from what you see when viewing the page in a browser: links, macros, and other entities are stored in a different format. So when you update a page, you need to make updates in the storage format.

The first thing you need to change is this:

# get current page content
page = conf.get_page_by_id(page_id, expand='body.storage')
page_content = page['body']['storage']['value']

Then you need to work with XHTML, so you might need to parse it in a different way.

Tola I'm New Here Jun 11, 2021

XHTML instead of HTML did the trick. Thanks.

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Miss the Confluence demos at Team 21? Watch them here!

Phew, Atlassian Team 2021 blew by. With dozens of demos and a handful of keynotes, you may have missed some of the awesome Confluence Cloud sessions. Don't' worry, you can watch them all here or on Y...

143 views 2 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you