import openpyxl
from openpyxl import Workbook
xlsx=Workbook()
xlsx=openpyxl.load_workbook(filename,data_only=False)
xlsx.sheetnames
xlsx.save(filename.xlsx)
xlsx.remove(sheet_name)
del xlsx['sheet_name']
copy_sheet=xlsx.copy_worksheet(source_xlsx)
sheet=xlsx.create_sheet('sheet_name',index)
sheet=xlsx.active
sheet=xlsx['sheet_name']
sheet.title
sheet.append(list)
for row in sheet.values:
for value in row:pass
sheet.sheet_properties.tabColor='1072BA'
sheet.max_row
sheet.max_column
sheet.row_dimensions[num_index].height = 40
sheet.column_dimensions['letter_index'].width = 30
sheet.merge_cells('A1:C3')
sheet.unmerge_cells('A1:C3')
sheet.freeze_panes='coordinate'
list(sheet.rows)
list(sheet.columns)
a1=sheet['A1']
a1.value
a1.row
a1.column
a1.coordinate
a1=sheet.cell(row=row_num,column=col_num,value=None)
from openpyxl.utils import get_column_letter, column_index_from_string
get_column_letter(int)
column_index_from_string('letter')
a1=value
a1=datetime.datetime.now().strftime("%Y-%m-%d")
from openpyxl.styles import Font, Border, Side, PatternFill, colors, Alignment
a1.font=Font(name='等线', size=24, italic=True, underline=True,color=colors.RED, bold=True)
a1.alignment=Alignment(horizontal='center', vertical='right')
left, right, top, bottom = [Side(style='thin', color='000000')] * 4
a1.border = Border(left=left, right=right, top=top, bottom=bottom)
cell_slice=sheet['coordinate_start':'coordinate_end']
column=sheet['column_letter']
column_slice=sheet['letter_start:letter_end']
row=sheet[row_num]
row_slice=sheet[num_start:num_end]
for row in sheet.iter_rows(min_row=row_num,min_col=col_num,max_row=row_num,max_col=col_num,values_only=False):
for cell in row:pass
for col in sheet.iter_cols(min_row=row_num,min_col=col_num,max_row=row_num,max_col=col_num,values_only=False):pass
for row in sheet.rows:
for cell in row:
print(cell.value,cell.coordinate)
for column in sheet.columns:
for cell in column:
print(cell.value,cell.coordinate)
cols_list=list(zip(*rows_list))
from openpyxl.drawing.image import Image
sheet.add_image(Image('logo.png'), 'A1')
import PyPDF3
with open('file.pdf','rb') as f:
pdf_reader=PyPDF3.PdfFileReader(f)
pdf_reader.numPages
pdf_reader.isEncrypted
pdf_reader.decrypt('str')
page=pdf_reader.getPage(index)
page.rotateClockwise(90)
page.mergePage(another_page)
page_text=page.extractText()
pdf_writer=PyPDF3.PdfFileWriter()
pdf_writer.encrypt('str')
for pagenum in range(pdf_reader.numPages):
pdf_writer.addPage(pdf_reader.getPage(pagenum))
with open('newfile.pdf','wb') as f:
pdf_writer.write(f)
import docx
doc=docx.Document('file.docx')
new_doc=docx.Document()
new_doc.add_picture('pic_file',width=docx.shared.Inches(float),height=docx.shared.Cm(float))
new_doc.add_heading(str,int)
new_para=new_doc.add_paragraph(str,'Style')
new_para.add_run(str)
new_doc.save('file.docx')
paragraphs_list=doc.paragraphs
para1=doc.paragraphs[0]
para1.text
para1.style='Style'
runs_list=para1.runs
run1=runs_list[0]
run1.text=sting
run1.style='StyleChar'
run1.bold=True
run1.italic=True
run1.underline=True
run1.strike=True
run1.double_strike=True
run1.all_caps=True
run1.small_caps=True
run1.shadow=True
run1.outline=True
run1.rtl=True
run1.imprint=True
run1.emboss=True
run1.add_break()
run1.add_break(docx.text.WD_BREAK.PAGE)
'Style':
Normal
BodyText
BodyText2-3
Caption
Heading1-9
IntenseQuote
List
List2-3
ListBullet
ListBullet2-3
ListContinue
ListContinue2-3
ListNumber
ListNumber2-3
ListParagraph
MacroText
NoSpacing
Quote
Subtitle
TOCHeading
Title