Automatically create word and excel reports in python

excel edition

excel creation

import openpyxl as opy
book = opy.Workbook()

Check the name of the sheet

sheet1 = book.active
sheet1.title

Rename the sheet

sheet1.title = 'mysheet_1'

Create excel file

book.save('make_excel.xlsx')

Open an existing file

my_made = opy.load_workbook('make_excel.xlsx')

Edit the specified sheet

sheet2 = my_made.active
table = my_made[sheet2.title]

Write a character by specifying a cell

table['A1'] = 'How is the weather today'

Reformat cells

from openpyxl.styles import Font
table['A1'].font = Font(bold=True,italic=True,size=28)

word edition

Up to 3.4 to specify docx with pip install After that, specify the package name with python-docx.

Create a file

import docx
doc = docx.Document()

Writing sentences

doc.add_paragraph('How is the weather today')
doc.add_paragraph()
doc.add_paragraph(today_list)
doc.add_paragraph()

Insert image

doc.add_picture('pict.png')

Save file

doc.save('make_word_today.doc')

that's all

Recommended Posts

Automatically create word and excel reports in python
Create and read messagepacks in Python
Parse the Researchmap API in Python and automatically create a Word file for the achievement list
Create SpatiaLite in Python
Python programming in Excel
Get stock prices and create candlestick charts in Python
Create a function in Python
Create a dictionary in Python
Create gif video in Python
Stack and Queue in Python
Unittest and CI in Python
[GCF + Python] How to upload Excel to GCS and create a new table in BigQuery
Manipulate the clipboard in Python and paste the table into Excel
Create code that outputs "A and pretending B" in python
How to log in to AtCoder with Python and submit automatically
MIDI packages in Python midi and pretty_midi
Difference between list () and [] in Python
View photos in Python and html
Sorting algorithm and implementation in Python
Create a DI Container in Python
Automatically format Python code in Vim
Manipulate files and folders in Python
About dtypes in Python and Cython
Create an Excel file with Python3
Assignments and changes in Python objects
Create a binary file in Python
Check and move directories in Python
Create Gmail in Python without API
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
Create Python project documentation in Sphinx
Function synthesis and application in Python
Create a Kubernetes Operator in Python
Export and output files in Python
Reverse Hiragana and Katakana in Python2.7
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
web coder tried excel in Python
Create a random string in Python
Create your own graph structure class and its drawing in python
Create a CGH for branching a laser in Python (laser and SLM required)
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Notes using cChardet and python3-chardet in Python 3.3.1.
Modules and packages in Python are "namespaces"
Avoid nested loops in PHP and Python
Create your own Linux commands in Python
Automatically create Python API documentation with Sphinx
Differences between Ruby and Python in scope
AM modulation and demodulation in Python Part 2
[Python] Automatically and seamlessly combine cropped images
difference between statements (statements) and expressions (expressions) in Python
Create ScriptableObject in Python when building ADX2
Eigenvalues and eigenvectors: Linear algebra in Python <7>
[LLDB] Create your own command in Python
Implementation module "deque" in queue and Python
Line graphs and scale lines in python
Create a simple GUI app in Python
Draw Nozomi Sasaki in Excel with python
Implement FIR filters in Python and C
Check and receive Serial port in Python (Port check)