xlwings使用チュートリアル
1724 ワード
参考になるチュートリアル
https://docs.xlwings.org/zh_CN/latest/api.html https://www.cnblogs.com/catgatp/p/7875683.html https://support.i-search.com.cn/article/1552533175579内容が豊富で、PythonはExcelファイルを読み書きします——xlwings(回転)https://www.jianshu.com/p/e92bad922197 https://www.jianshu.com/p/e92bad922197
1.開く
2.挿入と修正
2.1挿入
1.行の挿入
2.列の挿入
3.表の挿入
2.2出力
3.保存
https://docs.xlwings.org/zh_CN/latest/api.html https://www.cnblogs.com/catgatp/p/7875683.html https://support.i-search.com.cn/article/1552533175579内容が豊富で、PythonはExcelファイルを読み書きします——xlwings(回転)https://www.jianshu.com/p/e92bad922197 https://www.jianshu.com/p/e92bad922197
1.開く
#
import xlwings as xw
app = xw.App(visible=True,add_book=False)#
# ( ,Excel , )
# wb = app.books.add()
# ( )
wb = app.books.open('example.xlsx')
#
#wb = xw.Book('example.xlsx')
# Excel
2.挿入と修正
2.1挿入
1.行の挿入
#sht = wb.sheets[ sheet ]
sht = wb.sheets[0]
# A1, ‘Hello’
sht.range('a1').value = 'Hello'
# :A1:D4 1,2,3,4
sht.range('a1').value = [1,2,3,4]
# sht.range('a1:d4').value = [12,2,3,4]
2.列の挿入
sht.range('a2:a5').options(transpose=True).value = [5,6,7,8]
3.表の挿入
sht.range('a6').expand('table').value = [['a','b','c'],['d','e','f'],['g','h','i']]
2.2出力
#
print(sht.range('a1:d4').value)
#
a = sht.range('a:a').value
print(len(a))
rng = sht.range('a1').expand('table')
nrows = rng.rows.count
max_row = sht.api.UsedRange.Rows.count
?nrows max_row
a = sht.range(f'a1:a{nrows}').value
a
3.保存
#
wb.save('example2.xlsx') , example, ,excel 。
# ( )
wb.close()
# Excel
app.quit()