软件名称
(一个自用的脚本,没有名字
)
应用平台
Windows
注意:
- 该脚本依赖 MS Word 和 MS PowerPoint 工作,因此只能在 Windows 上运行。
- 该脚本已停止维护,但理论上还能用。
推荐类型
【开发者自荐】
一句简介
一个统计当前文件夹下所有 pdf 文档、docx 文档以及 pptx 文档总页数的小工具。支持计算双面打印耗纸量。
源代码与下载链接
如果您的电脑上没有 Python,也可以直接使用打包好的二进制文件:
- 下载链接:https://wwba.lanzoum.com/ilMnh0l0407i
- 密码:
h5ta - SHA256:
134716f4adc97a5bbb7ef94ec898f233807ff88b0186fe54b5d97590fca0a5af - 架构:AMD64
代码很简单。如果您想直接使用该脚本,请先安装 win32com 和 PyPDF3 两个库:
点击此处展开代码
import os
import math
from win32com.client import Dispatch
from PyPDF3 import PdfFileReader
def get_word_page(word_path):
word = Dispatch('Word.Application')
word.Visible = False
word = word.Documents.Open(word_path)
word.Repaginate()
num_of_sheets = word.ComputeStatistics(2)
return num_of_sheets
def get_pdf_page(pdf_path):
filename = pdf_path
reader = PdfFileReader(filename)
if reader.isEncrypted:
reader.decrypt('')
page = reader.getNumPages()
return page
page_sum = 0
cost_sum = 0
number_of_docx = 0
number_of_doc = 0
number_of_pdf = 0
page_of_docx = 0
page_of_doc = 0
page_of_pdf = 0
cost_of_docx = 0
cost_of_doc = 0
cost_of_pdf = 0
l=os.listdir('.')
for file in l:
if file.endswith('.docx'):
docfile=f"{os.getcwd()}/{file}"
docfile=docfile.replace("\\","/")
p=get_word_page(docfile)
number_of_docx+=1
page_of_docx+=p
cost_of_docx+=math.ceil(p/2)
if file.endswith('.doc'):
docfile=f"{os.getcwd()}/{file}"
docfile=docfile.replace("\\","/")
p=get_word_page(docfile)
number_of_doc+=1
page_of_doc+=p
cost_of_doc+=math.ceil(p/2)
if file.endswith('.pdf'):
p=get_pdf_page(file)
number_of_pdf+=1
page_of_pdf+=p
cost_of_pdf+=math.ceil(p/2)
page_sum=page_of_doc+page_of_docx+page_of_pdf
cost_sum=cost_of_doc+cost_of_docx+cost_of_pdf
print("统计报告")
print("当前目录下,有:")
print("docx 文档")
print(" 文件个数:", number_of_docx)
print(" 总页数:", page_of_docx)
print(" 如双面打印,须消耗纸张数:", cost_of_docx)
print("doc 文档")
print(" 文件个数:", number_of_doc)
print(" 总页数:", page_of_doc)
print(" 如双面打印,须消耗纸张数:", cost_of_doc)
print("pdf 文档")
print(" 文件个数:", number_of_pdf)
print(" 总页数:", page_of_pdf)
print(" 如双面打印,须消耗纸张数:", cost_of_pdf)
print("小结")
print(" 文件总页数:", page_sum)
print(" 如双面打印所有文档,须消耗纸张数:", cost_sum)
input("按 Enter 退出。")
附言
这是之前为了回答一位朋友的问题而写的小脚本,感觉可能有点用,就单独发出来了。
不过请注意:本人平时没有精力继续维护这个脚本。如果需要增加更多功能或进行优化,只能请大家自己动手,或借助 AI。
