How to empty all the content in a column in excel (Python Script)
Hi,
may I ask how can I clear all the content in a column for excel?
I have created a while loop to input new data for my test, but before another loop I would need to clear all the content in column C. Here is my script. If someone can help, that would be great.
def ExcelExample():
# Get the sheet of the Excel file
excelFile = Excel.Open("C:\\Users\\A\\Desktop\\Test.file\\Temp.xlsx")
excelSheet = excelFile.SheetByTitle["Sheet1"]
# Read data from the Excel file
ColumnNum = 1
RowNum = 2
totalrow = excelSheet.rowCount
NextRow = 2
#Clear column C all content
while RowNum >=2 and RowNum <= totalrow:
valueA = excelSheet.Cell[ColumnNum,RowNum].Value
if valueA==excelSheet.Cell[3,1].Value:
excelSheet.Cell[3,NextRow].Value = excelSheet.Cell[2,RowNum].Value
Log.Message(valueA+excelSheet.Cell[2,RowNum].Value+" added")
RowNum = RowNum+1
NextRow = NextRow +1
else:
RowNum = RowNum+1
else:
excelFile.Save()
I have used a IF...then...statement for this.
Data Loop A:
- user name "table data variables"
- password "table data variables"
- enter login SAP
>>>data loop B:
>>>>if excel column A (variables) equals to user name (previous data loop), the checkpoint if the page contains column B (variables)
- log out SAP
Hope it helps other people