python XlsxWriter 文本换行和链接样式 [英] python XlsxWriter text wrapping and links styling

查看:86
本文介绍了python XlsxWriter 文本换行和链接样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关 python XlsxWriter 的帮助.我需要为外部文件链接列添加链接样式.但是 Xlsxwriter 无法识别链接样式(其第二列)(文本:下划线,文本颜色:蓝色),如果我要为另一列添加文本换行(在本例中的第一列).

这是我的例子:

# _*_ 编码:utf-8导入 xlsxwriterwb = xlsxwriter.Workbook('/home/mtw/Downloads/my_export.xlsx')格式 = wb.add_format()format.set_text_wrap()sheet = wb.add_worksheet(name='export_object1')sheet.write_row('A1', [u'It\na bum\nwrap','外部:辞职信.docx',], 格式)wb.close()

所以我需要告诉 XlsxWriter 他可以识别和文本换行和链接样式.

微软办公室:2007.

xlsxwriter 最新版本.

谢谢.

解决方案

Excel 中的链接与任何其他格式文本一样具有单元格格式(通常为蓝色文本和下划线).

如果在 XlsxWriter 中没有为链接指定其他格式,模块会添加默认(蓝色下划线)格式,就像 Excel 在您输入 url 时所做的那样.这在

I need help with python XlsxWriter. I need to add link styling for external file link columns. But Xlsxwriter doesn't recognize styling for links(its second column) (text: underline, text-color: blue) if I'm adding the text wrapping for another columns(in this example first column).

Here is my example:

# _*_ coding: utf-8
import xlsxwriter

wb = xlsxwriter.Workbook('/home/mtw/Downloads/my_export.xlsx')

format = wb.add_format()
format.set_text_wrap()

sheet = wb.add_worksheet(name='export_object1')
sheet.write_row('A1', [
    u'Its\na bum\nwrap',
    'external:resignation_letter.docx',
], format)
wb.close()

So I need to tell the XlsxWriter that he can recognize and text wrapping and styling for links.

Microsoft office: 2007.

xlsxwriter latest version.

Thx.

解决方案

Links in Excel have cell formatting (generally blue text and an underline) like any other formatted text.

If no other formatting is specified for links in XlsxWriter the module adds a default (blue underline) format, like Excel does when you enter a url. This is explained in the write_url() docs.

However, if the user specifies a format for a cell with a link (like the text_wrap format in your example) then it overrides the default format.

So if you want blue underline plus text wrap format for urls you will have to specify it directly:

import xlsxwriter

workbook = xlsxwriter.Workbook('my_export.xlsx')
worksheet = workbook.add_worksheet(name='export_object1')

link_format = workbook.add_format({'color': 'blue', 
                                   'underline': True, 
                                   'text_wrap': True})

text_format = workbook.add_format({'text_wrap': True})

worksheet.write('A1', 'Its\na bum\nwrap',           text_format)
worksheet.write('B1', 'http://stackoverflow.com/',  link_format)

workbook.close()

Output:

这篇关于python XlsxWriter 文本换行和链接样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆