美文网首页
打印门贴签到表

打印门贴签到表

作者: Noza_ea8f | 来源:发表于2019-12-04 09:07 被阅读0次
    # -*- coding: utf-8 -*-
    # @Time    : 2018/12/7 0007 9:44
    # @Author  : Noza
    # @Email   : wz_spinoza@sina.com
    # @File    : print_table.py
    # @Software: PyCharm
    import pandas as pd
    import os
    
    path = '考场情况表.xls'
    df = pd.read_excel(io=path, sheet_name='排考', dtype=str)
    exam_room_nums = df['考场号'].values.tolist()
    
    ls = []
    for exam_room_num in exam_room_nums:
        # first_num = str(exam_room_num)[0]
        print_num = int(str(exam_room_num)[1:])
        data = 'Set sh = Worksheets("sheet1"): sh.PrintOut {}, {}, , False'.format(print_num, print_num)
        ls.append(data)
    
    # todo 写入文件
    # 删除已有文件
    my_file = 'data.txt'  # 文件路径
    if os.path.exists(my_file):  # 如果文件存在
        # 删除文件,可使用以下两种方法。
        os.remove(my_file)  # 则删除
        # os.unlink(my_file)
    
    # 创建一个新的txt文件
    txt_name = 'data.txt'
    
    
    # 写入路径并输出
    def output_data(ls):
        with open('data.txt', 'a+', encoding="utf-8") as f:
            # f.write('# -*- coding: utf-8 -*-\n')
            # f.write('# coding=gbk\n\n')
            f.write('Sub print1() \'定义打印过程' + '\n')
            f.write('Dim sh As Worksheet \'声明打印变量' + '\n')
            for i in ls:
                f.write(i + '\n')
    
    
    output_data(ls)
    

    相关文章

      网友评论

          本文标题:打印门贴签到表

          本文链接:https://www.haomeiwen.com/subject/fnjkgctx.html