Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel tables and move rows
#2
Sure you can, read the docs: https://openpyxl.readthedocs.io/en/stable/
you can have more that one worksheet open at a time (which you are doing on line 3)
Since you're buildng a dictionary (writer.sheets) to contain all worksheets,
you extract the sheet by title.
It would be easier (if only two sheets were involved, to open each with separate names)
using the attached simple spreadsheet, copy sheet 1 A1 to sheet2 B1:

from openpyxl import Workbook, load_workbook, cell
import os

os.chdir(os.path.abspath(os.path.dirname(__file__)))

def A1_to_B1():
    # move sheet 1 cell a1 to sheet2 cell b1 
    wb = load_workbook('Sheettest.xlsx')
    wb1 = sheet_object = wb.worksheets[0]
    wb2 = sheet_object = wb.worksheets[1]
    wb2.cell(row=1, column=2).value = wb1.cell(row=1, column=1).value
    wb.save('Sheettest.xlsx')

A1_to_B1()

Attached Files

.xlsx   Sheettest.xlsx (Size: 8.12 KB / Downloads: 149)
Reply


Messages In This Thread
Excel tables and move rows - by jdos - Jun-30-2020, 08:21 AM
RE: Excel tables and move rows - by Larz60+ - Jun-30-2020, 04:54 PM
RE: Excel tables and move rows - by jdos - Jun-30-2020, 05:31 PM
RE: Excel tables and move rows - by Larz60+ - Jun-30-2020, 06:46 PM
RE: Excel tables and move rows - by jdos - Jul-01-2020, 06:10 AM
RE: Excel tables and move rows - by Larz60+ - Jul-01-2020, 09:50 AM
RE: Excel tables and move rows - by jdos - Jul-02-2020, 05:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tables in Excel MaartenRo 3 584 Jan-06-2024, 03:46 PM
Last Post: deanhystad
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,988 Dec-12-2022, 08:22 PM
Last Post: jh67
  Deleting rows based on cell value in Excel azizrasul 11 2,814 Oct-19-2022, 02:38 AM
Last Post: azizrasul
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,655 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Slittping table into Multiple tables by rows drunkenneo 1 2,114 Oct-06-2021, 03:17 PM
Last Post: snippsat
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,157 May-04-2021, 10:51 PM
Last Post: rhat398
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,336 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  Python script to summarize excel tables, then output a composite table? i'm a total n surfer349 1 2,422 Feb-05-2021, 04:37 PM
Last Post: nilamo
  Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter jackie 1 3,261 May-27-2020, 11:47 PM
Last Post: mcmxl22
  Merging excel worksheets with balnk rows sauravksingh85 1 1,360 May-19-2020, 12:46 PM
Last Post: sauravksingh85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020