Autoitのユーザー関数( Excel.au3) でExcelを操作する

ExcelをAutoitで操作

Excel.au3はExcelをAutoitから動かすためのUDF(ユーザーが作った関数)です。進化してるので、関数なくなり、新しいものに置き換わってるようです。

AutoitはBasic言語に似た文法で、いろいろなものを自動化することができます。画像認識もできます。

ダウンロード先:  AutoIt – AutoIt

勉強中のサイト(Autoitでグラフを使う):

ルーレット当たり外れなどをExcelに記入してます:

Excel UDFのダウンロード先:

サンプルがうまく動かないので、何故か調べていたら「Excel.au3」が更新されているので使えない関数・新しくなったものといろいろ変更されているようです。

Autoitのサイトのサンプルが正しいとは限りません。動かないときはいろいろ調べてみましょう。

英語の新旧・比較サイト:

Excel.au3 大きな変更点

古いバージョン新しいバージョン
_ExcelRowDelete_Excel_RangeDelete
    $iRowChanged to $vRange range object.
_ExcelRowInsert_Excel_RangeInsert行の挿入
 _ExcelWriteCell_Excel_RangeWriteChanged parameters so specific sheets can be addressed.
_ExcelSheetActivate廃止
_ExcelSheetNameGet廃止

_ExcelRowInsert => _Excel_RangeInsert (行の挿入)

一行目の間違いを直しました

例)3行目に一行追加

#include <Excel.au3>
Local $oExcel = _Excel_Open()
Local $oWork = _Excel_BookNew($oExcel) ;// _

$oExcel.Cells(1,1).value = 123
$oExcel.Cells(2,1).value = 222
$oExcel.Cells(3,1).value = 333

_Excel_RangeInsert($oWork.Activesheet,"3:3") ;// 3行目に一行 <<<
;開始行:終わりの行
一行追加
_Excel_RangeInsert($oWork.Activesheet,"3:4")   ; "3:4"に変えれば 3行目と4行目追加
2行追加

_ExcelWriteCell > _Excel_RangeWrite パラメータが変更に

#include <Excel.au3>
_Excel_RangeWrite ( $oWorkbook, $vWorksheet, $vValue [, $vRange = "A1" [, $bValue = True [, $bForceFunc = False]]] )

ワークシートの指定ができるようになったようです。この関数はセルに値書き込みます。

_Excel_RangeWrite ( $oWork,"sheet1" , 999 , "C1")
cellに書き込み

UDF関数一覧

_Excel_BookAttachAttaches to the first instance of a workbook where the search string matches based on the selected mode
_Excel_BookCloseワークブックを閉じる
_Excel_BookListReturns a list of workbooks of a specified or all Excel instances
_Excel_BookNew新しいワークブックを作成
_Excel_BookOpenOpens an existing workbook
_Excel_BookOpenTextOpens a text file and parses the content to a new workbook with a single sheet
_Excel_BookSaveSaves the specified workbook
_Excel_BookSaveAsSaves the specified workbook with a new filename and/or type
_Excel_CloseCloses all worksheets and the instance of the Excel application
_Excel_ColumnToLetterConverts the column number to letter(s)
_Excel_ColumnToNumberConverts the column letter(s) to a number
_Excel_ConvertFormulaConverts cell references in a formula between A1 and R1C1 reference styles, relative and absolute reference type, or both
_Excel_ExportExports a workbook, worksheet, chart or range as PDF or XPS
_Excel_FilterGetReturns a list of set filters
_Excel_FilterSetSets/unsets filter definitions and filters the range
_Excel_OpenConnects to an existing Excel instance or creates a new one
_Excel_PictureAddAdds a picture on the specified workbook and worksheet
_Excel_PrintPrints a workbook, worksheet, chart or range
_Excel_RangeCopyPasteCuts or copies one or multiple cells, rows or columns to a range or from/to the clipboard
_Excel_RangeDeleteDeletes one or multiple cells, rows or columns from the specified worksheet
_Excel_RangeFindFinds matching cells in a range or workbook and returns an array with information about the found cells
_Excel_RangeInsertInserts one or multiple empty cells, rows or columns into the specified worksheet
_Excel_RangeLinkAddRemoveAdds or removes a hyperlink to/from a specified range
_Excel_RangeReadReads the value, formula or displayed text from a cell or range of cells of the specified workbook and worksheet
_Excel_RangeReplaceFinds and replaces matching strings in a range or worksheet
_Excel_RangeSortセルをソート
_Excel_RangeValidateAdds data validation to the specified range
_Excel_RangeWriteWrites value(s) or formula(s) to a cell or a cell range on the specified workbook and worksheet
_Excel_SheetAddAdds new sheet(s) to a workbook and sets their names
_Excel_SheetCopyMoveCopies or moves the specified sheet before or after a specified sheet in the same or a different workbook
_Excel_SheetDeleteDeletes the specified sheet by object, string name or by number
_Excel_SheetListReturns a list of all sheets in the specified workbook

コメント

タイトルとURLをコピーしました