会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 128427个问题
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 1楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 2楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 3楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 4楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 5楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 8楼

image.png

Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 9楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 10楼

#pip install python-pptx
from pptx import Presentation
def creat_ppt():
    #创建ppt对象
    ppt = Presentation()
    #添加幻灯片
    ppt.slides.add_slide(ppt.slide_layouts[0])
    #保存
    ppt.save('./creat_ppts/01_ppt.pptx')

if __name__ == '__main__':
    creat_ppt()

Traceback (most recent call last):

  File "D:\Users\W9020478\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\compat\__init__.py", line 10, in <module>

    Container = collections.abc.Container

                ^^^^^^^^^^^^^^^

AttributeError: module 'collections' has no attribute 'abc'     


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "f:\vscode\auto_ppt\01creat_ppt.py", line 2, in <module> 

    from pptx import Presentation

  File "D:\Users\W9020478\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\__init__.py", line 14, in <module>     

    from pptx.api import Presentation  # noqa

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "D:\Users\W9020478\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\api.py", line 15, in <module>

    from .package import Package

  File "D:\Users\W9020478\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\package.py", line 6, in <module>

    from pptx.opc.package import OpcPackage

  File "D:\Users\W9020478\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\opc\package.py", line 11, in <module>

    from pptx.compat import is_string, Mapping

  File "D:\Users\W9020478\AppData\Local\Programs\Python\Python311\Lib\site-packages\pptx\compat\__init__.py", line 14, in <module>

    Container = collections.Container

                ^^^^^^^^^^^^^^^^^^^^^

AttributeError: module 'collections' has no attribute 'Container'

这是什么错误

Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 11楼

import xlrd,xlwt
from xlutils.copy import copy

#读取excel
def read_excel():
    #打开excel文件
    read_wb = xlrd.open_workbook('./creat_excel/08count_data.xlsx')
    #获取工作簿
    read_ws = read_wb.sheet_by_index(0)
    #遍历数据集
     #统计
    count_price = []#各水果总价列表
    fen_type = {} #各品级水果总价字典
    for r in range(1,read_ws.nrows):
        count = read_ws.cell_value(r,2)*read_ws.cell_value(r,3)
        count_price.append(count)
        key = read_ws.cell_value(r,0)
        fen_type[key] = count
        if fen_type.get(key):
            fen_type[key] += count
        else:
            fen_type[key] = count
    return count_price,fen_type

#保存数据
def save_excel(count,fen):
    #打开excel文件
    read_wb = xlrd.open_workbook('./creat_excel/08count_data.xlsx')
    read_ws = read_wb.sheet_by_index(0)
    #复制并修改
    new_wb = copy(read_wb)
    new_ws = new_wb.get_sheet(0)
    #总价计算
    for r in range(1,read_ws.nrows):
        new_ws.write(r,4,count[r-1])
    #创建单独工作表
    new_ws2 = new_wb.add_sheet('汇总数据')
    for i,key in enumerate(fen.keys()):
        _type = key
        data = fen.get(key)
        #汇总类和总价
        new_ws2.write(i,0,key)
        new_ws2.write(i,1,data)
    #保存数据
    new_wb.save('./creat_excel/09count_data.xlsx')

if __name__=='__main__':
    c,f = read_excel()
    save_excel(c,f)

执行结果

image.png汇总结果不正确

Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 12楼
Python 全系列/ 第十四阶段:自动化操作办公软件、邮件、定时任务等/办公自动化 14楼

百战程序员微信公众号

百战程序员微信小程序

©2014-2024 百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637