Page 1 of 1

Cobra and Excel - a code snippet using .NET Excel Wrapper

PostPosted: Mon Jun 06, 2011 10:58 pm
by ObtuseAngle
Greetings Cobra community!

Trying to move from Python and COM access to Excel to Cobra and .NET, after much tearing of hair I eventually gave up on trying to use the Primary Interop Assemblies directly and decided to make use of somebody else's hard work.

There are a few wrappers available, but for my needs .NET Excel Wrapper was fine:
http://excelwrapperdotnet.codeplex.com/
C# usage example and API docs given.

Hugely simplified Cobra snippet:
Code: Select all
use ExcelWrapper

class Program

    def main
        xl = ExcelWrapper.Wrapper()
        xl.open("c:\\temp\\somefile.xls", true)
        c = xl.getCellValue('B2')
        print c
        xl.close


The value of true makes Excel and the workbook visible (briefly, in this example).

Posted in the hope it will lighten somebody else's workload.

Regards, Obtuse.

Re: Cobra and Excel - a code snippet using .NET Excel Wrappe

PostPosted: Wed Jun 08, 2011 1:31 am
by Charles
Excellent. Sometime in the near future, one will be able to conveniently inject @help in their source code to get the API info in a Cobra-friendly fashion, as a pop-up HTML document, like so:

xl = @help ExcelWrapper.Wrapper()


Not quite there yet, but I've started the implementation.

Re: Cobra and Excel - a code snippet using .NET Excel Wrappe

PostPosted: Wed Jun 08, 2011 4:27 pm
by ObtuseAngle
Great!
That will be very (ahem) helpful - getting the API stuff correct is one of my biggest stumbling blocks in Cobra.