Brandon Bilton
Brandon Bilton

Reputation: 13

Python 3.5 xlsxwriter assistance

How can can I convert "Daily Return" and "MTD Return" into percentages if I am using xlsxwriter?

*Current code being used with xlsxwriter

worksheet.write('B10', df2.loc[4,["NAV"]])
worksheet.write('C10', df2.loc[4,["Daily_DVA"]])
worksheet.write('D10', df2.loc[4,["MTD_DVA"]])

Image 1

Also how am I able to add colors to the "Trading Activity" and "Performance Data" columns along with making the text bold like the following image attached? I would also like to keep the text centered as well.

*Current code being used with xlsxwriter

worksheet.merge_range('A2:B2', 'Trading Activity', center_format)
worksheet.merge_range('A8:D8', 'Performance Data', center_format)

Image 2

Upvotes: 1

Views: 113

Answers (1)

jmcnamara
jmcnamara

Reputation: 41644

You just need to add appropriate formats. Like this:

import xlsxwriter

workbook = xlsxwriter.Workbook('example.xlsx')
worksheet = workbook.add_worksheet()

# Add a format for percentages.
percent_format = workbook.add_format({'num_format': '0%'})

worksheet.write('B1', .5)
worksheet.write('B2', .5, percent_format)

# Add a format for a merged range.
merge_format = workbook.add_format({
    'bold': True,
    'border': 1,
    'align': 'center',
    'valign': 'vcenter',
    'fg_color': '#16DDFF'})

worksheet.merge_range('B4:D4', 'Trading Activity', merge_format)

workbook.close()

Output:

enter image description here

Upvotes: 1

Related Questions