MyExcel.Save(MyDctTable, 'MyTable') !Where MyDctTable is a table structure in your dct, and MyTable is the name of the excel file to export to (don't worry about the .xls or .xlsx extension - OfficeInside will figure out which version your user is using and assign the extension accordingly) MyExcel.Load(MyDctTable, 'MyTable') !as above, but loads the data from the Excel spreadsheet into your table.
if not MyExcel.Load(Customers, excelFileName)
Message('Cannot import the data, loading failed. ' & CLip(MyExcel.errorMessage), 'Import Error', Icon:Exclamation)
end
BrowseCustomers.ResetFromFile()
! When loading from a File, populate the autonumber ID field
MyExcel.TakeRecord Procedure (*excelImportQType cellsQ)
code
if self.dataType = oi:file and self.action <> oix:Save
Access:Customers.PrimeRecord(true) ! Prime the record, do not clear fields
end
return parent.TakeRecord(cellsQ) ! Call the parent to continue processing
! When loading from a File, call the FileManager Insert method and return.
! For all other cases, call the parent to before the default action.
MyExcel.InsertRecord Procedure()
code
if self.dataType = oi:file and self.action <> oix:Save
return Access:Customers.Insert()
else ! Use the default behaviour when saving
parent.InsertRecord()
end
MyExcel.MapFieldToColumn(5,1) !Map table/queue/group field number 5 to excel spreadsheet column 1. MyExcel.MapFieldToColumn(2,2) MyExcel.MapFieldToColumn(3,3) MyExcel.MapFieldToColumn(4,3) !This will override the previous line, so that field 4 will be mapped to col 3. MyExcel.MapFieldToColumn(5,5) !This will clear the first mapping, in that Field 5 will now be mapped to Col 5. if not MyExcel.Save(BrowseCustomersQ, excelFileName) Message('Cannot Save the data. ' & Clip(MyExcel.errorMessage), 'Export Error', Icon:Exclamation) end
The Save method is designed to be completely containerized, so it initializes, opens, does the export, closes and kills the Excel com object to be self-contained in one method. If you are wanting to perform additional functions, the full range of oiExcel functionality is available to you, which you can use in the derived TakeComplete method.
MyExcel.Takeomplete procedure
code
parent.TakeComplete()
!Write your code in hear using the various
oiExcel methods and properties.
numColors long ! number of colors used in the custom excel palette
colorPalette long, dim(40) ! colors in the excel palette
curColor long ! the current color in the excel palette
palettePos long ! position of the current color in the palette
cellFontColor long ! The color to set the cell to
curCell string(5) ! The current cell
columnNumber long ! The current column number
rowNumber long ! The current row number
code
ExcelDoc.intepretClarionColorEquates = 0 ! Important: Treat passed colors as RGB
numColors = 1 ! First color in the Excel palette is always black
palettePos = 1 ! The current position in our palette
colorPalette[1] = color:black ! An array of colors (256)
curColor = color:black ! the current color
! Each time I need to use a specific color I check whether
! it needs to be added to the palette:
if not ExcelDoc.GetPaletteColor(cellFontColor)
ExcelDoc.SetPaletteColor(cellFontColor)
end
ExcelDoc.SetCellFontColor(palettePos, currentCell)
Methods and Properties for color managment:! Adds a color to the local and Excel paletteAddPaletteColor procedure(long pColor)
code
if NumColors > 39 and ExcelDoc.GetOfficeVersion < 12 ! Limit colors for old versions
! can do error handling here, or choose which color entry to replace etc.
return
end
numColors += 1
colorPalette[numColors] = pColor
curColor = pColor
palettePos = numColors
! add the color to the excel palette
ExcelDoc.SetPaletteColor(numColors, pColor)
! This locates a passed color in the palette and returns the position
GetPaletteColor procedure(long pColor)
i long
code
loop i = 1 to 40
if colorPalette[i] = pColor
curColor = colorPalette[i]
palettePos = i
return i
end
end
return 0
! Store the cell name (Note that the new method is called ColumnName()
! instead of GetColumnAddressFromColumnNumber())
currentCell = ExcelDoc.ColumnName(columnNumber) & rowNumber
! Add the data:
ExcelDoc.WriteToCell(cellData, currentCell)
! Format the cell:
ExcelDoc.SetCellFontName(cellFontName, currentCell)
ExcelDoc.SetCellFontSize(cellFontSize, currentCell)
!Set the picture: ExcelDoc.SetCellTextFormat('@n03') !You can also use the Excel format pictures directly if you know the excel picture to use !using SetCellNumberFormat
if Band(cellFontStyle, font:weight) >= font:bold
ExcelDoc.SetCellFontStyle('Bold', currentCell)
end
if Band(cellFontStyle, font:underline)
ExcelDoc.SetCellFontUnderline(oix:UnderlineStyleSingle, currentCell)
end
if cellFontColor > 0
if not ExcelDoc.GetPaletteColor(cellFontColor)
ExcelDoc.SetPaletteColor(cellFontColor)
end
ExcelDoc.SetCellFontColor(palettePos, currentCell)
end
if backgroundColor <> color:none
if not ExcelDoc.GetPaletteColor(backgroundColor)
ExcelDoc.SetPaletteColor(backgroundColor)
end
ExcelDoc.SetCellBackgroundColor(palettePos , currentCell)
end
excel oiExcel
row long
tot long
code
excel.OpenWorkbook(myWorkbookFile) ! Open the workbook
tot = excel.CountUseRows() ! Get the number of used rows
loop row = 1 to tot
idNumber = excel.ReadCell('A' & row) ! Get the ID from a particular cell
if idNumber = someValue
excel.SelectRows (row)
excel.DeleteSelection(oix:up)
end
end
excel.Save()
oiExcel Methods | |
---|---|
Workbook Methods | |
NewWorkbook | Creates a new workbook |
OpenWorkbook | Opens an existing workbook |
CloseWorkbook | Closes the currently open workbook |
CountOpenWorkbooks | Returns the number of workbooks opened in this instance of Excel |
GetFileName | Returns the current file name and path on disk. |
ProtectWorkbook | Turns on protection for the current workbook |
UnprotectWorkbook | Turns off protection for the current workbook |
Save | Saves changes to the current workbook |
SaveAs | Saves the workbook as a file on disk. |
Worksheet Methods | |
InsertWorksheet | Inserts a new worksheet |
DeleteWorksheet | Deletes a worksheet |
RenameWorksheet | Renames a worksheet |
CountWorksheets | Returns the number of worksheets in the workbook |
ProtectWorksheet | Turns on protection for the worksheet |
UnprotectWorksheet | Turns off protection for the worksheet |
SelectWorksheet | Selects a particular worksheet in the current workbook |
Rows and Column Methods | |
InsertColumn | Inserts a new column |
InsertRow | Inserts a new row |
CountUsedRows | Returns the number of rows that have been used (contain data) |
CountUsedColumns | Returns the number of columns that have been used (contain data) |
ColumnName | Converts a column number into the Excel name for that column. |
GetColumnAddressFromColumnNumber | Converts a number for the column into the Excel name for that column. Deprecated: replaced by ColumnName() |
GetColumnWidth | Returns the width of a column |
GetRowHeight | Returns the height of a row |
SelectRows | Selects one or more rows |
SelectColumns | Selects one or more columns |
SetRowHeight | Sets the height of a row |
SetColumnWidth | Sets the width of a column |
Printing Methods | |
SetPrintArea | Sets the area to print (limits printing to the set area) |
ClearPrintArea | Clears the are that was set using SetPrintArea() method |
PrintMe | Prints the document (see the PrintWorkbook and PrintWorksheet for the newer, more extensive methods) |
PrintPreview | Prints the document and displays a preview before printing to allow the user to choose whether to print or not and to check the print settings. |
PrintSheet | Print out the current sheet in the current workbook |
PrintWorkbook | Print the current workbook |
GetActivePrinter | This method returns the currently selected active printer. |
SetActivePrinter | This method sets the currently selected active printer. |
Editing Methods | |
Copy | Copies the current selection to the clipboard |
Find | Searches for a string in the document |
Paste | Pastes from the clipboard to the current position |
Undo | Undoes the last action |
Redo | Redoes an action that was undone |
DeleteSelection | Deletes the current selection |
ReplaceText | Replaces one or all occurrences of a string with the string specified. |
AddImage | Add an image at the currently selected cell. |
View and Application Methods | |
GetInfo | Retrieves a variety of information related to Excel, the user, and the current document. This information can be updated using the Update() method. |
Update | Sets a variety of information related to Excel, the user, and the current document. This information can be retrieved using the Get Info() method. |
GetPaletteColor | Returns the colour at the passed palette position. |
SetPaletteColor | Sets a colour in the Excel palette |
RunFile | Opens the Excel file in the parameter |
View Management | |
SetPageView | Sets the way the page is displayed |
ShowFormulaBar | Displays the Formula toolbar |
HideFormulaBar | Hides the Formula toolbar |
ShowToolbar | Shows the main Toolbar |
HideToolbar | Hides the main Toolbar |
ShowStatusBar | Shows the Status bar at the bottom of the window |
HideStatusBar | Hides the Status bar |
FreezePanes | |
Utility Methods | |
ErrorTrap | Called with error and warning messages. Provides centralised error handling and reporting. |
GetObjects | Called to initialize the various oiObjects in the Excel class. |
Init | Initialises the object and the COM interface if needed |
Kill | Disposes of the object and the COM interface if it is no longer being used by any objects. |
TakeEvent | Event handling, called when an event occurred in Word |
ExcelImport | Deprecated: Use the
oiExcelImpEx class for importing and exporting data. Imports a file from Excel into Clarion and calls the TakeImportRecord method for each row (record) imported. |
TakeImportRecord | Called by ExcelImport to allow each row (record) to be processed. |
ImportSetup | ExcelImport() Callback method - the spreadsheet has been opened, before records are imported. |
ImportComplete | ExcelImport() Callback method - import is complete, before the spreadsheet is closed. |
ImportXLSFile (deprecated) | Deprecated, replaced by ExcelImport |
AutoFilter | Enables Excel's auto filtering on a range of cells. |
Cell Methods | |
ReadCell | Gets the value of the specified cell |
WriteToCell | Sets the value of the specified cell |
WriteFormulaToCell | Writes a formula to a specified cell |
MergeCells | Merges a range of cells into a single large cell |
UnmergeCells | Unmerges a merged range of cells back into the original cells |
SelectCells | Selects a range of cells |
Cell Formatting | |
GetCellBackgroundColor | Gets the background color for a cell or a range of cells. |
SetCellAlignment | Sets the alignment for the contents of the selected cells |
SetCellBackgroundColor | Sets the background colour of the selected cells. |
SetCellBorders | Sets the borders for the selected cells |
SetCellFontColor | Sets the cell font colour |
SetCellFontName | Sets the font for the contents of the selected cells. |
SetCellFontSize | Sets the size of the font used for the selected cells |
SetCellFontStyle | Sets the style of the font (bold, italic etc.) |
SetCellFontUnderline | Underlines the contents of the selected cells |
SetCellNumberFormat | Sets the format (picture) used to display the contents of the selected cells. |
SetCellTextFormat | Sets the format (picture) used to display the contents of the selected cells using a clarion picture. |
SetCellProtection | Turns on or off cell protection |
Performance and Optimization | |
SetCalculations | Enables or disables automatic calculation each time a cell is modified. Turning this off has a massive performance impact when doing bulk insertion. |
Calculate | Forces a manual recalculation when SetCalculations() has been used to turn it off. |
SetScreenUpdating | Turns screen updating on or off. For use when Excel is hidden and a batch update is done. Has a small performance impact. |
Example |
---|
ExcelDoc.SetCalculations(oix:CalculationManual) |
Example |
---|
MyExcel.Copy () ! copies current selection MyExcel.Copy ('A1') ! copies cell A1 MyExcel.Copy ('A1', 'B3') ! copy range A1:B3 |
Parameter | Description |
---|---|
pFind | The string to search for. |
pAfter [Optional] | The cell after which you want the search to begin. This corresponds to the position of the active cell when a search is done from the user interface. Note that After must be a single cell in the range. Remember that the search begins after this cell; the specified cell isn't searched until the method wraps back around to this cell. If you don't specify this argument, the search starts after the cell in the upper-left corner of the range. |
lookIn [Optional] | The search location - can be one of the following values: oix:Comments (-4144), oix:Formulas (-4123), oix:Values (-4163) |
lookAt | The type of matching to do. Can be oix:Part (2) or oix:Whole (1). oix:Whole means that the text search for and the text searched in are an exact match. oix:Part means that the text searched for exists in the text searched. |
searchOrder | Can be either oix:ByRows (1) or oix:ByColumns (2). |
searchDirection | The direction to search in, either oix:Next (1) or oix:Previous (2) |
matchcase | Whether the search is case sensitive or not. oi:False for case insensitive, oi:True for case sensitive search |
matchByte | Only applies for double byte languages (Unicode). Setting this to true force double byte chars to only match double byte chars (which is not desired behaviour with Clarion strings) |
Parameter | Description |
---|---|
long | columnNumber: |
Example |
---|
columnName
cstring(6) col long row long code MyExcel.SetCalculations(oix:CalculationManual) ! Improve bulk insert performance loop col = 1 to 320 columnName = MyExcel.ColumnName(col) loop row = 1 to 100 MyExcel.WriteToCell(columnName & row , columnName & row) end end MyExcel.SetCalculations(oix:CalculationAutomatic) |
Parameter | Description |
---|---|
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) code PARENT.ErrorTrap (pErrorString, pFunctionName) if pErrorString = 'Init Failed' |
Parameter | Description |
---|---|
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). |
Examples |
---|
MyExcel.ExcelImport('expenses.xls',
?Progress, 32) ! This will call the TakeImportRecord() method for each record, ! which allows the records to be processed (see below):MyExcel.TakeImportRecord Procedure(long recordNumber, excelImportQType cellsQ) ReturnValue long destField any sourceField any i long code loop i = 1 to Records(cellsQ) Get(cellsQ, i) sourceField = Clip(cellsQ.cell) if Who(MyFile.Record, i) <> '' ! If the field exists in the file assign to it. destField &= What(MyFile.Record, i) destField = sourceField end end if Access:MyFile.Insert() return level:fatal ! Error adding a record, cancel import end return level:benign ! continue importing ! Parent Call ReturnValue = parent.TakeImportRecord(recordNumber, cellsQ) ! [Priority 5000] ! End of "Class Method - Executable Code Section" Return ReturnValue |
Example |
---|
CurrentPrinter = MyExcel.GetActivePrinter () |
Examples |
---|
ThisExcel.ImportSetup() code ! Select worksheet to import using the worksheet name self.SelectWorksheet('Sheet 2') parent.ImportSetup() |
Examples |
---|
ThisExcel.GetObjects() |
Examples |
---|
ThisExcel.ImportComplete() code ! Save a copy of the imported document as a CSV file in an 'Imported' folder self.SaveAs(LongPath() & '\' & 'Imported\' | & Format(Today(), @D6) & '.xls', oix:xlCSV) parent.ImportComplete() |
Example |
---|
MyExcel.FreezePanes () MyExcel.FreezePanes (false) |
Parameter | Description |
---|---|
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. |
Examples |
---|
curColor = oiExcel.GetCellbackgroundColor('',
'') ! Fetch the color
for the currently selected cells curColor = oiExcel.GetCellbackgroundColor('A1', '') ! Fetch the color for a specific cell curColor = oiExcel.GetCellbackgroundColor('D1', 'E7')! Fetch the color for the range of cells specified |
Example |
---|
MyExcel.WriteToCell ('Cell A1', (MyExcel.GetColumnAddressFromColumnNumber(1) & '1') ) MyExcel.WriteToCell ('Cell B1', (MyExcel.GetColumnAddressFromColumnNumber(2) & '1') ) MyExcel.WriteToCell ('Cell C1', (MyExcel.GetColumnAddressFromColumnNumber(3) & '1') ) |
Parameter | DDescription |
---|---|
byte pSwatch | The palette position (swatch) to return the color of. |
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 numColors long ! number of colors used in the custom excel palette colorPalette long, dim(40) ! colors in the excel palette curColor long ! the current color in the excel palette palettePos long ! position of the current color in the palette ! Adds a color to the local and Excel palette AddPaletteColor procedure(long pColor) code if NumColors > 39 and ExcelDoc.GetOfficeVersion < 12 ! Limit colors for old versions ! can do error handling here, or choose which color entry to replace etc. return end numColors += 1 colorPalette[numColors] = pColor curColor = pColor palettePos = numColors ! add the color to the excel palette ExcelDoc.SetPaletteColor(numColors, pColor) ! This locates a passed color in the palette and returns the position GetPaletteColor procedure(long pColor) i long code loop i = 1 to 40 if colorPalette[i] = pColor curColor = colorPalette[i] palettePos = i return i end end return 0 |
Example 2 |
---|
! Let the user pick a color (RGB) if ColorDialog('Select a color', tempLong) ! Set InterpretClarionColorEquates to false and pass RGB colors, ! Not Clarion color equates. MyExcel.InterpretClarionColorEquates = false ! Set swatch 33 to this RGB color (column1, row5 in palette) MyExcel.SetPaletteColor (33, tempLong) ! Set cell B2 to the color in swatch 33, which we just set MyExcel.SetCellBackgroundColor (33, 'B2') end |
Example 3 |
---|
curColor2 =
MyExcel.GetPaletteColor(2) ! Fetch and
store the current color MyExcel.SetPaletteColor(2, color:red) ! Replace it with red (Clarion color equate) curColor3 = MyExcel.GetPaletteColor(3) MyExcel.InterpretClarionColorEquates = false MyExcel.SetPaletteColor(3, 0FF00CCh) ! Set to an RGB color value ! Set cell B2 to the color in swatch 33, which we just set MyExcel.SetCellBackgroundColor(3, 'B2') |
Example |
---|
! 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 ! record:OutOfRange to stop processing records return Record:OutOfRange end if access:TempExcelTable.tryinsert() = level:benign TMP1:ColumnA = pA TMP1:ColumnB = pB TMP1:ColumnC = pC TMP1:ColumnD = pD TMP1:ColumnE = pE TMP1:ColumnF = pF TMP1:ColumnG = pG Access:TempExcelTable.update() end ReturnValue = PARENT.ImportXLSFile_TakeRecord(pRowNumber, pA, pB, pC, pD, | pE, pF, pG, pH, pI, pJ) |
Example |
---|
!
Initialise with the standard parameter values (Excel visible with no
event handling) MyExcel.Init() ! Initialise with Excel hidden and event handling on: |
Parameter | Description |
---|---|
pFileName | The name of the file to open. Can be any format supported by the version of Excel installed. If pFileName is empty or omitted, then the user is prompted to select a file to open. |
Examples |
---|
MyExcel.OpenWorkbook() ! Prompts the user for the file name |
MyExcel.OpenWorkbook(LongPath() & '\data.xlsx') ! Opens the specified file |
Example |
---|
! Excel print settings oixPrintProperties group, type pFrom long ! The number of the page at which to start printing. If this argument is omitted, printing starts at the beginning. pTo long ! The number of the last page to print. If this argument is omitted, printing ends with the last page. copies long ! The number of copies to print. If this argument is omitted, one copy is printed. pPreview long ! True to have Microsoft Excel invoke print preview before printing the object. False (or omitted) to print the object immediately. activePrinter cstring(200) ! Sets the name of the active printer. printToFile long ! True to print to a file. If PrToFileName is not specified, Microsoft Excel prompts the user to enter the name of the output file. collate long ! True to collate multiple copies. ! These two properties are not supported by the _PrintOut() method, which is being used, as the PrintOut() method always fails. prToFileName cstring(260) ! If PrintToFile is set to True, this argument specifies the name of the file you want to print to. ignorePrintAreas long ! True to ignore print areas and print the entire object. end |
Example |
---|
cellValue string(255) cellFormula string(255) |
Parameter | Description |
---|---|
string pFileName (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. |
string pOpenPassword (optional) | If this is set then this sets an Open password for the file. The user will need to enter this password in order to open the file. |
string pEditPassword (optional) | If this is set then this sets an Edit password for the file. The user will need to enter this password in order to edit the file. |
Name | Value | Description |
oix:xlAddIn | 18 | Microsoft Excel 2007 Add-In |
oix:xlAddIn8 | 18 | Microsoft Excel 97-2003 Add-In |
oix:xlCSV | 6 | CSV |
oix:xlCSVMac | 22 | Macintosh CSV |
oix:xlCSVMSDOS | 24 | MSDOS CSV |
oix:xlCSVWindows | 23 | Windows CSV |
oix:xlCurrentPlatformText | -4158 | Current Platform Text |
oix:xlDBF2 | 7 | DBF2 |
oix:xlDBF3 | 8 | DBF3 |
oix:xlDBF4 | 11 | DBF4 |
oix:xlDIF | 9 | DIF |
oix:xlExcel12 | 50 | Excel12 |
oix:xlExcel2 | 16 | Excel2 |
oix:xlExcel2FarEast | 27 | Excel2 FarEast |
oix:xlExcel3 | 29 | Excel3 |
oix:xlExcel4 | 33 | Excel4 |
oix:xlExcel4Workbook | 35 | Excel4 Workbook |
oix:xlExcel5 | 39 | Excel5 |
oix:xlExcel7 | 39 | Excel7 |
oix:xlExcel8 | 56 | Excel8 |
oix:xlExcel9795 | 43 | Excel9795 |
oix:xlHtml | 44 | HTML format |
oix:xlIntlAddIn | 26 | International Add-In |
oix:xlIntlMacro | 25 | International Macro |
oix:xlOpenXMLAddIn | 55 | Open XML Add-In |
oix:xlOpenXMLTemplate | 54 | Open XML Template |
oix:xlOpenXMLTemplateMacroEnabled | 53 | Open XML Template Macro Enabled |
oix:xlOpenXMLWorkbook | 51 | Open XML Workbook |
oix:xlOpenXMLWorkbookMacroEnabled | 52 | Open XML Workbook Macro Enabled |
oix:xlPDF | 57 | Save As PDF File |
oix:xlSYLK | 2 | SYLK |
oix:xlTemplate | 17 | Template |
oix:xlTemplate8 | 17 | Template 8 |
oix:xlTextMac | 19 | Macintosh Text |
oix:xlTextMSDOS | 21 | MSDOS Text |
oix:xlTextPrinter | 36 | Printer Text |
oix:xlTextWindows | 20 | Windows Text |
oix:xlUnicodeText | 42 | Unicode Text |
oix:xlWebArchive | 45 | Web Archive |
oix:xlWJ2WD1 | 14 | WJ2WD1 |
oix:xlWJ3 | 40 | WJ3 |
oix:xlWJ3FJ3 | 41 | WJ3FJ3 |
oix:xlWK1 | 5 | WK1 |
oix:xlWK1ALL | 31 | WK1ALL |
oix:xlWK1FMT | 30 | WK1FMT |
oix:xlWK3 | 15 | WK3 |
oix:xlWK3FM3 | 32 | WK3FM3 |
oix:xlWK4 | 38 | WK4 |
oix:xlWKS | 4 | Worksheet |
oix:xlWorkbookDefault | 51 | Workbook default |
oix:xlWorkbookNormal | -4143 | Workbook normal |
oix:xlWorks2FarEast | 28 | Works2 FarEast |
oix:xlWQ1 | 34 | WQ1 |
oix:xlXMLSpreadsheet | 46 | Spreadsheet |
Example |
---|
! Dangerous in Excel 2007
this may save as an xlsx file with an .xls extension ! which will display a warning when the document is opened, and may display ! a compatibility dialog when the document is saved in Excel 2007 MyExcel1.SaveAs(' test.xls ') ! Save in the default format and allow Excel to set the correct extension MyExcel1.SaveAs('test', oix:xlWorkbookDefault) ! Prompt the user MyExcel1.SaveAs() ! Save as a "normal" workbook (.xls), may display a compatibility dialog in Excel 2007 MyExcel1.SaveAs(LongPath() & '\' & Clip(excelFileName), oix:xlWorkbookNormal) |
Example |
---|
MyExcel.SelectCells ('B3') MyExcel.SelectCells ('B3', 'D12') MyExcel.SelectCells () ! Ctrl-A |
Example |
---|
MyExcel.SelectColumns ('B') MyExcel.SelectColumns ('B', 'D') |
Example |
---|
MyExcel.SelectRows (3) MyExcel.SelectRows (3, 8) |
Example |
---|
MyExcel.SelectWorksheet ('Sheet2') MyExcel.SelectWorksheet ('My Sheet') MyExcel.SelectWorksheet ('', 2) |
Parameter | Description |
---|---|
long calcType |
determines how Excel will handle inserted data. Can
be one of three values:
|
Example |
---|
ExcelDoc.SetCalculations(oix:CalculationManual)
! document being updated ExcelDoc.SetScreenUpdating(false) ! Write the required data to the worksheet here... ! Manually calculate (if necessary) ExcelDoc.Calculate() ! Automatic calculation can be optionally turned back on: EExcelDoc.SetCalculations(oix:CalculationAutomatic) |
Example |
---|
MyExcel.SetActivePrinter ('CutePDF Writer on CPW2:') |
Parameter | Description |
---|---|
long updateScreen | Set this to 1(true) to turn screen updating on, and to zero (false) to turn screen updating off. |
Example |
---|
ExcelDoc.SetCalculations(oix:CalculationManual)
! Screen updating can be turned off to provide a small performance boost ! in cases where the window is hidden or the user does not need to see the ! document being updated ExcelDoc.SetScreenUpdating(false) ! Write the required data to the worksheet here... ! Manually calculate (if necessary) ExcelDoc.Calculate() ! Automatic calculation can be optionally turned back on ExcelDoc.SetCalculations(oix:CalculationAutomatic) |
Parameter | Description |
---|---|
long option | Specifies which option is being set. This parameter
determines what the method actually does. Can have one of the following
values:
|
string value | The value to set the specified option to. The values for each option are listed under that option above. |
string fromCell | An optional parameter specifying the cell or start of a range of cells to apply the option to. The fromCell and toCell parameters are optional, and if they are not passed then the current selection in the document is used. If a single cell is passed in the fromCell parameter and toCell is not passed then only that single cell is affected. If both fromCell and toCell are specified they are used to determine the rectangular region of cells that are affected. Both fromCell and toCell must specify an Excel cell name. For example A1, B22, BA2 etc. You can use the ColumnName() method to convert a column number into the Excel name for that column. |
string toCell | An optional parameter specifying the cell or start of a range of cells to apply the option to. See the description for the fromCell parameter above for more information. |
Example |
---|
! Align the current selection right MyExcel.SetCellAlignment(oix:HorizontalAlignment, oix:xlRight) |
! Turn text wrapping on for a range of cells MyExcel.SetCellAlignment(oix:WrapText, true, 'B2', 'C4 ') |
! Turn text wrapping off for a range of cells MyExcel.SetCellAlignment(oix:WrapText, false, 'B2', 'C4') |
! Turn text wrapping off for a range of cells MyExcel.SetCellAlignment(oix:WrapText, false, 'B2', 'C4') |
Example |
---|
MyExcel.SetCellBackgroundColor
(oix:ColorYellow) MyExcel.SetCellBackgroundColor (oix:ColorYellow, 'D5') MyExcel.SetCellBackgroundColor (oix:ColorRed, 'B2', ' C5') MyExcel.SetCellBackgroundColor (oix:Color55, 'B2', 'C5') |
Example |
---|
MyExcel.SetCellBorders ('D5', '', oix:BorderEdgeBottom,
oix:LineStyleDouble) MyExcel.SetCellBorders ('B2', 'C6', oix:BorderEdgeBottom, oix:LineStyleContinuous) MyExcel.SetCellBorders ('B2', 'C6', oix:BorderEdgeTop, oix:LineStyleContinuous) MyExcel.SetCellBorders ('B2', 'C6', oix:BorderEdgeLeft, oix:LineStyleContinuous) MyExcel.SetCellBorders ('B2', 'C6', oix:BorderEdgeRight, oix:LineStyleContinuous) MyExcel.SetCellBorders ('B2', 'C6', oix:BorderInsideHorizontal, oix:LineStyleContinuous) MyExcel.SetCellBorders ('B2', 'C6', oix:BorderInsideVertical, oix:LineStyleContinuous) MyExcel.SetCellBorders ('D5', '', oix:BorderEdgeBottom, oix:LineStyleNone, oix:BorderWeightThick, color:red) |
Parameter | Description |
---|---|
long pFontColor | The font color for the cells. The type of the value passed is dependant on the .interpretClarionColorEquates property. If this is set to True, then the passed value is a Clarion color equate, such as Color:Yellow or Color:Red. If this is set to False (0), then the value passed is a position in the Excel palette. See the Remarks and See Also sections for palette and color management information. |
string pFromCell (optional) | If specified this is the starting cell of the selection to set the font color for. If this is not passed the current selection is used. If pFromCell is passed and pToCell is omitted, then the font color is set for the single cell. |
string pToCell (optional) | If specified this determines the end of the selection to set the font color for (all cells from pFromCell to pToCell will be modified). If both pFromCell and pToCell are omitted, then the currently selected cells are modified. If only pFromCell is passed, then just that cell is modified. |
Example |
---|
MyExcel.SetCellFontColor (color:red)
! currently selected cell/range MyExcel.SetCellFontColor (color:red, 'A1') ! cell A1 MyExcel.SetCellFontColor (color:red, 'A1', 'C3') ! range A1:C3 |
Example |
---|
MyExcel.SetCellFontName ('Verdana')
! currently selected cell MyExcel.SetCellFontName ('Arial', 'A1') ! cell A1 MyExcel.SetCellFontName ('Verdana', 'A1', 'C3') ! cell range A1:C3 |
Example |
---|
MyExcel.SetCellFontSize (16) ! currently
selected cell / range MyExcel.SetCellFontSize (20, 'A1') ! cell A1 MyExcel.SetCellFontSize (16, 'A1', 'C3') ! range A1:C3 |
Example |
---|
MyExcel.SetCellFontStyle ('Bold') ! currently
selected cell/range MyExcel.SetCellFontStyle ('Bold Italic', 'A1') ! cell A1 MyExcel.SetCellFontStyle ('Bold', 'A1', 'C3') ! range A1:C3 |
Example |
---|
MyExcel.SetCellFontUnderline (oix:UnderlineStyleDouble) MyExcel.SetCellFontUnderline (oix:UnderlineStyleNone, 'A1') MyExcel.SetCellFontUnderline (oix:UnderlineStyleDouble, 'A1', 'C3') |
Parameter | Description |
---|---|
string pPicture | Must be a clarion picture token (see the Clarion docs for picture
tokens): Currently supported (at the time of writing) Time, Date,
Numeric and Currency and String pictures. Special Overrides: Currency - uses the predefined Excel Currency picture. |
string pFromCell and string pToCell | used to specify the range which is going to be formatted. If you only want to format a single cell either pass the same address in both parameters, or pass the second parameter as nothing ( ' ' ). e.g. ('A1', ' A1'...) or ('A1', '', ...). To format the currently selected cell, omit these parameters |
Parameter | Description |
---|---|
string pFromCell and string pToCell | used to specify the range which is going to be formatted. If you only want to format a single cell either pass the same address in both parameters, or pass the second parameter as nothing ( ' ' ) e.g. ('A1', 'A1'...) or ('A1', '', ...) |
long pFormatType | Must be one of the following equates:
|
long pSymbol | Only applies if yourFormatType is
Currency or Accounting (see list above). This is used to set
the currency symbol displayed with your numbers.
pSymbol can be one of the following: ( if your currency is not listed
here please see the Note section below for using
any format supported by Excel)
|
long pDecimalPlaces | Only applies if your formatType is Number, Currency, Accounting, Percentage or Scientific. As the name implies, it is used to set the number of decimal places. |
long pSubType | Only applies if your FormatType is
Date, Time, Fraction, Special or Custom. Implementation is as
follows:
If FormatType is Date, then pSubType can be 1 through to 13 - examples of these date formats are:
|
Example |
---|
MyExcel.WriteToCell ('5.98', 'A3') MyExcel.SetCellNumberFormat(oix:NumberFormatCurrency, oix:CurrencySymbolUnitedKingdom, 2, , 'A3') Notes: Additional Formats, Fractions, Custom Pictures and Currencies.If formatType is Fraction, Special or Custom, then this method does not support it, however you can call an internal method to set the value to any value supported by Excel. You need to call the following method: oiExcel._WrapperRange (16, '', '', formatString, '', '', '') The formatString parameter contains a picture for the string and the number of decimal places. This is a standard Excel format string, and exactly the same string that works in Excel will work in this string: formatString = '#,##0.00' ! no currency, 2 decimal places formatString = '[$�-809]#,##0.000' ! UK Pound, 3 decimal places formatString = '[$$-409]#,##0.00' ! US Dollar, 3 decimal places formatString = '[$$-2409]# ##0.00' ! Caribbean dollar, 2 decimal spaces You can even use formats such as: formatString = '$#,##0;[Red]$#,##0' Which uses the dollar sign and comma separator for thousands, and no decimal places. The second part after the semi colon will cause negative numbers to be displayed in red (without a minus sign, sign it isn't explicitly stated in this case). In order to get the format strings for all the currencies (or anything else) that you need, open Excel, right click on a cell, and choose Format from the popup menu. In the dialog box displayed select the currency format that you want to use. Once you have the currency format select, the number of decimal places etc. change from Currency to Custom in the Category list on the left. It will display the picture used for this format. For example the following option is selected from the dropdown: $ English (Caribbean) Then and enter 2 decimal spaces, and switch from Currency to Custom in the Category list. The following picture is display: [$$-2409]# ##0.00 The value can be passed as the formatString parameter to the _WrapperRange method. |
Example |
---|
MyExcel.SetCellProtection (true, false) !
currently selected cell / range MyExcel.SetCellProtection (true, true, 'A1') ! cell A1 MyExcel.SetCellProtection (false, false, 'A1', 'C4') ! range A1:C4 |
Example |
---|
MyExcel.SetColumnWidth ('A', 'C', '15.71') MyExcel.SetColumnWidth ('A', , '18.45') |
Parameter | Description |
---|---|
byte pSwatch | The position in the palette to set |
long pColor | The color to set the specified color entry to. There are two ways of passing colors that are supported of OfficeInside. You can pass clarion color equates such as color:red, or you can pass the actual color values using a variable, or a numeric value such as 0FF0C0Ah. By default only Clarion color equates may be used. If you wish to pass the actual color values you must set the oiExcel.InterpretClarionColorEquates property to zero. It is set to 1 (true) by default. |
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 find the color and returns the palette position. ! Local or module data numColors long ! number of colors used in the custom excel palette colorPalette long, dim(40) ! colors in the excel palette curColor long ! the current color in the excel palette palettePos long ! position of the current color in the palette code! Adds a color to the local and Excel palette AddPaletteColor procedure(long pColor) code if NumColors > 39 and ExcelDoc.GetOfficeVersion < 12 ! Limit colors for old versions ! can do error handling here, or choose which color entry to replace etc. return end numColors += 1 colorPalette[numColors] = pColor curColor = pColor palettePos = numColors ! add the color to the excel palette ExcelDoc.SetPaletteColor(numColors, pColor) ! This locates a passed color in the palette and returns the position GetPaletteColor procedure(long pColor) i long code loop i = 1 to 40 if colorPalette[i] = pColor curColor = colorPalette[i] palettePos = i return i end end return 0 |
Example 2 |
---|
! Let the user pick a color (RGB) if ColorDialog('Select a color', tempLong) ! Set InterpretClarionColorEquates to false and pass RGB colors, ! Not Clarion color equates. MyExcel.InterpretClarionColorEquates = false ! Set swatch 33 to this RGB color (column1, row5 in palette) MyExcel.SetPaletteColor (33, tempLong) ! Set cell B2 to the color in swatch 33, which we just set MyExcel.SetCellBackgroundColor (33, 'B2') end |
Example 3 |
---|
curColor2 =
MyExcel.GetPaletteColor(2) ! Fetch and
store the current color MyExcel.SetPaletteColor(2, color:red) ! Replace it with red (Clarion color equate) curColor3 = MyExcel.GetPaletteColor(3) MyExcel.InterpretClarionColorEquates = false MyExcel.SetPaletteColor(3, 0FF00CCh) ! Set to an RGB color value ! Set cell B2 to the color in swatch 3, which we just set MyExcel.SetCellBackgroundColor(3, 'B2') |
Example |
---|
MyExcel.SetRowHeight(5,8,'20.75')
MyExcel.SetRowHeight(9,,'20.75') |
Parameter | Description |
---|---|
long recordNumber | The record number being processed. |
excelImportQType cellsQ | A queue that contains the values of all cells (fields) in the current
row (record). The queue has the following structure:excelImportQType queue
cell string(_oit:LargeStringSize) end |
The _oit:LargeStringSize | equate defaults to 1024, which means that each cell may only contain up to 1024 characters. |
Example |
---|
MyExcel.ExcelImport('expenses.xls',
?Progress, 32) ! This will call the TakeImportRecord() method for each record, ! which allows the records to be processed (see below):MyExcel.TakeImportRecord Procedure(long recordNumber, excelImportQType cellsQ) ReturnValue long destField any sourceField any i long code loop = i = 1 to Records(cellsQ) sourceField &= What(cellsQ, i) if Who(MyFile.Record, i) <> '' ! If the field exists in the file assign to it. destField &= What(MyFile.Record, i) destField = sourceField if Access.MyFile.Insert() return level:fatal ! Error adding a record, cancel import end end end return level:benign ! continue importing ! Parent Call ReturnValue = parent.TakeImportRecord(recordNumber, cellsQ) ! [Priority 5000] ! End of "Class Method - Executable Code Section" Return ReturnValue |
Example |
---|
MyExcel.WriteToCell('Test') MyExcel.WriteToCell('Test', 'B3') |
This Example loops through a table and writes each row in the table to a row
in Excel. The example only writes the first two fields, but each additional
field is done in the same manner. currentRow long code MyExcel.NewWorkbook() currentRow = 1 Set(MyFile) loop until Access:MyFile.Next() MyExcel.WriteToCell(MyFile.Field1, clip(MyExcel.ColumnName(1)) & currentRow) MyExcel.WriteToCell(MyFile.Field2, clip(MyExcel.ColumnName(2)) & currentRow) MyExcel.WriteToCell(day(LC:LC_Date)&'.'&month(LC:LC_Date)&'.'&year(LC:LC_Date), clip(MyExcel.ColumnName(3)) & currentRow) !This will enter the date in the format that excel understands. currentRow += 1 end MyExcel.SaveAs(fileName) |
Example |
---|
MyExcel.WriteFormulaToCell('=SUM(A6:A12)') MyExcel.WriteFormulaToCell('=SUM(A6:A12)', 'B3') |
oiExcel Class Properties | |
---|---|
New Properties (also listed below) |
|
dontCloseOnKill | Leaves Excel open when the Kill method is called. |
oiExcel Propeties | |
dontCloseOnKill | |
interpretClarionColorEquates |
! Clean up the object and COM interface, but leave Excel open:
myExcel.dontCloseOnKill = 1
myExcel.Kill()
Example 1 |
---|
curColor long code ! Let the user pick a color (RGB) if ColorDialog('Select a color', curColor) MyExcel.SetPaletteColor(33, curColor) ! Set swatch 33 to this RGB color MyExcel.InterpretClarionColorEquates = false MyExcel.SetCellBackgroundColor(33, 'B2') end |
Example 2 |
---|
TempLong = 0FFFF00h ! Use an RGB color (yellow) MyExcel.SetPaletteColor(33, curColor) MyExcel.InterpretClarionColorEquates = false ! Set cell B2 to the color in swatch 33, which we just set MyExcel.SetCellBackgroundColor (33, 'B2') |
Equate: | |||
GetInfo? | Update? | Description (To Do) | |
oix:Left | |||
oix:Top | |||
oix:Width | |||
oix:WindowState | |||
oix:ApplicationVisible |
oiExcelImpEx Class Methods | |
---|---|
Save | Exports the data to the excel file. |
Load | Imports the data from an excel file into the data structure. |
ValidateRecord | Useful if you want to filter out records immediately before importing/exporting that record (during the import process). |
IgnoreField | Adds a field to the internal ignored queue, so that the particular data field is omitted from the exporting/import. |
ClearIgnored | Clear the internal IgnoreFields queue. |
IsIgnored | Check if a field is going to be ignored or not. |
MapFieldToColumn | Creates an entry in the ColMap internal queue to map a field to a particular column. |
PrimeRecord | This method primes the fields immediately prior to inserting the record. You can override field values here. |