This set of routines differs from Randallc's in a few important ways:
1. Instead of opening and closing the document for each call, my routines offer more flexibility. Basically, you call a function to open/create the workbooks, call others to write/read/format the workbook by active sheet, and call yet another to save/close out the workbook and terminate the object.
2. Each function is (or will be) written according to the UDF standards previously established by the community.
3. I will be creating different UDFs for different automation tasks in Excel for brevity's sake - namely, I'll be separating "common" functions from chart-related functions and other more specialized tasks. I'm thinking one UDF for worksheet-related tasks (the "common" set), one for charts, one for perhaps pivot tables, and others for maybe diagrams/drawing, lists, OLE, XML, and other not-as-common tasks. I suppose it depends on the size of finished UDFs, as yet undetermined. Right now I figure I'm about 90% complete on the common UDF, and about 30% complete on the chart UDF.
Suggestions, comments, contributions, and questions welcomed.
CHANGELOG
---------01/05/08---------- v1.4
--------New functions:
_ExcelAttach() - Attach to an already running instance of Excel (contributed by big_daddy)
_ExcelPrintRange() - Prints a range of cells in the active worksheet
_ExcelPrintSheet() - Prints the specified worksheet
_ExcelBookPropertiesGet() and _ExcelBookPropertiesSet(), get or set some important book properties
_ExcelCreateBorders() is back and better than before
_ExcelReadSheetToArray() - Read the contents of a sheet (in whole or part) into a 2d array (contributed by PsaltyDS)
_ExcelWriteSheetFromArray() - Write the contents of a 2d array into a worksheet (contributed by PsaltyDS)
--------Updated functions:
_ExcelBookOpen() supports read-only, document open/read password, and document write-protect password
_ExcelBookSaveAs() supports document open/read password, document read/write password, document sharing, and sharing conflict resolution
_ExcelFindInRange() fixed and improved RegExp
_ExcelSheetUsedRangeGet() fixed and improved RegExp
--------Bug fixes:
* Typos in _ExcelHyperlinkInsert()
* _ExcelWriteFormula() had some R1C1 reference issues
* When using Opt("MustDeclareVars",1) the _ExcelOpen* commands toss out an undeclared variable error for the $oExcel variable. Fixed (thanks, Blue Drache).
* In the description of _ExcelBookSaveAs, the syntax shows "_ExcelSaveDocAs." Fixed (thanks, ChrisJakarta).
* Some typos corrected and error checking added to _ExcelCellMerge()
---------11/30/06---------- v1.32
Bug fixed for _ExcelSheetUsedRangeGet()
---------11/30/06---------- v1.31
Fixed typos in _ExcelCellFormat()
---------11/24/06---------- v1.3
v1.3
Changed: Added more extensive error handling to _ExcelSheetMove(), and gave it the ability to place a sheet after another, as well as before
Changed: Fixed and cleaned up _ExcelWriteArray()
Changed: Added read-only flag to _ExcelBookOpen()
Fixed: _ExcelHyperlinkInsert(), was very buggy
Added: _ExcelFindInRange(), new function that returns addresses of all instances of a search string in a range as a 2 dimensional array
Added: _ExcelReplaceInRange(), new function that replaces target strings in a range with another string
Added: _ExcelSheetActivate(), to replace _ExcelSheetNumActivate() and _ExcelSheetNameActivate(); added extensive error handling
Added: _ExcelSheetDelete(), to replace _ExcelSheetNumDelete() and _ExcelSheetNameDelete(); added extensive error handling
Added: _ExcelSheetUsedRangeGet(), for finding the used range of a sheet, contributed by DaLiMan, revised by SEO
Added: _ExcelCellFormat(), for formatting a range of cells with parameters like wrapped text, text orientation, text indentation, etc.
Added: _ExcelCellMerge(), for merging (or unmerging) together all cells of a given range
Added: _ExcelReadArray(), for reading a number of cells straight into an array
Added: _ExcelInsert(), insert the clipboard data at a specified cell, shifting the existing contents left or down
Added: _ExcelBookOpenTxt(), for opening and parsing a text file as a worksheet
Removed: The functions that were depricated as of last release - _ExcelWriteCellA1(), _ExcelWriteCellR1C1(), _ExcelWriteFormulaA1(), _ExcelWriteFormulaR1C1(), _ExcelReadCellA1(), _ExcelReadCellR1C1(), _ExcelCopyA1(), _ExcelCopyR1C1(), _ExcelPasteA1(), _ExcelPasteR1C1(), _ExcelNumberFormatA1(), _ExcelNumberFormatR1C1(), _ExcelFontBold(), _ExcelFontItalic(), and _ExcelFontUnderline()
Removed: Headers for _ExcelSheetNumActivate(), _ExcelSheetNameActivate(), _ExcelSheetNumDelete() and _ExcelSheetNameDelete(); these functions will be removed entirely from the next release
Removed: _ExcelSheetUsedRowGet() and _ExcelSheetUsedColGet(), replaced by _ExcelSheetUsedRangeGet()
Things to be incorporated into next release:
Printing & document setup
Workbook & worksheet password/protection/encryption
Bordering will return, with better options
---------10/24/06----------
Update, v1.2
MAJOR UPDATE! Will most likely break existing scripts. Please update scripts accordingly.
Changed: All functions that accepted $sRange will now accept either A1 or R1C1 format. This means that all of these functions will have different parameters, and in most cases the order of the parameters will be different as well. Here's a list of changed functions, with new syntax:
_ExcelWriteCell($oExcel, $sValue, $sRangeOrRow, $iColumn = 1)
_ExcelWriteFormula($oExcel, $sFormula, $sRangeOrRow, $iColumn = 1)
_ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelCopy($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPaste($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelNumberFormat($oExcel, $sFormat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelHyperlinkInsert($oExcel, $sLinkText, $sAddress, $sRangeOrRow, $iColumn = 1)
_ExcelSort($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2)
_ExcelSortExtended($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2, $iHeader = 0, $fMatchCase = False, $iOrientation = 2, $iDataOption = 0)
_ExcelCommentAdd($oExcel, $sComment, $sRangeOrRow, $iColumn = 1, $fVisible = 0)
_ExcelCommentDelete($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelCommentShow($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fVisible = False)
_ExcelCommentRead($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelFontSetProperties($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fBold = False, $fItalic = False, $fUnderline = False)
_ExcelFontSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sFontName = "Arial")
_ExcelFontGet($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelFontSetSize($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iFontSize = 10)
_ExcelFontGetSize($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelFontSetColor($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelFontGetColor($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelCellColorSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelCellColorGet($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelHorizontalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sHorizAlign = "left")
_ExcelVerticalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sVertAlign = "bottom")
Changed: Several headers that had typos or were otherwise incorrect.
Changed: _ExcelColWidthSet($oExcel, $vColumn, $vWidth), _ExcelColWidthGet($oExcel, $vColumn), _ExcelRowHeightSet($oExcel, $vRow, $vHeight), _ExcelRowHeightGet($oExcel, $vRow) all now accept numbers as well as letters for column or row (A1 and R1C1 format)
Removed: All headers from functions that specify A1 or R1C1 addressing in their function names. The associated functions remain, but will be removed at next release. Here's the list of functions to be removed:
_ExcelWriteCellA1()
_ExcelWriteCellR1C1()
_ExcelWriteFormulaA1()
_ExcelWriteFormulaR1C1()
_ExcelReadCellA1()
_ExcelReadCellR1C1()
_ExcelCopyA1()
_ExcelCopyR1C1()
_ExcelPasteA1()
_ExcelPasteR1C1()
_ExcelNumberFormatA1()
_ExcelNumberFormatR1C1()
Removed: Headers for _ExcelFontBold(), _ExcelFontItalic(), and _ExcelFontUnderline(). These functions will be removed entirely from the next release.
Moved: _ExcelSortExtended() to working functions list, with thanks to DaLiMan
_ExcelSortExtended($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2, $iHeader = 0, $fMatchCase = False, $iOrientation = 2, $iDataOption = 0)
Added: _ExcelSheetUsedRowGet(), contributed by Stanley Lim, minor changes by SEO
Added: _ExcelSheetUsedColGet(), contributed by DaLiMan, based on _ExcelSheetUsedRowGet() by Stanely Lim, minor changes by SEO
Added: _ExcelFontSetProperties(), which replaces _ExcelFontBold(), _ExcelFontItalic(), and _ExcelFontUnderline()
---------10/13/06----------
Update, v1.11
Changed: _ExcelBookNew() has been drastically changed - please read its header!
Changed: _ExcelBookSaveAs() has had some important notes added to its header
Changed: Updated many comment headers
Fixed: Typos and bugs in _ExcelReadCellR1C1()
Added: _ExcelHyperlinkInsert() to working functions list
Added: Some functions to be written, _ExcelBookOpenTxt(), _ExcelCellFormat(), _ExcelCellMerge(), _ExcelPrintSheet(), _ExcelPrintRange(), _ExcelPrintSetup()
Added: Simple example file, ExcelCOM_UDF_Example01.au3
---------10/11/06----------
Update, v1.1
Updates: _ExcelPictureAdd(), _ExcelPictureAdjust(), _ExcelPictureScale(), _ExcelSheetNumActivate(), _ExcelSheetNameActivate(), _ExcelSheetNumDelete(), _ExcelSheetNameDelete(),
_ExcelCellColorSet(), _ExcelFontColorGet() all updated, tested, and added to working functions list.
Comments (help) updated for most functions.
Changed names of the following functions to match big_daddy's suggestion: _ExcelColumnInsert(), _ExcelColumnDelete(), _ExcelRowInsert(), _ExcelRowDelete(), ExcelHyperlinkInsert(), _ExcelFontSet(), _ExcelFontGet(), _ExcelFontSetSize(), _ExcelFontGetSize(), _ExcelFontSetColor(), ExcelFontGetColor(), _ExcelCellColorSet(), _ExcelCellColorGet(), ExcelHorizontalAlignSet(), _ExcelVerticalAlignSet(), _ExcelColWidthSet(), _ExcelColWidthGet(), _ExcelRowHeightSet(), _ExcelRowHeightGet(), _ExcelSheetMove(), _ExcelSheetAddNew(), _ExcelSheetNameGet(), _ExcelSheetNameSet(), _ExcelSheetNumActivate(), _ExcelSheetNameActivate(), _ExcelSheetNumDelete(), _ExcelSheetNameDelete(), _ExcelSheetList().
---------10/11/06----------
Update, v1.01
Updates: Changed function names for _Excel document add/save/new functions, removed _ExcelInit(), gave _ExcelBookOpen() and _ExcelBookNew() the ability to return object handle.
Additions: None
---------10/10/06----------
Initial release, v1.0
Updates: None
Additions: None
LIST OF WORKING FUNCTIONS (count = 68)
_ExcelBookNew($fVisible = 1)
_ExcelBookAttach($s_string, $s_mode = "FilePath")
_ExcelBookOpen($sFilePath, $fVisible = 1, $fReadOnly = False, $sPassword = "", $sWritePassword = "")
_ExcelBookOpenTxt($sFilePath, $sDelimiter = ",", $iStartRow = 1, $iDataType = 1, $iTextQualifier = 1, $fConsecDelim = False, $fVisible = 1)
_ExcelBookSave($oExcel, $fAlerts = 0)
_ExcelBookSaveAs($oExcel, $sFilePath, $sType = "xls", $fAlerts = 0, $fOverWrite = 0, $sPassword = "", $sWritePassword = "", $iAccessMode = 1, $iConflictResolution = 2)
_ExcelBookClose($oExcel, $fSave = 1, $fAlerts = 0)
_ExcelShow($oExcel)
_ExcelHide($oExcel)
_ExcelWriteCell($oExcel, $sValue, $sRangeOrRow, $iColumn = 1)
_ExcelWriteFormula($oExcel, $sFormula, $sRangeOrRow, $iColumn = 1)
_ExcelWriteArray($oExcel, $iStartRow, $iStartColumn, $aArray, $iDirection = 0, $iIndexBase = 0)
_ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelReadArray($oExcel, $iStartRow, $iStartColumn, $iNumCells, $iDirection = 0, $iIndexBase = 0)
_ExcelCopy($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPaste($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelInsert($oExcel, $sRangeOrRow, $iColumn = 1, $iShiftDirection = -4121)
_ExcelRowDelete($oExcel, $iRow, $iNumRows = 1)
_ExcelColumnDelete($oExcel, $iColumn, $iNumCols = 1)
_ExcelRowInsert($oExcel, $iRow, $iNumRows = 1)
_ExcelColumnInsert($oExcel, $iColumn, $iNumCols = 1)
_ExcelNumberFormat($oExcel, $sFormat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPictureInsert($oExcel, $sFilePath, $iLeft, $iTop, $iWidth, $iHeight, $fLinkToFile = False, $fSaveWithDoc = False)
_ExcelPictureAdjust($oPicture, $iHorizontal, $iVertical, $iRotation = 0)
_ExcelPictureScale($oPicture, $nScaleWidth = 1, $nScaleHeight = 1, $fScaleOrigWidth = True, $fScaleOrigHeight = True, $iScaleFrom = 0)
_ExcelCreateBorders($oExcel, $sBorderStyle, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iEdgeLeft = 1, $iEdgeTop = 1, $iEdgeBottom = 1, $iEdgeRight = 1, $iEdgeInsideV = 0, $iEdgeInsideH = 0)
_ExcelHyperlinkInsert($oExcel, $sLinkText, $sAddress, $sScreenTip, $sRangeOrRow, $iColumn = 1)
_ExcelSort($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2)
_ExcelSortExtended($oExcel, $sKey, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDirection = 2, $iHeader = 0, $fMatchCase = False, $iOrientation = 2, $iDataOption = 0)
_ExcelFindInRange($oExcel, $sFindWhat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDataType = 0, $iWholeOrPart = 2, $fMatchCase = False, $fMatchFormat = "")
_ExcelReplaceInRange($oExcel, $sFindWhat, $sReplaceWith, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iWholeOrPart = 2, $fMatchCase = False, $fMatchFormat = "", $fReplaceFormat = False)
_ExcelCommentAdd($oExcel, $sComment, $sRangeOrRow, $iColumn = 1, $fVisible = 0)
_ExcelCommentDelete($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelCommentShow($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fVisible = False)
_ExcelCommentRead($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelSplitWindow($oExcel, $iSplitRow, $iSplitColumn)
_ExcelFontSetProperties($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fBold = False, $fItalic = False, $fUnderline = False)
_ExcelFontSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sFontName = "Arial")
_ExcelFontGet($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelFontSetSize($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iFontSize = 10)
_ExcelFontGetSize($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelFontSetColor($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelFontGetColor($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelCellColorSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iColorIndex = 1, $hColor = 0x000000)
_ExcelCellColorGet($oExcel, $sRangeOrRow, $iColumn = 1)
_ExcelHorizontalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sHorizAlign = "left")
_ExcelVerticalAlignSet($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $sVertAlign = "bottom")
_ExcelColWidthSet($oExcel, $vColumn, $vWidth)
_ExcelColWidthGet($oExcel, $vColumn)
_ExcelRowHeightSet($oExcel, $iRow, $vHeight)
_ExcelRowHeightGet($oExcel, $iRow)
_ExcelSheetMove($oExcel, $vMoveSheet, $vRelativeSheet = 1, $fBefore = True)
_ExcelSheetAddNew($oExcel, $sName = "")
_ExcelSheetNameGet($oExcel)
_ExcelSheetNameSet($oExcel, $sSheetName)
_ExcelSheetActivate($oExcel, $vSheet)
_ExcelSheetDelete($oExcel, $vSheet, $fAlerts = False)
_ExcelSheetList($oExcel)
_ExcelSheetUsedRangeGet($oExcel, $vSheet)
_ExcelCellFormat($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $fWrapText = False, $iOrientation = 0, $fAddIndent = False, $iIndentLevel = 0, $fShrinkToFit = False)
_ExcelCellMerge($oExcel, $fDoMerge, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1)
_ExcelPrintRange($oExcel, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iCopies = 1, $sActivePrinter = "", $fPrintToFile = False, $fCollate = False, $sPrToFileName = "")
_ExcelPrintSheet($oExcel, $vSheet, $iCopies = 1, $sActivePrinter = "", $fPrintToFile = False, _
_ExcelBookPropertiesGet($oExcel)
_ExcelBookPropertiesSet($oExcel, $sAuthor = "", $sTitle = "", $sSubject = "")
_ExcelReadSheetToArray($oExcel, $iStartRow = 1, $iStartColumn = 1, $iRowCnt = 0, $iColCnt = 0)
_ExcelWriteSheetFromArray($oExcel, ByRef $aArray, $iStartRow = 1, $iStartColumn = 1, $iRowBase = 1, $iColBase = 1)
LIST OF FUNCTIONS IN NEED OF TESTING AND/OR FURTHER DEVELOPMENT (count = 0)
None at present.
Latest Version - v1.5 (07/18/2008)LIST OF FUNCTIONS TO BE WRITTEN (count = 0)
_ExcelPrintSetup() for more printing options
More options for shared workbooks
Bordering will be updated to be even more flexible
Excel.zip 66.42K
9999 downloadsNote: This thread is being maintained by litlmike while LocoDarwin is away
---
ExcelCOM_UDF.au3 (v1.4)
Attached examples:
ExcelCOM_UDF_Example01.au3 --- Basic usage (create book, populate cells, read cells, save, quit)
ExcelCOM_UDF_Example02.au3 --- Basic usage (create book, populate table, add formulas, save, quit)ExcelCOM_UDF.au3 138.3K 11732 downloads
ExcelCOM_UDF_Example01.au3 798bytes 8800 downloads
ExcelCOM_UDF_Example02.au3 2.29K 7118 downloads
Edited by big_daddy, 29 July 2008 - 02:00 PM.







