电脑是32位系统,pycharm也是32位,用这段代码编译出了程序,这程序在32位上完美运行。现在没有64位系统,没法测试,请帮我看看,能不能在64位上使用?
from docx import Document
document =Document("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx")
import os #获取当前目录
os.getcwd()
def delete_paragraph(paragraph): #删除段落函数
p = paragraph._element
p.getparent().remove(p)
# p._p = p._element = None
paragraph._p = paragraph._element = None
all_paragraphs = document.paragraphs
for paragraph in all_paragraphs: #执行删除段落
delete_paragraph(paragraph) #执行删除段落
#以下实现获取当前时间功能
import time
nowtime=str(time.ctime())
print(nowtime) #第一种时间格式Mon May 17 12:10:46 2021
def get_current_time(is_chinese=False):
import time
import locale
if not is_chinese:
return time.strftime('%Y-%m-%d %H:%M:%S')
elif is_chinese:
locale.setlocale(locale.LC_CTYPE, 'chinese')
return time.strftime('%Y年%m月%d日%H时%M分%S秒')
nowtime1=get_current_time()
print(nowtime1) #第二种时间格式2021-05-17 12:10:47
#以下实现项目与价格内容累加计算等功能
class Product:
def __init__(self, name, price):
self.name = name
self.price = price
def create_receipt(products):
total_price = sum(product.price for product in products)
receipt = f"{'项目名称'.ljust(10,' ')} {'价格(元)':<10}\n"
#<表示左对齐,后面的数字表示宽度。ljust第一个参数表示左对齐,几个宽度,第二参数是不足用全角空格代替,这个全角空格自己输进去
for product in products:
receipt += f"{product.name.ljust(10,' ')} {product.price:<10}\n"
receipt += f"\n{'总价'.ljust(10,' ')} {total_price:<10}"
return receipt
#参考项目的名称与价格
# 创建一些商品
name=input("请输入项目名称:")
price=int(input("请输入当前项目价格:"))
product1=Product(name,price)
products=[product1]
#不够再加项目与价格
while (input("结束输入请输入1并按回车键") != "1"):
name = input("请输入项目名称:")
price = int(input("请输入当前项目价格:"))
product1= Product(name, price)
products.append(product1)
# 创建并打印小票
receipt = create_receipt(products)
print(receipt)
#以下是自定义函数,用以设置每段字体
# 以下是字体的设置,小心原来的文档要关闭。
from docx import Document
from docx.oxml.ns import qn
from docx.shared import Pt, RGBColor
def type (neirong,ziti,zitidaxiao,jiacu,qingxie):
p3 = document.add_paragraph()
text3 = p3.add_run(neirong)
text3.font.name = ziti
text3._element.rPr.rFonts.set(qn('w:eastAsia'),ziti)
text3.font.size = Pt(zitidaxiao) # 5,5.5,6.5,7.5,9,10.5是5号,12,14,15,16,18,22,24,26,36,42
text3.font.color.rgb = RGBColor(0, 0, 0)
text3.bold = jiacu
text3.italic =qingxie
type(" 收费小结", u'宋体',12, True, False)
type("-----------------------------------------", u'宋体',6.5, True, False)
type(receipt, u'宋体', 9, True, False)
type("-----------------------------------------", u'宋体',6.5, True, False)
type(nowtime1, u'宋体', 9, True, False)
remark=input("请输入备注内容:")
type("备注:"+remark, u'宋体', 12, True, False)
document.save("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx") #文件名使用反斜杠
input("please input any key to go on!已经保存确定后开始打印")
#以下实现打印功能
import tempfile
import win32api
import win32print
def printer_loading(filename):
open(filename, "r")
win32api.ShellExecute(
0,
"print",
filename,
#
# If this is None, the default printer will
# be used anyway.
#
'/d:"%s"' % win32print.GetDefaultPrinter(),
".",
0
)
printer_loading("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx")
input("please input any key to go on!正在打印,请等待启动word文档,确定后保存记录")
#以下实现把数据写入txt作记录
from docx import Document # *.py 文件名不能与库所需的关键词同名
#打开word文档
document = Document("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx")
#获取所有段落
all_paragraphs = document.paragraphs
#打印看看all_paragraphs是什么东西
print(all_paragraphs) #<class 'list'>,打印后发现是列表 。这里有更改过,删了type()
#是列表就开始循环读取
f = open("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结记录.txt", "a+") # 以追加的方式
f.write("\n") # 写完通过\n进行换行
f.write("-------------------------------------------------------------------------------")
f.write("\n") # 写完通过\n进行换行
f.write(nowtime1)
f.write("\n") # 写完通过\n进行换行
for paragraph in all_paragraphs:
#打印每一个段落的文字
f = open("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结记录.txt", "a+") # 以追加的方式
f.write(paragraph.text)
f.write("\n") # 写完通过\n进行换行
f.close()
print(paragraph.text)
input("please input any key to exit!")
from docx import Document
document =Document("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx")
import os #获取当前目录
os.getcwd()
def delete_paragraph(paragraph): #删除段落函数
p = paragraph._element
p.getparent().remove(p)
# p._p = p._element = None
paragraph._p = paragraph._element = None
all_paragraphs = document.paragraphs
for paragraph in all_paragraphs: #执行删除段落
delete_paragraph(paragraph) #执行删除段落
#以下实现获取当前时间功能
import time
nowtime=str(time.ctime())
print(nowtime) #第一种时间格式Mon May 17 12:10:46 2021
def get_current_time(is_chinese=False):
import time
import locale
if not is_chinese:
return time.strftime('%Y-%m-%d %H:%M:%S')
elif is_chinese:
locale.setlocale(locale.LC_CTYPE, 'chinese')
return time.strftime('%Y年%m月%d日%H时%M分%S秒')
nowtime1=get_current_time()
print(nowtime1) #第二种时间格式2021-05-17 12:10:47
#以下实现项目与价格内容累加计算等功能
class Product:
def __init__(self, name, price):
self.name = name
self.price = price
def create_receipt(products):
total_price = sum(product.price for product in products)
receipt = f"{'项目名称'.ljust(10,' ')} {'价格(元)':<10}\n"
#<表示左对齐,后面的数字表示宽度。ljust第一个参数表示左对齐,几个宽度,第二参数是不足用全角空格代替,这个全角空格自己输进去
for product in products:
receipt += f"{product.name.ljust(10,' ')} {product.price:<10}\n"
receipt += f"\n{'总价'.ljust(10,' ')} {total_price:<10}"
return receipt
#参考项目的名称与价格
# 创建一些商品
name=input("请输入项目名称:")
price=int(input("请输入当前项目价格:"))
product1=Product(name,price)
products=[product1]
#不够再加项目与价格
while (input("结束输入请输入1并按回车键") != "1"):
name = input("请输入项目名称:")
price = int(input("请输入当前项目价格:"))
product1= Product(name, price)
products.append(product1)
# 创建并打印小票
receipt = create_receipt(products)
print(receipt)
#以下是自定义函数,用以设置每段字体
# 以下是字体的设置,小心原来的文档要关闭。
from docx import Document
from docx.oxml.ns import qn
from docx.shared import Pt, RGBColor
def type (neirong,ziti,zitidaxiao,jiacu,qingxie):
p3 = document.add_paragraph()
text3 = p3.add_run(neirong)
text3.font.name = ziti
text3._element.rPr.rFonts.set(qn('w:eastAsia'),ziti)
text3.font.size = Pt(zitidaxiao) # 5,5.5,6.5,7.5,9,10.5是5号,12,14,15,16,18,22,24,26,36,42
text3.font.color.rgb = RGBColor(0, 0, 0)
text3.bold = jiacu
text3.italic =qingxie
type(" 收费小结", u'宋体',12, True, False)
type("-----------------------------------------", u'宋体',6.5, True, False)
type(receipt, u'宋体', 9, True, False)
type("-----------------------------------------", u'宋体',6.5, True, False)
type(nowtime1, u'宋体', 9, True, False)
remark=input("请输入备注内容:")
type("备注:"+remark, u'宋体', 12, True, False)
document.save("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx") #文件名使用反斜杠
input("please input any key to go on!已经保存确定后开始打印")
#以下实现打印功能
import tempfile
import win32api
import win32print
def printer_loading(filename):
open(filename, "r")
win32api.ShellExecute(
0,
"print",
filename,
#
# If this is None, the default printer will
# be used anyway.
#
'/d:"%s"' % win32print.GetDefaultPrinter(),
".",
0
)
printer_loading("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx")
input("please input any key to go on!正在打印,请等待启动word文档,确定后保存记录")
#以下实现把数据写入txt作记录
from docx import Document # *.py 文件名不能与库所需的关键词同名
#打开word文档
document = Document("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结.docx")
#获取所有段落
all_paragraphs = document.paragraphs
#打印看看all_paragraphs是什么东西
print(all_paragraphs) #<class 'list'>,打印后发现是列表 。这里有更改过,删了type()
#是列表就开始循环读取
f = open("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结记录.txt", "a+") # 以追加的方式
f.write("\n") # 写完通过\n进行换行
f.write("-------------------------------------------------------------------------------")
f.write("\n") # 写完通过\n进行换行
f.write(nowtime1)
f.write("\n") # 写完通过\n进行换行
for paragraph in all_paragraphs:
#打印每一个段落的文字
f = open("F:/新建文件夹 (4)/口腔小常识/上标题/下标题/收费小结记录.txt", "a+") # 以追加的方式
f.write(paragraph.text)
f.write("\n") # 写完通过\n进行换行
f.close()
print(paragraph.text)
input("please input any key to exit!")