How can you Create a copy of a worksheet by iterating through another while excluding certain rows in a array.?“Large data” work flows using pandasOpenpyxl reads and returns a None every second cellUsing openpyxl to copy from one workbook to another results in error when savingPython OpenPyXl to move rows to master workbookfor i in range just uses last row - openpyxlPython3 openpyxl Copying data from row that contains certain value to new sheet in existing workbookopenpyxl loaded workbooks are emptyOpenpyxl printing a list through column'NoneType' object has no attribute 'max_row'openpyxl - Compiling identical sheets to new sheet

Why does AM radio react to IR remote?

Defending Castle from Zombies

Is allowing Barbarian features to work with Dex-based attacks imbalancing?

Do multi-engine jets need all engines with equal age to reduce asymmetry in thrust and fuel consumption arising out of deterioration?

The meaning of asynchronous vs synchronous

What's the point of fighting monsters in Zelda BotW?

Why is the Grievance Studies affair considered to be research requiring IRB approval?

How does attacking during a conversation affect initiative?

If I said I had $100 when asked, but I actually had $200, would I be lying by omission?

Spicing up a moment of peace

Employing a contractor proving difficult

Why does a sticker slowly peel off, but if it is pulled quickly it tears?

Find feasible point in polynomial time in linear programming

Is this password scheme legit?

Can a network vulnerability be exploited locally?

How to say "I only speak one language which is English" in French?

Looking for a plural noun related to ‘fulcrum’ or ‘pivot’ that denotes multiple things as crucial to success

Why is there no Disney logo in MCU movies?

Can I get a PhD for developing educational software?

Are sweatpants frowned upon on flights?

Why is there not a willingness from the world to step in between Pakistan and India?

Is it unusual for a math department not to have a mail/web server?

Why did the population of Bhutan drop by 70% between 2007 and 2008?

Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?



How can you Create a copy of a worksheet by iterating through another while excluding certain rows in a array.?


“Large data” work flows using pandasOpenpyxl reads and returns a None every second cellUsing openpyxl to copy from one workbook to another results in error when savingPython OpenPyXl to move rows to master workbookfor i in range just uses last row - openpyxlPython3 openpyxl Copying data from row that contains certain value to new sheet in existing workbookopenpyxl loaded workbooks are emptyOpenpyxl printing a list through column'NoneType' object has no attribute 'max_row'openpyxl - Compiling identical sheets to new sheet






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm comparing two workbooks using Openpyxl I have it incrementing a counter for later usage and then keeping track of rows that should be removed from the initial workbook. How do I go about getting rid of these rows from that workbook or creating a new sheet(With the Original then deleted) or workbook with those rows removed?



I've written the code up until this point but I havent found much in terms of writing or deleting rows from a workbook and I haven't any concrete luck, I was advised by someone to instead create a copy of the workbook but I also have had no success at doing such.



from openpyxl import load_workbook
from tkinter import Tk
from tkinter.filedialog import askopenfilename
import datetime
import time

class ManualReporter:
def __init__(self):
'''
Initializes Variables for use within the Class
Hides the tkinter pop-up when using the file dialog
'''
Tk().withdraw()
self.sap_file = None
self.tracker_file = None
self.wb_sap = None
self.wb_wt = None
self.XT = 0
self.deadrows = []


def open_sapfile(self):
'''
Sets the sap_file variable to be the first directory to the SAP Report based on what the User Selects in the File Dialog
Sets that directory and the file as the current workbook under the variable self.wb_sap
Creates a Backup of the SAP Report so that if Errors Occur a Fresh Clean Copy is Present
'''
self.sap_file = askopenfilename()
self.wb_sap = load_workbook(filename=self.sap_file)
# Code to create a backup File in-case of Error or Fault
copyfile = "Untimed_Report_SAP_" + str(datetime.date.today())+".xlsx"
self.wb_sap.save(copyfile)
print(self.sap_file)
def open_tracker(self):
'''
Same as Above, sets self.tracker_file as a filedialog which retrieves the file's directory (User Inputted)
Loads the File Workbook as self.wb_wt
Creates a Backup of the Second SAP Report so that if Error Occurs a Clean Copy is Present.
'''
self.tracker_file = askopenfilename()
self.wb_wt = load_workbook(filename=self.tracker_file)
print(self.tracker_file)
def check_rows(self):
'''
Sets the Active Sheets in Both the Workbook Variables,
Creates a New Sheet in the Newest Report to Contain the Modified Data,
Iterates through the Rows of the Two Sheets checking for a Comparison in Part Number,
OpCode and then Compares the X/T/P Classification and Adjusts Data in Second Sheet
'''
start = time.time()
sap = self.wb_sap.worksheets[0] #Sets The First Sheet in the Excel Workbook as the variable sap
wt = self.wb_wt.worksheets[0]#Sets the First Sheet in the Second Report as the var wt
ws1 = self.wb_sap.create_sheet("Sheet1", 1)#Create a Spare Sheet in the First Report to place the Adjusted Data
ws1 = self.wb_sap.worksheets[1]#Sets ws1 as the Active Second Sheet for New Data
for saprow in sap.iter_rows():
for wtrow in wt.iter_rows():
if (saprow[3].value == wtrow[4].value and int(saprow[2].value) == int(wtrow[5].value)):# IF Material NUM & OPCode MATCH DO:
if wtrow[7].value in ("T","P"): #WT Entry is Marked as T/P
if saprow[4].value is "X": #SAP Report Entry is Marked as X
self.XT += 1#Increment X->Ts Counts
#print("X->T")
self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
ws1.append(saprow)


end = time.time()
#print("Finished, Total X->Ts: ", self.XT)
print("Time Taken: ", (end - start))



x = ManualReporter()
x.open_sapfile()
x.open_tracker()
x.check_rows()


My expectation is that the output would be an exact copy of workbook one but the rows that had a certain change in values are removed from that workbook. I expected to be able to delete them but no methods I've done have achieved anything other than broken code or issues.



 self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
for i in saprow:
#Code to Create a row in ws1.
#Code to Append value of saprow[i] to current ws1 rows


EDIT 1: I included my Attempts to append the rows to a copied worksheet.
EDIT 2: I though about manually iterating through the Saprow and appending the data into the rows of the new sheet but I've stumped myself thinking about it.










share|improve this question





















  • 1





    If this code results in errors, it would be prudent to include a full stack trace of the error...

    – Reedinationer
    Mar 27 at 21:19






  • 1





    The easist thing to do is loop over two sheets in parallel and write only those rows you want to.

    – Charlie Clark
    Mar 28 at 8:37











  • @Reedinationer The Code doesn't Error as far as I know I got it to loop and mark the entries I can remove just the process of removal is something I'm not familiar with.

    – Robert Farmer
    Mar 28 at 18:30






  • 1





    I'm curious why you are needing to remove them at all? I would have thought you would just not write them in the first place during the copy/paste process, right? I'm not an openpyxl wizard though, I typically prefer xlwings

    – Reedinationer
    Mar 28 at 18:33











  • So Essentially its a Report that Gets updated daily and I do monthly reports of the contents and so I compare the Month to Month differences. The final report has the X/P Entries Removed and as far as I've found just deleting the entries isn't possible nor is it advised so Making a copy as I iterate through the reports and appending the non-offending rows seems to be my current goal

    – Robert Farmer
    Mar 28 at 19:41

















1















I'm comparing two workbooks using Openpyxl I have it incrementing a counter for later usage and then keeping track of rows that should be removed from the initial workbook. How do I go about getting rid of these rows from that workbook or creating a new sheet(With the Original then deleted) or workbook with those rows removed?



I've written the code up until this point but I havent found much in terms of writing or deleting rows from a workbook and I haven't any concrete luck, I was advised by someone to instead create a copy of the workbook but I also have had no success at doing such.



from openpyxl import load_workbook
from tkinter import Tk
from tkinter.filedialog import askopenfilename
import datetime
import time

class ManualReporter:
def __init__(self):
'''
Initializes Variables for use within the Class
Hides the tkinter pop-up when using the file dialog
'''
Tk().withdraw()
self.sap_file = None
self.tracker_file = None
self.wb_sap = None
self.wb_wt = None
self.XT = 0
self.deadrows = []


def open_sapfile(self):
'''
Sets the sap_file variable to be the first directory to the SAP Report based on what the User Selects in the File Dialog
Sets that directory and the file as the current workbook under the variable self.wb_sap
Creates a Backup of the SAP Report so that if Errors Occur a Fresh Clean Copy is Present
'''
self.sap_file = askopenfilename()
self.wb_sap = load_workbook(filename=self.sap_file)
# Code to create a backup File in-case of Error or Fault
copyfile = "Untimed_Report_SAP_" + str(datetime.date.today())+".xlsx"
self.wb_sap.save(copyfile)
print(self.sap_file)
def open_tracker(self):
'''
Same as Above, sets self.tracker_file as a filedialog which retrieves the file's directory (User Inputted)
Loads the File Workbook as self.wb_wt
Creates a Backup of the Second SAP Report so that if Error Occurs a Clean Copy is Present.
'''
self.tracker_file = askopenfilename()
self.wb_wt = load_workbook(filename=self.tracker_file)
print(self.tracker_file)
def check_rows(self):
'''
Sets the Active Sheets in Both the Workbook Variables,
Creates a New Sheet in the Newest Report to Contain the Modified Data,
Iterates through the Rows of the Two Sheets checking for a Comparison in Part Number,
OpCode and then Compares the X/T/P Classification and Adjusts Data in Second Sheet
'''
start = time.time()
sap = self.wb_sap.worksheets[0] #Sets The First Sheet in the Excel Workbook as the variable sap
wt = self.wb_wt.worksheets[0]#Sets the First Sheet in the Second Report as the var wt
ws1 = self.wb_sap.create_sheet("Sheet1", 1)#Create a Spare Sheet in the First Report to place the Adjusted Data
ws1 = self.wb_sap.worksheets[1]#Sets ws1 as the Active Second Sheet for New Data
for saprow in sap.iter_rows():
for wtrow in wt.iter_rows():
if (saprow[3].value == wtrow[4].value and int(saprow[2].value) == int(wtrow[5].value)):# IF Material NUM & OPCode MATCH DO:
if wtrow[7].value in ("T","P"): #WT Entry is Marked as T/P
if saprow[4].value is "X": #SAP Report Entry is Marked as X
self.XT += 1#Increment X->Ts Counts
#print("X->T")
self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
ws1.append(saprow)


end = time.time()
#print("Finished, Total X->Ts: ", self.XT)
print("Time Taken: ", (end - start))



x = ManualReporter()
x.open_sapfile()
x.open_tracker()
x.check_rows()


My expectation is that the output would be an exact copy of workbook one but the rows that had a certain change in values are removed from that workbook. I expected to be able to delete them but no methods I've done have achieved anything other than broken code or issues.



 self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
for i in saprow:
#Code to Create a row in ws1.
#Code to Append value of saprow[i] to current ws1 rows


EDIT 1: I included my Attempts to append the rows to a copied worksheet.
EDIT 2: I though about manually iterating through the Saprow and appending the data into the rows of the new sheet but I've stumped myself thinking about it.










share|improve this question





















  • 1





    If this code results in errors, it would be prudent to include a full stack trace of the error...

    – Reedinationer
    Mar 27 at 21:19






  • 1





    The easist thing to do is loop over two sheets in parallel and write only those rows you want to.

    – Charlie Clark
    Mar 28 at 8:37











  • @Reedinationer The Code doesn't Error as far as I know I got it to loop and mark the entries I can remove just the process of removal is something I'm not familiar with.

    – Robert Farmer
    Mar 28 at 18:30






  • 1





    I'm curious why you are needing to remove them at all? I would have thought you would just not write them in the first place during the copy/paste process, right? I'm not an openpyxl wizard though, I typically prefer xlwings

    – Reedinationer
    Mar 28 at 18:33











  • So Essentially its a Report that Gets updated daily and I do monthly reports of the contents and so I compare the Month to Month differences. The final report has the X/P Entries Removed and as far as I've found just deleting the entries isn't possible nor is it advised so Making a copy as I iterate through the reports and appending the non-offending rows seems to be my current goal

    – Robert Farmer
    Mar 28 at 19:41













1












1








1








I'm comparing two workbooks using Openpyxl I have it incrementing a counter for later usage and then keeping track of rows that should be removed from the initial workbook. How do I go about getting rid of these rows from that workbook or creating a new sheet(With the Original then deleted) or workbook with those rows removed?



I've written the code up until this point but I havent found much in terms of writing or deleting rows from a workbook and I haven't any concrete luck, I was advised by someone to instead create a copy of the workbook but I also have had no success at doing such.



from openpyxl import load_workbook
from tkinter import Tk
from tkinter.filedialog import askopenfilename
import datetime
import time

class ManualReporter:
def __init__(self):
'''
Initializes Variables for use within the Class
Hides the tkinter pop-up when using the file dialog
'''
Tk().withdraw()
self.sap_file = None
self.tracker_file = None
self.wb_sap = None
self.wb_wt = None
self.XT = 0
self.deadrows = []


def open_sapfile(self):
'''
Sets the sap_file variable to be the first directory to the SAP Report based on what the User Selects in the File Dialog
Sets that directory and the file as the current workbook under the variable self.wb_sap
Creates a Backup of the SAP Report so that if Errors Occur a Fresh Clean Copy is Present
'''
self.sap_file = askopenfilename()
self.wb_sap = load_workbook(filename=self.sap_file)
# Code to create a backup File in-case of Error or Fault
copyfile = "Untimed_Report_SAP_" + str(datetime.date.today())+".xlsx"
self.wb_sap.save(copyfile)
print(self.sap_file)
def open_tracker(self):
'''
Same as Above, sets self.tracker_file as a filedialog which retrieves the file's directory (User Inputted)
Loads the File Workbook as self.wb_wt
Creates a Backup of the Second SAP Report so that if Error Occurs a Clean Copy is Present.
'''
self.tracker_file = askopenfilename()
self.wb_wt = load_workbook(filename=self.tracker_file)
print(self.tracker_file)
def check_rows(self):
'''
Sets the Active Sheets in Both the Workbook Variables,
Creates a New Sheet in the Newest Report to Contain the Modified Data,
Iterates through the Rows of the Two Sheets checking for a Comparison in Part Number,
OpCode and then Compares the X/T/P Classification and Adjusts Data in Second Sheet
'''
start = time.time()
sap = self.wb_sap.worksheets[0] #Sets The First Sheet in the Excel Workbook as the variable sap
wt = self.wb_wt.worksheets[0]#Sets the First Sheet in the Second Report as the var wt
ws1 = self.wb_sap.create_sheet("Sheet1", 1)#Create a Spare Sheet in the First Report to place the Adjusted Data
ws1 = self.wb_sap.worksheets[1]#Sets ws1 as the Active Second Sheet for New Data
for saprow in sap.iter_rows():
for wtrow in wt.iter_rows():
if (saprow[3].value == wtrow[4].value and int(saprow[2].value) == int(wtrow[5].value)):# IF Material NUM & OPCode MATCH DO:
if wtrow[7].value in ("T","P"): #WT Entry is Marked as T/P
if saprow[4].value is "X": #SAP Report Entry is Marked as X
self.XT += 1#Increment X->Ts Counts
#print("X->T")
self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
ws1.append(saprow)


end = time.time()
#print("Finished, Total X->Ts: ", self.XT)
print("Time Taken: ", (end - start))



x = ManualReporter()
x.open_sapfile()
x.open_tracker()
x.check_rows()


My expectation is that the output would be an exact copy of workbook one but the rows that had a certain change in values are removed from that workbook. I expected to be able to delete them but no methods I've done have achieved anything other than broken code or issues.



 self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
for i in saprow:
#Code to Create a row in ws1.
#Code to Append value of saprow[i] to current ws1 rows


EDIT 1: I included my Attempts to append the rows to a copied worksheet.
EDIT 2: I though about manually iterating through the Saprow and appending the data into the rows of the new sheet but I've stumped myself thinking about it.










share|improve this question
















I'm comparing two workbooks using Openpyxl I have it incrementing a counter for later usage and then keeping track of rows that should be removed from the initial workbook. How do I go about getting rid of these rows from that workbook or creating a new sheet(With the Original then deleted) or workbook with those rows removed?



I've written the code up until this point but I havent found much in terms of writing or deleting rows from a workbook and I haven't any concrete luck, I was advised by someone to instead create a copy of the workbook but I also have had no success at doing such.



from openpyxl import load_workbook
from tkinter import Tk
from tkinter.filedialog import askopenfilename
import datetime
import time

class ManualReporter:
def __init__(self):
'''
Initializes Variables for use within the Class
Hides the tkinter pop-up when using the file dialog
'''
Tk().withdraw()
self.sap_file = None
self.tracker_file = None
self.wb_sap = None
self.wb_wt = None
self.XT = 0
self.deadrows = []


def open_sapfile(self):
'''
Sets the sap_file variable to be the first directory to the SAP Report based on what the User Selects in the File Dialog
Sets that directory and the file as the current workbook under the variable self.wb_sap
Creates a Backup of the SAP Report so that if Errors Occur a Fresh Clean Copy is Present
'''
self.sap_file = askopenfilename()
self.wb_sap = load_workbook(filename=self.sap_file)
# Code to create a backup File in-case of Error or Fault
copyfile = "Untimed_Report_SAP_" + str(datetime.date.today())+".xlsx"
self.wb_sap.save(copyfile)
print(self.sap_file)
def open_tracker(self):
'''
Same as Above, sets self.tracker_file as a filedialog which retrieves the file's directory (User Inputted)
Loads the File Workbook as self.wb_wt
Creates a Backup of the Second SAP Report so that if Error Occurs a Clean Copy is Present.
'''
self.tracker_file = askopenfilename()
self.wb_wt = load_workbook(filename=self.tracker_file)
print(self.tracker_file)
def check_rows(self):
'''
Sets the Active Sheets in Both the Workbook Variables,
Creates a New Sheet in the Newest Report to Contain the Modified Data,
Iterates through the Rows of the Two Sheets checking for a Comparison in Part Number,
OpCode and then Compares the X/T/P Classification and Adjusts Data in Second Sheet
'''
start = time.time()
sap = self.wb_sap.worksheets[0] #Sets The First Sheet in the Excel Workbook as the variable sap
wt = self.wb_wt.worksheets[0]#Sets the First Sheet in the Second Report as the var wt
ws1 = self.wb_sap.create_sheet("Sheet1", 1)#Create a Spare Sheet in the First Report to place the Adjusted Data
ws1 = self.wb_sap.worksheets[1]#Sets ws1 as the Active Second Sheet for New Data
for saprow in sap.iter_rows():
for wtrow in wt.iter_rows():
if (saprow[3].value == wtrow[4].value and int(saprow[2].value) == int(wtrow[5].value)):# IF Material NUM & OPCode MATCH DO:
if wtrow[7].value in ("T","P"): #WT Entry is Marked as T/P
if saprow[4].value is "X": #SAP Report Entry is Marked as X
self.XT += 1#Increment X->Ts Counts
#print("X->T")
self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
ws1.append(saprow)


end = time.time()
#print("Finished, Total X->Ts: ", self.XT)
print("Time Taken: ", (end - start))



x = ManualReporter()
x.open_sapfile()
x.open_tracker()
x.check_rows()


My expectation is that the output would be an exact copy of workbook one but the rows that had a certain change in values are removed from that workbook. I expected to be able to delete them but no methods I've done have achieved anything other than broken code or issues.



 self.deadrows.append(saprow)
else:
if saprow not in self.deadrows:
for i in saprow:
#Code to Create a row in ws1.
#Code to Append value of saprow[i] to current ws1 rows


EDIT 1: I included my Attempts to append the rows to a copied worksheet.
EDIT 2: I though about manually iterating through the Saprow and appending the data into the rows of the new sheet but I've stumped myself thinking about it.







python openpyxl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 20:50







Robert Farmer

















asked Mar 27 at 21:15









Robert FarmerRobert Farmer

839 bronze badges




839 bronze badges










  • 1





    If this code results in errors, it would be prudent to include a full stack trace of the error...

    – Reedinationer
    Mar 27 at 21:19






  • 1





    The easist thing to do is loop over two sheets in parallel and write only those rows you want to.

    – Charlie Clark
    Mar 28 at 8:37











  • @Reedinationer The Code doesn't Error as far as I know I got it to loop and mark the entries I can remove just the process of removal is something I'm not familiar with.

    – Robert Farmer
    Mar 28 at 18:30






  • 1





    I'm curious why you are needing to remove them at all? I would have thought you would just not write them in the first place during the copy/paste process, right? I'm not an openpyxl wizard though, I typically prefer xlwings

    – Reedinationer
    Mar 28 at 18:33











  • So Essentially its a Report that Gets updated daily and I do monthly reports of the contents and so I compare the Month to Month differences. The final report has the X/P Entries Removed and as far as I've found just deleting the entries isn't possible nor is it advised so Making a copy as I iterate through the reports and appending the non-offending rows seems to be my current goal

    – Robert Farmer
    Mar 28 at 19:41












  • 1





    If this code results in errors, it would be prudent to include a full stack trace of the error...

    – Reedinationer
    Mar 27 at 21:19






  • 1





    The easist thing to do is loop over two sheets in parallel and write only those rows you want to.

    – Charlie Clark
    Mar 28 at 8:37











  • @Reedinationer The Code doesn't Error as far as I know I got it to loop and mark the entries I can remove just the process of removal is something I'm not familiar with.

    – Robert Farmer
    Mar 28 at 18:30






  • 1





    I'm curious why you are needing to remove them at all? I would have thought you would just not write them in the first place during the copy/paste process, right? I'm not an openpyxl wizard though, I typically prefer xlwings

    – Reedinationer
    Mar 28 at 18:33











  • So Essentially its a Report that Gets updated daily and I do monthly reports of the contents and so I compare the Month to Month differences. The final report has the X/P Entries Removed and as far as I've found just deleting the entries isn't possible nor is it advised so Making a copy as I iterate through the reports and appending the non-offending rows seems to be my current goal

    – Robert Farmer
    Mar 28 at 19:41







1




1





If this code results in errors, it would be prudent to include a full stack trace of the error...

– Reedinationer
Mar 27 at 21:19





If this code results in errors, it would be prudent to include a full stack trace of the error...

– Reedinationer
Mar 27 at 21:19




1




1





The easist thing to do is loop over two sheets in parallel and write only those rows you want to.

– Charlie Clark
Mar 28 at 8:37





The easist thing to do is loop over two sheets in parallel and write only those rows you want to.

– Charlie Clark
Mar 28 at 8:37













@Reedinationer The Code doesn't Error as far as I know I got it to loop and mark the entries I can remove just the process of removal is something I'm not familiar with.

– Robert Farmer
Mar 28 at 18:30





@Reedinationer The Code doesn't Error as far as I know I got it to loop and mark the entries I can remove just the process of removal is something I'm not familiar with.

– Robert Farmer
Mar 28 at 18:30




1




1





I'm curious why you are needing to remove them at all? I would have thought you would just not write them in the first place during the copy/paste process, right? I'm not an openpyxl wizard though, I typically prefer xlwings

– Reedinationer
Mar 28 at 18:33





I'm curious why you are needing to remove them at all? I would have thought you would just not write them in the first place during the copy/paste process, right? I'm not an openpyxl wizard though, I typically prefer xlwings

– Reedinationer
Mar 28 at 18:33













So Essentially its a Report that Gets updated daily and I do monthly reports of the contents and so I compare the Month to Month differences. The final report has the X/P Entries Removed and as far as I've found just deleting the entries isn't possible nor is it advised so Making a copy as I iterate through the reports and appending the non-offending rows seems to be my current goal

– Robert Farmer
Mar 28 at 19:41





So Essentially its a Report that Gets updated daily and I do monthly reports of the contents and so I compare the Month to Month differences. The final report has the X/P Entries Removed and as far as I've found just deleting the entries isn't possible nor is it advised so Making a copy as I iterate through the reports and appending the non-offending rows seems to be my current goal

– Robert Farmer
Mar 28 at 19:41












1 Answer
1






active

oldest

votes


















1















After Ample help I have reached the conclusion that to copy data from one sheet to another you can copy over data row by row through this Method:



self.workbook = load_workbook(filename="filepath")
sheet1 = self.workbook.worksheet[0]
sheet2 = self.workbook.create_sheet("Sheet 2")
sheet2 = self.workbook.worksheets[1]
for row in sheet1.iter_rows():
sheet2.append([cell.value for cell in row])


I also figured out if you want to filter out data you can add if statements inside of the for-loop above that can limit what rows have their cells written into the new worksheet.



self.RowsToExclude = Some List containing row data that will be excluded.
for row in sheet1.iter_rows():
if row not in self.RowsToExclude:
ws1.append([cell.value for cell in row])


Finally, I'd like to thank all those who contributed towards me reaching this conclusion.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386574%2fhow-can-you-create-a-copy-of-a-worksheet-by-iterating-through-another-while-excl%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1















    After Ample help I have reached the conclusion that to copy data from one sheet to another you can copy over data row by row through this Method:



    self.workbook = load_workbook(filename="filepath")
    sheet1 = self.workbook.worksheet[0]
    sheet2 = self.workbook.create_sheet("Sheet 2")
    sheet2 = self.workbook.worksheets[1]
    for row in sheet1.iter_rows():
    sheet2.append([cell.value for cell in row])


    I also figured out if you want to filter out data you can add if statements inside of the for-loop above that can limit what rows have their cells written into the new worksheet.



    self.RowsToExclude = Some List containing row data that will be excluded.
    for row in sheet1.iter_rows():
    if row not in self.RowsToExclude:
    ws1.append([cell.value for cell in row])


    Finally, I'd like to thank all those who contributed towards me reaching this conclusion.






    share|improve this answer





























      1















      After Ample help I have reached the conclusion that to copy data from one sheet to another you can copy over data row by row through this Method:



      self.workbook = load_workbook(filename="filepath")
      sheet1 = self.workbook.worksheet[0]
      sheet2 = self.workbook.create_sheet("Sheet 2")
      sheet2 = self.workbook.worksheets[1]
      for row in sheet1.iter_rows():
      sheet2.append([cell.value for cell in row])


      I also figured out if you want to filter out data you can add if statements inside of the for-loop above that can limit what rows have their cells written into the new worksheet.



      self.RowsToExclude = Some List containing row data that will be excluded.
      for row in sheet1.iter_rows():
      if row not in self.RowsToExclude:
      ws1.append([cell.value for cell in row])


      Finally, I'd like to thank all those who contributed towards me reaching this conclusion.






      share|improve this answer



























        1














        1










        1









        After Ample help I have reached the conclusion that to copy data from one sheet to another you can copy over data row by row through this Method:



        self.workbook = load_workbook(filename="filepath")
        sheet1 = self.workbook.worksheet[0]
        sheet2 = self.workbook.create_sheet("Sheet 2")
        sheet2 = self.workbook.worksheets[1]
        for row in sheet1.iter_rows():
        sheet2.append([cell.value for cell in row])


        I also figured out if you want to filter out data you can add if statements inside of the for-loop above that can limit what rows have their cells written into the new worksheet.



        self.RowsToExclude = Some List containing row data that will be excluded.
        for row in sheet1.iter_rows():
        if row not in self.RowsToExclude:
        ws1.append([cell.value for cell in row])


        Finally, I'd like to thank all those who contributed towards me reaching this conclusion.






        share|improve this answer













        After Ample help I have reached the conclusion that to copy data from one sheet to another you can copy over data row by row through this Method:



        self.workbook = load_workbook(filename="filepath")
        sheet1 = self.workbook.worksheet[0]
        sheet2 = self.workbook.create_sheet("Sheet 2")
        sheet2 = self.workbook.worksheets[1]
        for row in sheet1.iter_rows():
        sheet2.append([cell.value for cell in row])


        I also figured out if you want to filter out data you can add if statements inside of the for-loop above that can limit what rows have their cells written into the new worksheet.



        self.RowsToExclude = Some List containing row data that will be excluded.
        for row in sheet1.iter_rows():
        if row not in self.RowsToExclude:
        ws1.append([cell.value for cell in row])


        Finally, I'd like to thank all those who contributed towards me reaching this conclusion.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 10 at 20:55









        Robert FarmerRobert Farmer

        839 bronze badges




        839 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386574%2fhow-can-you-create-a-copy-of-a-worksheet-by-iterating-through-another-while-excl%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현