0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonのopenpyxlを使ってExcelシートの罫線を取得する

Posted at

英語記事も色々調べ倒して、どこにも無かったのでどっかの誰かの役に立てば…(と言う名の備忘録)と思い残しておくことにした。

動作環境:
 Python = 3.10.8
 OS = windows11
 IDE = VScode 1.74.3

コード

from openpyxl import load_workbook

filename = 'testExcel.xlsx'

wb = load_workbook(filename)

ws = wb.active

print('left: ', ws['C39'].border.left.border_style)
print('right: ', ws['C39'].border.right.border_style)
print('top: ', ws['C39'].border.top.border_style)
print('bottom: ', ws['C39'].border.bottom.border_style)

結果

left:  medium
right:  medium
top:  medium
bottom:  thin

解説

上のコードではセル'C39'の罫線左右上下を返すようにしている。
どうやって見つけたかというと、VScodeのデバッガーで対象にブレイクポイントを貼った。
ちなみに、thinは標準の線、mediumは太めの線になる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?