pyexcel_xlsx 使用例子

須要從excel裏導數據,之前用C#弄過,說了慚愧,到如今也沒想明白啥是 容器,在python裏百度一下,好多套路,找了一個簡單的,就這麼幾行就好了,厲害啊。python

 

pip3 install pyexcel_xlsxapp

---------------------------excel

#! /usr/bin/evn python
# coding=utf-8ip

# pyexcel_xlsx 以 orderedDict 結構處理數據utf-8

from collections import OrderedDictget

from pyexcel_xlsx import get_data
from pyexcel_xlsx import save_datait

def read_xls_file():
    xls_data = get_data(r"write_test.xlsx")
    print ("Get data type:",type(xls_data))
    for sheet_n in xls_data.keys():
        print (sheet_n,":",xls_data[sheet_n])
    
# 寫excel數據,xls格式
def save_xls_file():
    data = OrderedDict()
    # sheet表的數據
    sheet_1 = []
    row_1_data = [u"ID",u"暱稱",u"等級"] # 每一行的數據
    row_2_data = [4,5,36]
    #逐條添加數據
    sheet_1.append(row_1_data)
    sheet_1.append(row_2_data)
    #添加sheet表
    data.update({u"這是XX表":sheet_1})
    
    #保存成xls文件
    save_data("write_test.xlsx",data)
    
    
        
if __name__=='__main__':
    #read_xls_file()
    save_xls_file()pip

相關文章
相關標籤/搜索