Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing URLs as a plain text to Excel in Python via XLSXwriter

Is it possible to write urls to .xlsx file via XLSXwriter as a plain text (without hyperlinks)? I mean, when I write urls, they are inserted as visible part and hyperlink. I would like to avoid hyperlink and leave url as a simple text string without any formatting

Here is my code:

b = xlsxwriter.Workbook(fn+'_'+time.strftime('%d.%m.%Y_%H-%M-%S')+'.xlsx')
s = b.add_worksheet()
s.set_zoom(125)
s.set_column('A:K', 30)
format = b.add_format({'align': 'left', 'font_name': 'Arial', 'font_size': 10})

s.write_row(0, 0, head, format)
for i in range(len(cols)):
    s.write_column(1, i, cols[i], format)

b.close()

thanks,

like image 489
user1192422 Avatar asked Oct 20 '25 11:10

user1192422


1 Answers

You could use the write_string() method instead of write_column(). The write_column() method calls write() which calls write_url() by default. That would require you to roll your own loop.

Or set the workbook constructor property to tell the module to ignore urls when calling write():

workbook = xlsxwriter.Workbook(filename, {'strings_to_urls': False})
like image 109
jmcnamara Avatar answered Oct 23 '25 07:10

jmcnamara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!