从AutoIT中获取文档中的行数

时间:2013-10-16 19:59:04

标签: excel autoit

如何让它自动确定能够设置脚本参数的行数(在excel文档中)?

#include <Excel Rewrite.au3>

Global $i = 1
Global $selector = '"of","restaurant","courtyard","licenced","landscapes","travel","specialist","testing","relay","imaging","environmental","associates"'
Global $sFormula = "=IF(OR(ISNUMBER(search("" ""&{" & $selector & "}&"" "","" ""&b" & $i & "&"" ""))),""YES"",""NO"")"

Global Const $xlCellTypeVisible = 12 ; All visible cells
Global $aData = $sFormula
Global $oExcel = _Excel_Open() ; Connect to Excel or open a new instance
Global $oWorkbook = _Excel_BookNew($oExcel) ; Create a new workbook

For $i = 0 To 100 step 1
Next

_Excel_RangeWrite($oWorkbook, Default, $aData, "A1:A100");
MsgBox(0, "RangeWrite Data", @error)
_Excel_FilterSet($oWorkbook, Default, $oWorkbook.Activesheet.UsedRange, 1, "NO") ; Only display even numbers
MsgBox(0, "FilterSet", @error)
Global $oRange = $oWorkbook.Activesheet.UsedRange.SpecialCells($xlCellTypeVisible) ; Only select visible rows
MsgBox(0, "Visible cells", @error)
$oRange.EntireRow.Delete ; delete visible rows

3 个答案:

答案 0 :(得分:0)

您的Do循环没有退出。

Do循环应以Until而不是end结束。

Do
    statements
    ...
Until <expression>

我相信您的while循环应该以{{1​​}}

结尾
WEnd

所有这些都是这样的:

While <expression>
    statements
    ...
WEnd

答案 1 :(得分:0)

我假设你想要这样的东西:

For $i = 0 To 100
    $sFormula = "...A" & $i ; example of adding an column number to a formula
    _ExcelWriteFormula($oExcel, $sFormula, $i, 2); 2 is for column B , 3 for C and so on.
Next

请在自动帮助文件中查看Excel功能的基本用法。

#include <Excel.au3>

Local $oExcel = _ExcelBookNew() ;Create new book, make it visible

For $i = 0 To 20 ;Loop
    _ExcelWriteCell($oExcel, $i, $i, 1) ;Write to the Cell
Next

_ExcelWriteFormula($oExcel, "=Average(R1C1:R20C1)", 1, 2) ;Uses R1C1 referencing

MsgBox(0, "Exiting", "Press OK to Save File and Exit")
_ExcelBookSaveAs($oExcel, @TempDir & "\Temp.xls", "xls", 0, 1) ; Now we save it into the temp directory; overwrite existing file if necessary
_ExcelBookClose($oExcel) ; And finally we close out

上次尝试

#include <Excel.au3>

Local $oExcel = _ExcelBookNew() ;Create new book, make it visible

$selector = '"of","restaurant","courtyard","licenced","landscapes","travel","specialist","testing","relay","imaging","environmental","associates"'


For $i = 0 To 100
    $sFormula = "=IF(OR(ISNUMBER(search("" ""&{" & $selector & "}&"" "","" ""&b" & $i & "&"" ""))),""YES"",""NO"")"
    _ExcelWriteFormula($oExcel, $sFormula, $i, 1); 2 is for column B , 3 for C and so on.
Next

答案 2 :(得分:0)

示例(不使用Excel.au3)

; Create new Excel file with one sheet 
Local $oExcel = ObjCreate("Excel.Application")
With $oExcel
    .SheetsInNewWorkbook = 1
    .Visible = 1
    .WorkBooks.Add
    .ActiveWorkbook.Worksheets(1).Name = "Foo"
    .ActiveWorkbook.Worksheets(1).Cells(1,1) = "IBICF !!!"
EndWith

; Write some data in sheet "Foo"
Local $array_1[5] = ["c1","c2","c3","c4","c5"]
Local $array_2[5] = ["val11","val12","val13","val14","val15"]
Local $array_3[5] = ["val21","val22","val23","val24","val25"]
Local $array_4[5] = ["val31","val32","val33","val34","val35"]
For $i = 0 To Ubound($array_1) - 1
    $oExcel.Activesheet.Cells(1,($i+1)).Value = $array_1[$i]
    $oExcel.Activesheet.Cells(2,($i+1)).Value = $array_2[$i]
    $oExcel.Activesheet.Cells(3,($i+1)).Value = $array_3[$i]
    $oExcel.Activesheet.Cells(4,($i+1)).Value = $array_4[$i]
Next

; Get the count number columns and rows use in this sheet
Local $number_cols = $oExcel.ActiveSheet.UsedRange.Columns.Count
Local $number_rows = $oExcel.ActiveSheet.UsedRange.Rows.Count

http://www.autoitscript.fr/forum/viewtopic.php?t=3272&f=11

的更多信息(法语)