zoukankan      html  css  js  c++  java
  • Python: open excel file

     https://github.com/dhellmann/pymotw-3

    https://github.com/xlwings/xlwings

    https://pypi.org/project/pypiwin32/
    https://github.com/Googulator/pypiwin32
    https://gist.github.com/gabemarshall/9372073

    import xlwings as xw;
    from pathlib import Path;
    import time;
    
    
    # 多文件设置密码 Geovin Du 涂聚文 xlrd、xlwt、xlwings、win32com.client
    # https://docs.xlwings.org/en/stable/api.html
    # open(fullname, update_links=None, read_only=None, format=None, password=None, write_res_password=None, ignore_read_only_recommended=None, origin=None, delimiter=None, editable=None, notify=None, converter=None, add_to_mru=None, local=None, corrupt_load=None)
    
    app =xw.App(visible=False,add_book=False);
    folder_path=Path('C:\\Users\\geovindu\\Documents\\Visual Studio 2017\\Projects\\PythonTickt\\PythonTickt\\excel\\');
    file_list=folder_path.glob('*.xls*');
    for i in file_list:
        workbook=app.books.open(i)
        workbook.api.Password='geovindu'
        workbook.save()
        workbook.close()
    app.quit();
    print('ok!');
    

      

    # geovindu 打开文件
    #xlrd、xlwt、xlwings、win32com.client(pip install pypiwin32)
    
    app=xw.App(visible=False,add_book=False);
    folder_path=Path('C:\\Users\\geovindu\\Documents\\Visual Studio 2017\\Projects\\PythonTickt\\PythonTickt\\excel\\14.xlsx');
    workbook=app.books.open(folder_path); #xlwb = xlApp.Workbooks.Open(filename, False, True, None, password)
    worksheet=workbook.sheets;
    list=[];
    for i in worksheet:
        sheet_name=i.name;
        print(i.name);
        list.append(sheet_name);
    print(list);
    workbook.close();
    app.quit();
    

      

    #打开有密码的EXCEL文件 涂聚文 Geovin Du
    # Anaconda 5.2.0 
    # from win32com.client import Dispatch,DispatchEx,constants;
    # import win32com.client; #(pip install pypiwin32)
    dupath=Path('C:\\Users\\geovindu\\Documents\\Visual Studio 2017\\Projects\\PythonTickt\\PythonTickt\\excel\\20198HBDAY.xlsx');
    xlApp = win32com.client.Dispatch("Excel.Application");
    xlApp.Visible = False #文档打开,不显示打开
    xlApp.DisplayAlerts = True
    xlwb = xlApp.Workbooks.Open(dupath, False, True, None, password)
    print("Success! Password is: "+password)
    dusheet=xlwb.sheets;
    dulist=[];
    for i in dusheet:
        duname=i.name;
        print(i.name);
        dulist.append(duname);
    print(dulist);
    xlwb.Close(False); #涂聚文 Geovin Du 关闭
    xlApp.Quit(); #退出
    

      

  • 相关阅读:
    Exp5 MSF基础应用
    20155239 《网络对抗》Exp4 恶意代码分析
    20155239吕宇轩《网络对抗》Exp3 免杀原理与实践
    20155239 吕宇轩 后门原理与实践
    20155239吕宇轩 Exp1 PC平台逆向破解(5)M
    学号—20155239—吕宇轩《信息安全系统设计基础》课程总结
    20155238 2016-2017-2《Java程序设计》课程总结
    20155238 第十五周课堂实践
    20155238 实验四 Android程序设计
    20155238 《JAVA程序设计》实验三(敏捷开发与XP实践)实验报告
  • 原文地址:https://www.cnblogs.com/geovindu/p/15655367.html
Copyright © 2011-2022 走看看