d = new adodatabase() d.connectionString = "Provider=MSDASQL.1;Persist Security Info=True;Data Source=energydata" d.active = true q = new adoquery() q.sql = "select siteId,eTimestamp,econs from energydata where siteId = '227105' " q.sql += "and eTimestamp between '2020-06-05 010:00:00' and '2020-06-05 12:55:00' " q.active = true oExcel = new oleAutoclient("excel.application") // oExcel.visible = true oExcel.workbooks.add() nRow = 1 //Add headings for i = 1 to q.rowset.fields.size oExcel.ActiveSheet.cells( nRow, i ).select() with ( oExcel.ActiveCell ) if i = 1 ColumnWidth := 8 formula := 'siteID' elseif i = 2 ColumnWidth := 20 formula := 'Timestamp' elseif i = 3 ColumnWidth := 10 formula := 'Econs' endif endwith next nRow++ do while not q.rowset.endofset for i = 1 to q.rowset.fields.size oExcel.ActiveSheet.cells( nRow, i ).select() if i = 1 oExcel.Activecell.formula = "'"+q.rowset.fields[i].value elseif i = 2 oExcel.Activecell.formula = "'"+dttoc(q.rowset.fields[i].value) elseif i = 3 oExcel.Activecell.formula = q.rowset.fields[i].value endif next nRow++ q.rowset.next() enddo q.active= false d.active = false oExcel.visible = true