So This might looks silly to some of you but I am new at python so i don't quite know what is happening,
I need to delet the first column and the first 7 rows of a excel sheet, after looking it up I found here on this website that open another file and coping only what I needed would be easier, so I tried something like this
import openpyxl
#File to be copied
wb = openpyxl.load_workbook(r"C:\Users\gb2gaet\Nova pasta\old.xlsx") #Add file name
sheet = wb["Sheet1"]#Add Sheet name
#File to be pasted into
template = openpyxl.load_workbook(r"C:\Users\gb2gaet\Nova pasta\new.xlsx") #Add file name
temp_sheet = wb["Sheet1"] #Add Sheet name
#Takes: start cell, end cell, and sheet you want to copy from.
def copyRange(startCol, startRow, endCol, endRow, sheet):
rangeSelected = []
#Loops through selected Rows
for i in range(startRow,endRow + 1,1):
#Appends the row to a RowSelected list
rowSelected = []
for j in range(startCol,endCol+1,1):
rowSelected.append(sheet.cell(row = i, column = j).value)
#Adds the RowSelected List and nests inside the rangeSelected
rangeSelected.append(rowSelected)
return rangeSelected
#Paste data from copyRange into template sheet
def pasteRange(startCol, startRow, endCol, endRow, sheetReceiving, copiedData):
countRow = 0
for i in range(startRow,endRow+1,1):
countCol = 0
for j in range(startCol,endCol+1,1):
sheetReceiving.cell(row = i, column = j).value = copiedData[countRow][countCol]
countCol += 1
countRow += 1
def createData():
print("Processing...")
selectedRange = copyRange(2,8,17,100000,sheet)
pasteRange(1,1,16,100000,temp_sheet,selectedRange)
wb.save("new.xlsx")
print("Range copied and pasted!")
the program runs without any error but when I look into the new table it is completely empty, what am I missing? If you guys can think of any easier solution to delete the rows and columns I am open to change all the code though