Simple creation of excel files using COMate
Posted: Thu Nov 13, 2008 7:22 pm
Hi,
I've developped this program to create excelfiles from a txt file, using COMate facilities (thanks, srod).
And this is a "txl" (text) file for testing purposes:
Best Regards
I've developped this program to create excelfiles from a txt file, using COMate facilities (thanks, srod).
Code: Select all
IncludePath "C:\Apps\COMate"
XIncludeFile "COMate.pbi"
Global ExcelObj.COMateObject, WorkBook.COMateObject, WorkSheet.COMateObject
filename.s = ProgramParameter()
if len(filename)
if lcase(GetExtensionPart(filename)) <> "txl": filename + ".txl": endif
if ReadFile(1, filename)
Repeat
if eof(1): break: endif
linetxl.s = trim(ReadString(1))
if len(linetxl)
if left(linetxl,1) = ";": continue: endif
command.s = StringField(linetxl,1," ")
linerest.s = trim(right(linetxl, len(linetxl)-len(command)))
select command
case "open" : ExcelObj = COMate_CreateObject(linerest)
case "book" : WorkBook = ExcelObj\GetObjectProperty(linerest)
case "sheet": WorkSheet = ExcelObj\GetObjectProperty(linerest)
case "exeob": ExcelObj\Invoke(linerest)
case "exebk": WorkBook\Invoke(linerest)
case "exesh": WorkSheet\Invoke(linerest)
case "close"
if FindString(lcase(linerest),"book",1): WorkBook\Release(): endif
if FindString(lcase(linerest),"appl",1): ExcelObj\Release(): endif
case "setbk": WorkBook\SetProperty(linerest)
case "setsh": WorkSheet\SetProperty(linerest)
case "set" : ExcelObj\SetProperty(linerest)
default : ExcelObj\SetProperty(linerest)
endselect
endif
Forever
endif
endif
END
Code: Select all
;/////////////////////////////////////////////////////////////////////////////////
;***COMate*** COM automation through iDispatch.
;*===========
;*
;*Excel demo.
;/////////////////////////////////////////////////////////////////////////////////
open Excel.Application
set Visible = #False
book Workbooks\Add
sheet Sheets('Sheet2')
exesh Activate()
set Cells(2,1) = 'Hello 2B'
sheet Sheets('Sheet3')
exesh Activate()
set Cells(2,1) = 'Hello 3B'
sheet Worksheets\Add
setsh Name = 'Another'
set Cells(2,1) = 'Hello 4B'
sheet Sheets('Sheet1')
exesh Activate()
set Cells(1,1) = 'Hello 1B'
set Cells(4,1) = 66.52
set Cells(5,1) = 71.63
set Cells(6,1) = '=A4+A5'
set Evaluate('A10') = '=SUM(A4:A6)'
exebk SaveAs('C:\Apps\COMate\Testing.xls')
exeob Quit()
close book appl