Forum Discussion

Mr_Bro's avatar
Mr_Bro
Champion Level 0
5 years ago
Solved

Write Conent To Excel using ADO connectio

Hi team,

 

im trying to write some content to excel using ADO connection.

can any one help me in achieving the same. 

im using Python and below is the sample code where i m trying to write the content to excel.

def writeDataToExcel():
  strSheet = 'over'
  filepath = r'C:\Users\sathishkumark\Desktop\Test.xlsx' 
  ConnectionString = 'Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ='+filepath+';ReadOnly=0;Extended Properties=Excel 12.0 Macro;HDR=YES;'
  objExcel = ADO.CreateConnection()
  objExcel.ConnectionString = ConnectionString
  objExcel.Open()
  objRS = ADO.CreateRecordset()
  strQuery = "update ["+strSheet+"$] set col1 = 'sda';"
  objRS.Open (strQuery, objExcel, 3, 3)
  objExcel.Close()
  objExcel.Close()

Kind Regards,

Sathish Kumar K