Subject Re: Opening an excel file in a dbase program
From Gaetano D. <gaetanoddRemoveThis@andThatHotmail.com>
Date Thu, 17 Jun 2021 18:27:28 +1000
Newsgroups dbase.getting-started

On 17/06/2021 17:39, Rod Hamilton wrote:
> How can I open an excel file using code in my dbase program using the 'Run' command or is there another way ?
>
> Thanks
>
Here is a little demo of the basics to get you started:


*** pre-requisite, Excel must be installed on the machine running the code
*** in other words, you cannot deploy this code to another machine
*** if it doesn't have Excel installed

//instantiating the oleautoclient
oXL=new oleautoclient("Excel.application")

//set general parameters
oXL.application.DisplayAlerts = false
oXL.application.visible=false // or true if you want to see it happening
oXL.application.alertBeforeOverwriting = false
oXL.application.screenupdating = false // similar to notifyControls in dBase

//create a blank workbook
oXL.workbooks.add()
//save the workbook and give it a name
oXL.activeworkbook.saveas("d:\documents\dbase\turnkeys\myOLEworkbook.xlsx")

//selecting an entire column
oXL.Columns("A:A").Select()
//changing the number format for the numeric selection - dates are
numbers in Excel too
oXL.Selection.NumberFormat = "yyyymmdd hh:mm:ss"
oXL.range("A1").select()
oXL.selection.value="test"
// set font to bold
oXL.selection.font.bold=true
//using offsets from the current cell instead of using absolute values -
same row, 2 columns further
oXL.selection.offset(0,2).select()
oXL.selection.value="test2"
//using offsets from the current cell - 1 row down, same colum
oXL.selection.offset(1,0).select()
//set a formula in a cell
oXL.ActiveCell.FormulaR1C1 = "=TODAY()"
//save and exit
oXL.activeworkbook.save()
oXL.quit()
oXL=null
return

--
Gaetano.