00读取csv文件

import csv
def readCsv(path):infolist = []with open (path,"r") as f:allFileInfo = csv.reader(f)print(allFileInfo)for row in allFileInfo:infolist.append(row)return infolistpath =r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\2、读写csv文件\000001.csv"
info = readCsv(path)
# [[],[],[]]

01写csv文件

import csvdef writeCsv(path,data):with open(path,"w")as f:write = csv.writer(f)for rowData in data:print("*********")write.writerow(rowData)path =r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\2、读写csv文件\000003.csv"
writeCsv(path, [[1,2,3],[4,5,6],[7,8,9]])

02读取pdf文件

import sys
import importlib
importlib.reload(sys)from pdfminer.pdfparser import PDFParser, PDFDocument
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import PDFPageAggregator
from pdfminer.layout import LTTextBoxHorizontal, LAParams
from pdfminer.pdfinterp import PDFTextExtractionNotAlloweddef readPDF(path,topath):#以二进制打开pdf文件f = open(path,"rb")#创建一个PDF文档分析器parse = PDFParser(f)#创建PDF文档pdfFile = PDFDocument()#链接 分析器与文档对象 互相连接parse.set_document(pdfFile)pdfFile.set_parser(parse)#提供初始化密码pdfFile.initialize()#检测文档是否提供txt转换if not pdfFile.is_extractable:raise PDFTextExtractionNotAllowedelse:#解析数据#数据管理器manager = PDFResourceManager()#创建一个PDF设备的对象laparams= LAParams()device = PDFPageAggregator(manager,laparams=laparams)#解释器对象interpreter = PDFPageInterpreter(manager,device)#开始循环处理,每次处理一页for page in pdfFile.get_pages():interpreter.process_page(page)layout =device.get_result()for x in layout:if (isinstance(x,LTTextBoxHorizontal)):with open(topath,"a")as f:str = x.get_text()# print(str)f.write(str+"\n")topath=r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\a.txt"
path =r"D:\xiazaipan\第1章  Python语言基础\16、py2与py3的区别和测试\0-作业\文件的封装\sunck.pdf"
readPDF(path,topath)

03播放音乐

#pip install pygameimport time
import pygame#音乐路径
filePath = r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\7、播放音乐\res\0.mp3"# 初始化
pygame.mixer.init()#加载音乐
track = pygame.mixer.music.load(filePath)#播放
pygame.mixer.music.play()#
time.sleep(5)
pygame.mixer.music.pause()#暂停
#停止
pygame.mixer.music.stop()

04修改背景图片

# win键加R   ->regedit ->HKEY_CURRENT_USER->
#Control panel->Desktop->import win32api
import win32con
import win32guidef setWallPaper(path):#打开注册表reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)#2拉伸 0居中 6适应 10填充win32api.RegSetValueEx(reg_key,"WallpaperStyle",0,win32con.REG_SZ,"6")## win32api.RegSetValueEx(reg_key,)# win32api.RegSetValueEx(reg_key,"WallPaper" )# win32con.SPIF_SENDWININICHANGE立即生效win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,path,win32con.SPIF_SENDWININICHANGE)# 图片地址
setWallPaper(r"")

05整蛊程序

import time
import pygame
import win32api
import win32con
import win32gui
import threadingdef go():pygame.mixer.init()while 1:for i in range(5):filePath =\r"H:\QIANfeng code\17自动化办公鼠标键盘模拟\res"+"\\"+str(i)+".mp3"track = pygame.mixer.music.load(filePath)pygame.mixer.music.play()time.sleep(10)pygame.mixer.music.stop()def setWallPaper(path):reg_key = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)win32api.RegSetValueEx(reg_key,"WallpaperStyle",0,win32con.REG_SZ,"6")win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,path,win32con.SPIF_SENDWININICHANGE)
#线程
th = threading.Thread(target = go ,name ="LoopThread")
th.start()
while True:go()for i in range(9):filePath = r"H:\QIANfeng code\17自动化办公鼠标键盘模拟\res1"+"\\"+str(i)+".jpeg"print(filePath)setWallPaper(filePath)time.sleep(5)

06键盘模拟

import win32con
import win32api
import time'''
win32api.keybd_event(91,0,0,0)
time.sleep(0.1)
win32api.keybd_event(91,0,win32con.KEYEVENTF_KEYUP,0)
'''
while 1 :win32api.keybd_event(91,0,0,0)time.sleep(0.1)win32api.keybd_event(77,0,0,0)time.sleep(0.1)win32api.keybd_event(77,0,win32con.KEYEVENTF_KEYUP,0)win32api.keybd_event(91, 0, win32con.KEYEVENTF_KEYUP, 0)time.sleep(3)

07语音控制游戏

08鼠标模拟

import win32con
import win32api
import timewin32api.SetCursorPos([30,40])
time.sleep(0.1)
#鼠标左键按下
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0)
#鼠标左键抬起
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0)win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0)

09读取doc与docx文件

import win32com
import win32com.clientdef readWordFile(path):#调用系统word功能,可以处理doc和 docx两种文件mw = win32com.client.Dispatch("Word.Application")#打开文件doc = mw.Documents.Open(path)for paragraph in doc.Paragraphs:line = paragraph.Range.Textprint(line)#关闭文件doc.Close()#退出文件mw.Quit()path = r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\4、word自动化办公\sunck.doc"
readWordFile(path)

10读取doc与docx文件并写入其他文件

import win32com
import win32com.clientdef readWordFile(path):mw = win32com.client.Dispatch("Word.Application")doc = mw.Documents.Open(path)#将word的数据保存到另一个文件doc.SaveAs(toPath,2)#2表示txt文件doc.Close()mw.Quit()toPath = r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\4、word自动化办公\1.txt"

11创建word文件

import win32com
import win32com.client
import osdef makeWordFile(path,name):word = win32com.client.Dispatch("Word.Application")#创建文档doc = word.Documents.Add()#文档可见word.Visible = True#写内容#从头开始写r = doc.Range(0,0)r.InsertAfter("亲爱的"+name+"\n")r.InsertAfter("想你")#存储文件doc.SaveAs(path)#关闭文件doc.Close()#退出文件# word.Quit()names = ["zhangsan","lisi","wangwu"]
for name in names:path = os.path.join(os.getcwd(),name)makeWordFile(path,name)path = r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\4、word自动化办公"

12读取xlsx文件

#xlsx xls
#openpyxl->xlsxfrom openpyxl.reader.excel import load_workbookdef readXlsxFile(path):file= load_workbook(filename = path)print(file.get_sheet_names())sheets = file.get_sheet_names()#拿出一个表格sheet = file.get_sheet_by_name(sheets[0])#最大行数print(sheet.max_row)#最大列数print(sheet.max_column)#表名print(sheet.title)for lineNum in range(1,sheet.max_row+1):print(lineNum)lineList = []for columnNum in range(1,sheet.max_column):#拿数据value = sheet.cell(row=lineNum,column = columnNum).value# if value!=None:lineList.append(value)print(lineList)path= r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\5、excel自动化办公\1.xlsx"
readXlsxFile(path)

13返回整体xlsx数据

#  xlsx   xls
# openpyxl  ->  xlsxfrom openpyxl.reader.excel import load_workbookdef readXlsxFile(path):dic = {}file = load_workbook(filename=path)sheets = file.get_sheet_names()print(len(sheets))for sheetName in sheets:sheet = file.get_sheet_by_name(sheetName)#一张表的所有数据sheetInfo = []for lineNum in range(1, sheet.max_row + 1):lineList = []for columnNum in range(1, sheet.max_column + 1):value = sheet.cell(row=lineNum, column=columnNum).valuelineList.append(value)sheetInfo.append(lineList)#将一张表的数据存到字典dic[sheetName] = sheetInforeturn dic#不能处理xls文件
path = r""
dic = readXlsxFile(path)
print(dic["安力博发"])
print(len(dic))

14返回xls和xlsx文件内容

#有序字典
from collections import OrderedDict
#读取数据
from pyexcel_xls import get_datadef readXlsAndXlsxFile(path):dic = OrderedDict()#抓取数据xdata = get_data(path)for sheet in xdata:dic[sheet]= xdata[sheet]return dicpath= r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\5、excel自动化办公\1.xlsx"
dic = readXlsAndXlsxFile(path)
print(dic)
print(len(dic))

15写入xls文件

#有序字典
from collections import OrderedDict
#读取数据
from pyexcel_xls import get_data
from pyexcel_xls import save_datadef makeExcelFile(path,data):dic = OrderedDict()for sheetName,sheetValue in data.items():d= {}d[sheetName]=sheetValuedic.update(d)save_data(path,dic)#只能写xls
path= r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\5、excel自动化办公\11.xls"
makeExcelFile(path,{"表1":[[1,2,3],[4,5,6]],"表2":[[11,22,33],[44,55,66]]})

16写ppt

import win32com
import win32com.clientdef makeppt(path):ppt = win32com.client.Dispatch("PowerPoint.Application")ppt.Visible=True#增加一个文件pptFile = ppt.Presentations.Add()#创建页  参数1为页数 参数2为主题类型page1 = pptFile.Slides.Add(1,1)#正标题副标题 就两个t1 = page1.Shapes[0].TextFrame.TextRanget1.Text = "Liuwang "t2 = page1.Shapes[1].TextFrame.TextRanget2.Text = "Liuwang is a good man  "# 第二页page2 = pptFile.Slides.Add(2, 2)t3 = page2.Shapes[0].TextFrame.TextRanget3.Text = "LiuGE "t4 = page2.Shapes[1].TextFrame.TextRanget4.Text = "LiuGE is a good man  "#保存pptFile.SaveAs(path)pptFile.Close()ppt.Quit()path = r"D:\xiazaipan\第1章  Python语言基础\15、自动化办公与鼠标键盘模拟\4、word自动化办公"
makeppt(path)

python中自动化办公 【笔记】相关推荐

  1. Python实现自动化办公(三):Python对PPT文档的基本操作(python-pptx)

    Python对PPT文档的基本操作 文章目录 Python对PPT文档的基本操作 一.pptx模块 1.官方文档 2.安装pptx模块 二.基本函数的使用方法 三.使用案例 1.修改ppt内容 2.写 ...

  2. Python编程自动化办公案例(3)

    · 作者简介:一名在校计算机学生.每天分享Python的学习经验.和学习笔记.   座右铭:低头赶路,敬事如仪 个人主页:网络豆的主页​​​​​​ 目录 前言 一.前几章代码 1.获取到第一题的选项单 ...

  3. python自动化办公入门书籍推荐-盘点使用Python进行自动化办公所需要的知识点

    知乎上有人提问:用python进行办公自动化都需要学习什么知识呢? 这可能是很多非IT职场人士面临的困惑,想把python用到工作中,却不知如何下手?python在自动化办公领域越来越受欢迎,批量处理 ...

  4. python自动化办公培训排名-盘点使用Python进行自动化办公所需要的知识点

    三军可夺帅也,匹夫不可夺志也. 知乎上有人提问:用python进行办公自动化都需要学习什么知识呢? 这可能是很多非IT职场人士面临的困惑,想把python用到工作中,却不知如何下手?python在自动 ...

  5. python自动化办公入门书籍-盘点使用Python进行自动化办公所需要的知识点

    知乎上有人提问:用python进行办公自动化都需要学习什么知识呢? 这可能是很多非IT职场人士面临的困惑,想把python用到工作中,却不知如何下手?python在自动化办公领域越来越受欢迎,批量处理 ...

  6. python自动化办公都能做什么-盘点使用Python进行自动化办公所需要的知识点

    三军可夺帅也,匹夫不可夺志也. 知乎上有人提问:用python进行办公自动化都需要学习什么知识呢? 这可能是很多非IT职场人士面临的困惑,想把python用到工作中,却不知如何下手?python在自动 ...

  7. 用python实现自动化办公------Excel操作

    用python实现自动化办公------Excel操作 用python实现自动化办公------Excel操作 用python实现自动化办公------Excel操作 摘要 一 matplotlib和 ...

  8. 如何用python实现自动化办公_Python自动化办公都需要掌握什么知识?

    知乎上有人提问:用python进行办公自动化都需要学习什么知识呢? 这可能是很多非IT职场人士面临的困惑,想把python用到工作中,却不知如何下手?python在自动化办公领域越来越受欢迎,批量处理 ...

  9. python自动化办公教程书籍_盘点使用Python进行自动化办公所需要的知识点

    知乎上有人提问:用python进行办公自动化都需要学习什么知识呢? 这可能是很多非IT职场人士面临的困惑,想把python用到工作中,却不知如何下手?python在自动化办公领域越来越受欢迎,批量处理 ...

最新文章

  1. ppt 的局部分大功能软件介绍.ZoomIt
  2. 2074. 反转偶数长度组的节点
  3. python包numpy_NumPy Python科学计算软件包的终极指南
  4. 开发到底喜欢看怎样的需求文档
  5. Qt多线程端口扫描工具(开源)
  6. linux barrier,如何决定何时启用Linux文件系统barrier功能?
  7. J2EE五层架构概念[转+整理]
  8. 040、JVM实战总结:案例实战:每日百亿数据量的实时分析引擎,为啥频繁发生Full GC ?
  9. flume消费kafka数据太慢_kafka补充01
  10. linux列出一个目录及其子目录下面的某种类型的文件
  11. 超链接为什么在HTML的head可以运行,悬赏问答 - HTML开发中,为什么最好把CSS的link标签放在head/head之间??...
  12. cadence17.2小白eda365skill 安装教程
  13. 淘票票经典Python爬虫案例
  14. 编写一个非常简单的 JavaScript 编辑器
  15. 前端-深克隆与浅克隆
  16. 机器人前沿--下肢外骨骼机器人
  17. 关于软件注册问题的讨论
  18. iPhoneX(刘海屏)适配
  19. TTS(TextToSpeach)语音朗读实例
  20. 小程序 JSON.stringify() 和 JSON.parse() 的使用

热门文章

  1. linux下gdb单步调试
  2. GCC中SIMD指令的应用方法
  3. 手机号码归属地及运营商查询
  4. 使用编辑工具快速创建实体对象的方法
  5. Error: Can't resolve 'babel-loader'
  6. Win7 U盘安装Ubuntu16.04 双系统
  7. mysql5.5提示Deprecated: mysql_query(): The mysql extension is deprecated
  8. BZOJ 1968: [Ahoi2005]COMMON 约数研究 水题
  9. performSegueWithIdentifier:sender里边的sender是啥意思
  10. 从Loagistic 到 SVM算法