|
|||
www.capesoft.com |
|||
![]() |
Microsoft Excel Functionality |
| Add_MSExcel_Object | ||||||||||||||||||||||
|
||||||||||||||||||||||
| Import an Excel File (ImportXLStoTPSAbc and ImportAnXLSFile) | |||
| Summary | |||
| The
ImportXLStoTPSAbc and ImportAnXLSFile templates allow you to import files
from Excel into you database. From the Application menu in the Clarion select "Template Utility" and select "ImportXlsToTpsABC" from the Class OfficeInside section. This will add the import Wizard procedure. Simply call this procedure from a button on your browse etc. 2) ImportAnXLSFile: import without a Wizard: Once you have added the code template, double click on it
to change the Both ways are demonstrated in the offdemo.app example application
(see the |
|||
| oiExcel Class Methods - Grouped by Use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| oiExcel Class Method Alphabetical Listing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AutoFilter
(
string pFromColumn, <string pToColumn> ) ,byte,proc
|
|
Forces the workbook to calculate the values of all cells and ensures they are up to date. When data is written to Excel by default it automatically checks whether the data is a formula and performs any needed calculation on the cell. This can slow down writing of data dramatically, although it ensures that all cells in the workbook are always up to date. In order to speed up writing data to Excel this method allow calculation to be set to manual by calling the SetCalculations() method, so data can be written, and then any calculations needed can be performed by calling the Calculate() method Parameters
Return Value
Examples ExcelDoc.SetCalculations(oix:CalculationManual)
|
|
MyExcel.ClearPrintArea ()
|
| CloseWorkbook
( byte pSaveChanges=1 ) ,byte,proc MyExcel.CloseWorkbook() ! user is prompted to save
|
| Copy
( <string pFromCell>, <string pToCell> ) ,byte,proc MyExcel.Copy () ! copies current selection MyExcel.Copy ('A1') ! copies cell A1 MyExcel.Copy ('A1', 'B3') ! copy range A1:B3
|
ColumnName (long columnNumber) Returns a string that contains the Excel name of a column when passed the number of the column. Excel names columns alphabetically. The first column is A, the second B and so on. After the 26th column (Z), two characters are used to present the column. Column 27 is AA, 28 is AB and so on. This method actually returns the characters used for any column up to 450,000. Version of Excel prior to Excel 2007 only supported 255 columns (so the final column was named IV). In Excel 2007 this limit has been increased to 16K. This method is particularly useful when processing columns in a loop. Parameters long columnNumber: Return Value Returns a string that contains the name of the column. Examples This example writes the name of each cell to that particular cell for 100 rows and 320 columns columnName
cstring(6)
|
|
CountOpenWorkbooks( ) ,long,proc TempLong = MyExcel.CountOpenWorkbooks()
|
|
CountUsedRows
( ) ,long,proc TempLong = MyExcel.CountUsedRows()
|
| CountWorksheets
( ) ,long,proc TempLong = MyExcel.CountSheets()
|
| Cut
( ) ,byte,proc MyExcel.Cut()
|
|
DeleteSelection ( long pShift ) ,byte,proc MyExcel.DeleteSelection (oix:Up)
|
|
DeleteWorksheet
( ) ,byte,proc MyExcel.DeleteWorksheet()
|
|
ErrorTrap (string pErrorString, string pFunctionName) This method is called when an error occurs. Office Inside provides embed points for this method (before parent call, and after parent call) where you can put code to deal with any errors Office Inside experiences (see the example code above - note the grey text indicates code generated by the Office Inside template, the black text is what you would add). By default any errors that Office Inside encounters will be dealt with as follows:
Parameters string pErrorString: A string containing the error description. string pFunctionName: A string that contains the name of the function that the error occured in. Examples
MyExcel.ErrorTrap
PROCEDURE (string pErrorString, string pFunctionName) Return Values None Notes Note: This is a callback method. This means that unlike normal methods that you call in order to perform some function, the OfficeInside methods will call this method. This allows you to add your own code in this method to respond to to the particular event that triggered the method being called. Note: Even if you suppress error messages the ErrorTrap method will still be called, however no message will be displayed to the user. Note: The Suppress Error Messages checkbox simply generates a line of code that sets the SuppressErrorMessages property to true. You can set this property manually if you prefer.
|
|
ExcelImport (string fileName, long progressControl=0, long columns, long startRow=1) Imports a file from Excel and allows each row to be processed. Loads a large number of file formats supported by Excel and processes each row in the file. For each row the TakeImportRecord() method is called to allow you to then process the row (record). The TakeImportRecord method is passed a queue that contains all the cells in the current row. Parameters string fileName: The file name to import. If an empty string ('') is passed the method will prompt the user for a file name. long progressControl: An optional parameter that allows the a progress control handle to be passed to the method. The progress control will be updated as the import is done. Optional. long columns: The number of columns to import. Required. long startRow: The row to start at. This value is optional and default to importing from the first row (1). Return Values Returns 1 for success and zero for failure, or if the user cancels the import (only applies if no file name was passed and the user is prompted for a file name).
Examples The below example demonstrates how to use the Who() and What() method to dynamically assign each field from the queue to a any file, based purely on field order. You could also use Who() to find fields with matching names. Alternatively you could fetch specific columns using the Get() function and assign them to specific fields rather than using a loop to do this dynamically. MyExcel.ExcelImport('expenses.xls',
?Progress, 32) MyExcel.TakeImportRecord
Procedure(long recordNumber, excelImportQType cellsQ)
|
|
This method is called by the ExcelImport method once the Excel spreadsheet has been opened, but before any data is imported. This allow the sheet to be changed, or the document otherwise manipulated or modified before the actual importing of individual records (rows) begins. Parameters None Return Values None
Examples ThisExcel.ImportSetup()
|
|
This method is called by the ExcelImport method once the Excel spreadsheet has been completely imported, but but before the spreadsheet is closed. You can use this to do any cleanup, or take any actions once the import is completed that might need to be done on the Excel document. Parameters None Return Values None
Examples ThisExcel.ImportComplete()
|
|
FreezePanes
( byte pFreeze=true ) ,byte MyExcel.FreezePanes () MyExcel.FreezePanes (false)
|
|
GetCellBackgroundColor (string fromCell, string toCell) , long Returns the background color of a cell or range of cells. The value returned is the palette position of the color, use the GetPaletteColor() and SetPaletteColor() to get and set the actual colors used. Parameters string fromCell The starting cell address. Both cell addresses can be passed as empty strings to use the currently selection. string toCell The ending cell address. This can be passed as an empty string if a specific cell, or the current selection is being used. Return Value The palette position of the background color for the specific cells, or the current selection if no cell addresses are specified. If an error occurs the method returns -1 (color:none). The retrieve the color corresponding the the palette entry returned use the GetPaletteColor method. Examples curColor = oiExcel.GetCellbackgroundColor('',
'') ! Fetch the color
for the currently selected cells |
|
GetColumnAddressFromColumnNumber (long pColumnNumber) Important: This method is deprecated and has been replaced by ColumnName(). The new method removes the limitation of 26 columns and supports up to 450,000 columns (Excel 2007 removes the 255 column limit of previous version and supports 65535 columns). The GetColumnAddressFromColumnNumber method now just calls ColumnName().
|
|
GetColumnWidth ( string pColumn ) ,string loc:ColumnWidth = MyExcel.GetColumnWidth('B')
|
|
GetInfo ( byte pOption ) ,string,proc TempString = MyExcel.GetInfo (oix:WindowState)
|
|
GetFileName (), string Returns the file name and path on disk for the currently open document. Paremeters None Return Value Returns a string containing the file name and path of the current document. If the document was not opened, and has not been saved, then it returns the current name of the document, such as 'Document1'.
|
|
GetPaletteColor
(byte pSwatch), long Unlike MS Word, Excel stores colors in a palette - you can only use the colors contained in that palette. If the default palette for a given worksheet does not contain the colors you want to use, you can change them using the SetPaletteColor method. For two palette management functions for your applications see the Examples section below, as well as the section Color Management in Excel and Cell Formattting (recommended reading). Parameters byte pSwatch: The palette position (swatch) to return the color of. Return Value Returns a long value that contains the color of the swatch (palette entry) specified by the pSwatch parameter. Notes (Important) The color swatches are the "blocks" of color you see when you click the "Font Color" droplist on the Excel toolbar. You will see there are 8 columns and 5 rows or swatches (totalling 40 swatches). We have labelled these swatches as 1 being column 1 row 1, 2 being column 2 row 1, 8 being column 8 row 1, 9 being column 1 row 2, and so on. By default, Office Inside supports using standard Clarion color equates, so long as you're using the default Excel palette, so you would simply pass COLOR:YELLOW to an Office Inside method, and it would then use the closest match to that color from the default palette. If you would rather use the palette directly (which means that passing standard Clarion color equates would no longer work), so can do this by simply setting the InterpretClarionColorEquates property to false (after calling oiExcel.Init(), which will set it to true), as shown in the example code. If you do that, then any color parameter that you pass in needs to be the color swatch number. Important: By default oiExcel.InterpretClarionColorEquates is set to true. This means that passing RGB color values, or colors stored in longs will not work. You must set this property to false (0) to pass colors as long value or as RBG colors (such as 0FF00FFh or a color value returned from the ColorDialog() function. Examples The first example below demonstrates how to create a local array of colors and a pair of procedures. This allows you to create your own color palette and synchronize it with that of Excel. Example 1 AddPaletteColor(): This adds a palette color. Note that each time a color is added the variable numColors is incremented. In this case for versions of Excel prior to Excel 2007 you should limit this to 40 entries. GetPaletteColor(): This locates a palette entry from the local palette by matching the passed color to each palette entry. You could expand on this to find the closest match. Unlike the oiExcel.GetPaletteColor method, this does not return a color at a position in a palette, it finds the color and returns the palette position.
! Local or module data Example 2 ! Let the user pick a color (RGB) Example 3 curColor2 =
MyExcel.GetPaletteColor(2) ! Fetch and
store the current color
|
|
GetRowHeight ( string ) ,string X = MyExcel.GetRowHeight (5) ! get height for row 5
|
| HideFormulaBar
( ) ,byte,proc MyExcel.HideFormulaBar()
|
|
HideStatusBar ( ) ,byte,proc MyExcel.HideStatusBar()
|
|
HideToolbar (long
pToolbar) ,byte,proc MyExcel.HideToolbar(oix:ToolbarStandard)
|
|
ImportXLSFile (string pFileName, long pProgressControl=0, long pColums=10) Important: This method is deprecated. Please use the new ExcelImport method. This method provides an easy way to import an Excel spreadsheet. You simply call this method, and then Office Inside will read the data out of the spreadsheet, one row at a time. As it reads a row, the object's ImportXLSFile_TakeRecord method will be called, and the data for that row will be contained in the parameters for the ImportXLSFile_TakeRecord method. There are actually two different ImportXLSFile_TakeRecord methods. One only passes in columns A through to J (default), the other passes in columns A through to Z. Only one of these two ImportXLSFile_TakeRecord methods will be called. Which one called is determined by the value of the pColumns parameter:
Examples Typically you would code as follows: ! Call ImportXLS file, to begin importing records MyExcel.ImportXLSFile ('c:\temp.xls') ! Once you have called ImportXLSFile, the ImportXLSFile_TakeRecord method ! will fire once for every record that is read in, you have to put code ! into that method to actually write the record to your table, as follows: MyExcel.ImportXLSFile_TakeRecord PROCEDURE (long pRowNumber, string pA, string pB, | string pC, string pD, string pE, string pF, | string pG, string pH, string pI, string pJ) ReturnValue byte CODE if pRowNumber > 10 ! you don't have to do this, but you can return
|
|
Init (byte startVisible=1, byte enableEvents=0) Initialises the oiExcel object and the COM interface and performs all setup necessary to begin automating Excel, including starting Excel itself and controlling whether Excel starts as visible to the user and whether to enable event handling. Parameters byte startVisible: Determines whether Excel is visible at startup or not. Pass as 1 (the default) to make Excel visible, or pass zero to keep Excel hidden. Note: You can also set whether Excel is visible after you have called the Init method by using the Update method, passing oix:ApplicationVisible as the property to set and 1 as the value to set it to. byte enableEvents: Determines whether event handling is enabled. Defaults to zero (no event handling). Pass as 1 to enable event handling. Return Values Returns true (1) if successful and false (0) if the method fails. Examples !
Initialise with the standard parameter values (Excel visible with no
event handling)
|
| InsertColumn
( <string pCellAddress>,
byte pShiftOption=0 ) ,byte,proc
MyExcel.InsertColumn () MyExcel.InsertColumn ('C3')
|
|
InsertRow ( <string
pCellAddress>, byte pShiftOption=0 ) ,byte,proc
MyExcel.InsertRow () MyExcel.InsertRow ('C3')
|
|
InsertWorksheet ( ) ,byte,proc MyExcel.InsertWorksheet()
|
|
Kill ( byte
pUnloadCOM=1 ) ,byte,proc
MyExcel.Kill()
|
|
MergeCells ( string
pFromCell, string pToCell ) , byte, proc
MyExcel.MergeCells ('B2', 'C4') Merges the range of cells identified by the pFromCell and pToCell parameters.
|
|
NewWorkbook ( ) ,byte,proc MyExcel.NewWorkbook()
|
|
OpenWorkbook ( string
pFileName ) , byte, proc MyExcel.OpenWorkbook()
|
|
Paste ( ) ,byte,proc Same effect as "Edit --> Paste" in MS Excel. Example MyExcel.Paste()
|
|
PasteSpecial ( ) , byte, proc
This method has not been implemetned in this realease. Example
Notes Not yet implemented...
|
|
PrintMe ( ) ,byte,proc Prints the current document to the default system printer. Return Value Returns true (1) if no problems were experienced. Examples
Notes More options to follow in future releases...
|
|
PrintPreview ( ) ,byte, proc MyExcel.PrintPreview()
|
|
ProtectWorkbook ( string
pPassword, byte pStructure, byte
pWindows ) , byte, proc
This is the equivalent of "Tools" --> "Protection" --> "Protect Workbook" in MS Excel. If you are unfamiliar with protecting sheets refer to the MS Excel documentation (search for "Protect workbooks from changes").
|
|
ProtectWorksheet
( string pPassword, byte pDrawingObjects, byte pContents, byte pScenarios, byte pUserInterfaceOnly
) ,byte,proc MyExcel.ProtectWorksheet('MyPassword', true, true, true, false)
|
| ReadCell (<string pCellAddress>, byte pFormula=false) , string
Reads a value from a cell, which is returned as a string. There is a limit of 255 characters for the returned data.
cellValue string(255) cellFormula string(255)
|
| Redo
( ) ,byte,proc MyExcel.Redo()
|
|
RenameWorksheet ( string pName ) ,byte,proc MyExcel.RenameWorksheet ('Sales')
|
| ReplaceText ( string pFindText, string pReplaceText, byte pReplaceAll=false ) ,byte,proc MyExcel.ReplaceText ('Cape', 'Soft', true)
|
| Save
( ) ,byte,proc MyExcel.Save()
|
|||||||||||||||||||||||||||||||||||||||||||||||
| SaveAs (<string
FileName>, <long
fileType>) Saves the current workbook using the name provided in the FileName parameter. Also optionally allows the File Type to be specified, which is particularly useful with Office 2007, which default to a new XLSX format, and displays a "Compatibility Warning" dialog box when saving a file that has the .XLS extension. Return Values Returns true (1) if no problems were experienced and zero (0) if the function failed. When an error occurs the ErrorTrap() method is called with error information, if you have debug logging enabled this will be output to the debug log and can be viewed using DebugView. Parameters string fileName (optional): Specified the name of the file that the document should be saved as, and should include the full path if the file is not saved in the current directory. If no file name is specified the user is prompted for a name. long fileType (optional): A value that determines the type of file saved. This can be used to override the default Excel file type. For example in Excel 2007 the default file type is .XLSX, which cannot be opened by previous versions of Excel. This can be used to save as a standard XLS file, which is compatible with Excel 97, 2000, XP and 2003. The below table shows a list of all possible values, and the equates provided for the values, as well as a description of the file type.
|