A module that allows you to create Excel files (extension xlsx) using Python. You can generate tables that appeared in Excel 2007 or later, tweak each cell property, and create a fairly full-scale form. Due to various circumstances, the final output format must be Excel, but it is recommended when input is very troublesome and you can not write Excel normally.
For the time being, just touch.
For the time being, you can install it with easyinstall. This is OK even under Windows environment
> easy_install xlsxwriter
First, import the module with ʻimport xls xwriter`. Next, create a workbook by specifying the file name, insert several worksheets as needed, and close the workbook when the processing is completed, and the file will be completed.
sample.py
import xlsxwriter
wb = xlsxwriter.Workbook('test.xlsx')
ws = wb.add_worksheet("Sheet name")
ws.write(0, 0, "Test test test")
wb.close()
You can also create tables added in Excel 2007 or later.
sample.py
#Omission
data = []
headers = [
{ "header": "Header 1"},
{ "header": "Header 2"},
{ "header": "Header 3"}]
ws.add_table(0, 0, len(data) - 1, len(headers) - 1, {
'data': data,
'autofilter': True,
'header_row': True,
'banded_rows': True,
'banded_columns': True,
'first_column': True,
'columns': headers
})
#Omission
Now you have a table. Sounds good.
The only thing I tried was "wrap around and display the whole".
set_text_wrap.py
#Omission
format = workbook.add_format()
format.set_text_wrap()
ws.set_column(0, 0, 13)
ws.set_column(1, 2, 13, format)
#Omission
The first argument of set_column () is the column number of the first column that uses this format, the second argument is the column number of the last column, the third argument is the column width, and the last object that specifies the format. If you have one, specify it in the fourth argument.
You can find a lot of information on the module page. http://xlsxwriter.readthedocs.org/en/latest/ Looking at the bottom right of the screen, it seems that we are trying to get a reference in PDF or ePUB format.
Recommended Posts