亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Python xlwings模塊簡單使用

系統 5566 0

Python xlwings模塊簡單使用

  • xlwings 安裝

  • xlwings excel-book-打開-新建

  • xlwings sheet-api

  • xlwings 操作數據

  • xlwings 讀取數據

 xlwings 安裝  

  • 操作excel模塊的比較              
     image.png 

  • xlwings官方文檔

  • 基本操作              
     image.png  

  • 安裝              
     pip install xlwings              

 xlwings 打開-新建  

  • 打開excel文件

  • 多個excel操作

  import                 time              import                 xlwings 
              as                 xw              """ visible Ture:可見excel False:不可見excel add_book True:打開excel并且新建工作簿 False:不新建工作簿 """                app 
              =                 xw              .                App              (                visible              =                True                ,                 add_book              =                False                )                wb 
              =                 app              .                books              .                open                (                './a.xlsx'                )                wb2 
              =                 app              .                books              .                open                (                "./b.xlsx"                )                # 打印當前活躍的books-  print                (                app              .                books              .                active              )                # 打印當前的book-Books([,])  print                (                app              .                books              )                wb              .                save              (                )                # 關閉a.xlsx文件-指定操作的excel                # wb.close()                app              .                books              [                0                ]                .                close              (                )                time              .                sleep              (                3                )                app              .                quit              (                )

 

  • 新建excel文件

  import                 xlwings 
              as                 xw

app 
              =                 xw              .                App              (                visible              =                True                ,                 add_book              =                False                )                # 添加一個新的工作薄                wb 
              =                 app              .                books              .                add              (                )                # 保存文件                wb              .                save              (                './a2.xlsx'                )                wb              .                close              (                )                app              .                quit              (                )

 

 xlwings sheet-api  

  • 新建sheet

  wb.sheets.add("sheet2")

 

  • 刪除sheet

  wb              .                sheets              [                "sheet2"                ]                .                delete              (                )

 

  • 查看當前表格名

  wb              .                sheets              [                1                ]                .                name

 

  • 重命名表格sheet

  wb              .                sheets              [                1                ]                .                name              =                “abc”

 

  • 清空整張表格的內容和格式

  wb              .                sheets              [                1                ]                .                clear              (                )

 

  • 查看當前活躍的sheet

  wb              .                sheets              .                active
sh 
              =                 wb              .                sheets              .                active
sh              .                range                (                "A1"                )                .                value              =                "A1"

 

  • 激活指定的sheet

  wb              .                sheets              [                "sheet1"                ]                .                activate              (                )

 

 xlwings 操作數據  

  • 引用單元格

  import                 xlwings 
              as                 xw              import                 time

app 
              =                 xw              .                App              (                visible              =                True                ,                 add_book              =                False                )                wb 
              =                 app              .                books              .                open                (                "./a.xlsx"                )                sht 
              =                 wb              .                sheets              [                "sheet1"                ]                # TODO 待輸入-見下面示例                # A1 單元格                wb              .                sheets              [                "sheet1"                ]                .                range                (                "A1"                )                # A2 單元格                sht              .                range                (                "A2"                )                # A3單元格-xw-當前活躍的app-book-sheet                xw              .                Range              (                "A3"                )                # A4單元格                rng_a4 
              =                 sht              [                "A4"                ]                # A1:B3 單元格                rng_a1_b3 
              =                 sht              [                "A1:B3"                ]                rng_a1_b3_2 
              =                 sht              .                range                (                "A1:B3"                )                xw              .                Range              (                (                1                ,                1                )                ,                (                3                ,                2                )                )                # C1單元格                rng_c1 
              =                 sht              [                0                ,                2                ]                time              .                sleep              (                3                )                wb              .                save              (                )                wb              .                close              (                )                app              .                quit              (                )

 

  • 寫入數據

  1. 單個單元格輸入

  sht              .                range                (                "A1"                )                .                value              =                "A1"

 

image.png

  1. 輸入行-- 在A2輸入1,B2輸入2

  sht              .                range                (                "A2"                )                .                value              =                [                1                ,                2                ]

 

image.png  

  1. 輸入行-A3-A4-A5賦值

  sht              .                range                (                "A3"                )                .                options              (                transpose              =                True                )                .                value 
              =                [                "行"                ,                "行"                ,                "行"                ]

 

image.png  

  1. 輸入表格

  sht              .                range                (                'A4'                )                .                options              (                expand              =                'table'                )                .                value 
              =                [                [                1                ,                2                ]                ,                [                3                ,                4                ]                ]                sht              .                range                (                "A4:B5"                )                .                value 
              =                [                [                1                ,                2                ]                ,                [                3                ,                4                ]                ]

 

image.png  

 xlwings 讀取數據  

  • 讀取

  sht              .                range                (                "A1"                )                .                value

sht              .                range                (                "A1:A3"                )                .                value

sht              .                range                (                "A1:B3"                )                .                value

xw              .                Range              (                "A1"                )                .                value

更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日日操天天 | 久久久久一 | 成年女人永久免费观看片 | 香蕉国产人午夜视频在线观看 | 热思思久久 | 立即播放免费毛片一级 | 欧美日比视频 | 一级毛片免费一级直接观看 | 成人性生活视频 | 久草免费在线观看 | 久久国产亚洲欧美日韩精品 | 99国产福利视频区 | 有码一区| 国农村精品国产自线拍 | 久久思 | 九九视频精品在线 | 青青青国产成人久久111网站 | 欧美日韩亚洲在线观看 | 久久99一区| 四虎1515| 99国产精品热久久久久久 | 91精品国产爱久久久久 | 91精品国产乱码久久久久久 | 国产一区二区三区免费视频 | 久久久精品久久久久三级 | 国产片欧美片亚洲片久久综合 | 日本一区二区三区久久 | 韩日中文字幕 | 久久九九热re6这里有精品 | 久久久久无码国产精品一区 | 日韩欧美毛片免费看播放 | 在线播放国产区 | 亚洲国产品综合人成综合网站 | 欧美激情免费 | 久久国产香蕉 | 成年人一级黄色片 | 国产精品免费一区二区区 | 中国护士一级毛片免费版本 | 日韩毛片免费在线观看 | 婷婷中文 | 国产日韩欧美综合一区二区三区 |