Hi Alan
We do a lot of excel work but we use the active X automation not .Net. We imported the Excel Active X Automation library. We can then use these classes to open / drive excel.
In order to work out the code for Excel, we record a Macro in Excel of what we need to do and then look at the code of the Macro to work out what code is needed in Jade.
For example, the macro to create a new workbook is
In Jade this translates to (First two lines are to open Excel, last line to get the active worksheet.)
Code: Select all
// Create the application
create zMyXLApplication;
zMyXLApplication.createAutomationObject();
// Add a new workbook
zMyActiveWorkbook := zMyXLApplication.workbooks.add( null );
// Get the active Sheet
zMyActiveWorksheet := zMyActiveWorkbook.activeSheet.getInterface( I_Worksheet ).I_Worksheet;
Notice how the last line uses the getInterface method to get the worksheet as a I_Worksheet object. This is the method to use when type casting. I'm not sure but you may just need to type cast the .Net object returned to the correct type.
All the help is available on the MSDN site (or just use google.)
Note: Each time you call an excel function that creates an excel object, the relevant object is created in Jade. These need to be cleaned up. For example a method that gets a cell and formats it as bold, the range returned needs to be deleted.
Code: Select all
setRange_Bold(
piRow : Integer;
pcColumn : String;
piRow_2 : Integer;
pcColumn_2 : String
);
vars
oRange : Range;
begin
oRange := zMyActiveWorksheet.range( pcColumn & piRow.String, pcColumn_2 & piRow_2.String );
oRange.font.putBold( true );
epilog
delete oRange;
end;
Secondly, each call to Excel is a round trip between the application server and the thin client. However once you've worked out the process, you could code a .Net DLL or similar that would do all the excel maniuplation in the dll. That way Jade only makes one call to the dll, not 20 or more calls to Excel.
If you are populating a data table into Excel, it is much more efficient to extract it as a CSV file and then import that file into Excel. We've tried setting the value of each cell, but it just too slow with large data sets.
Cheers
Torrie