Reputation: 13
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"]])
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)
Upvotes: 1
Views: 113
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:
Upvotes: 1