1
by Sylvain Pineau
Import upstream version 0.5.2 |
1 |
#######################################################################
|
2 |
#
|
|
3 |
# An example of using Python and XlsxWriter to write some "rich strings",
|
|
4 |
# i.e., strings with multiple formats.
|
|
5 |
#
|
|
1.1.1
by Zygmunt Krynicki
Import upstream version 0.6.7 |
6 |
# Copyright 2013-2015, John McNamara, jmcnamara@cpan.org
|
1
by Sylvain Pineau
Import upstream version 0.5.2 |
7 |
#
|
8 |
import xlsxwriter |
|
9 |
||
10 |
workbook = xlsxwriter.Workbook('rich_strings.xlsx') |
|
11 |
worksheet = workbook.add_worksheet() |
|
12 |
||
13 |
worksheet.set_column('A:A', 30) |
|
14 |
||
15 |
# Set up some formats to use.
|
|
16 |
bold = workbook.add_format({'bold': True}) |
|
17 |
italic = workbook.add_format({'italic': True}) |
|
18 |
red = workbook.add_format({'color': 'red'}) |
|
19 |
blue = workbook.add_format({'color': 'blue'}) |
|
20 |
center = workbook.add_format({'align': 'center'}) |
|
21 |
superscript = workbook.add_format({'font_script': 1}) |
|
22 |
||
23 |
# Write some strings with multiple formats.
|
|
24 |
worksheet.write_rich_string('A1', |
|
25 |
'This is ', |
|
26 |
bold, 'bold', |
|
27 |
' and this is ', |
|
28 |
italic, 'italic') |
|
29 |
||
30 |
worksheet.write_rich_string('A3', |
|
31 |
'This is ', |
|
32 |
red, 'red', |
|
33 |
' and this is ', |
|
34 |
blue, 'blue') |
|
35 |
||
36 |
worksheet.write_rich_string('A5', |
|
37 |
'Some ', |
|
38 |
bold, 'bold text', |
|
39 |
' centered', |
|
40 |
center) |
|
41 |
||
42 |
worksheet.write_rich_string('A7', |
|
43 |
italic, |
|
44 |
'j = k', |
|
45 |
superscript, '(n-1)', |
|
46 |
center) |
|
47 |
||
48 |
workbook.close() |