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?

【Python】Excelデータを別のブックにコピーする(範囲指定)

Last updated at Posted at 2024-07-07

import openpyxl as px

#aというExcelをwbに関連づける
wb = px.load_workbook('Book1.xlsx')

#aシートを関連付け
ws = wb['Sheet1']

#bというExcelをwbに関連づける
wb2 = px.load_workbook('Book2.xlsx')

#bシートを関連付け
ws2 = wb2['Sheet1']

#コピー元のaシート(範囲指定:row=行,column=列)
for i in range(3,20):
for j in range(1,3):
copy = ws.cell(row = i, column =j).value

#コピー先のbブック、bシートにコピー元のデータを貼り付け
ws2.cell(row = i, column =j , value = copy)

#bブックを「copy4」で保存する
wb2.save(filename = 'Book2.xlsx')

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?