-1

如何让它自动确定行数(在 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
4

3 回答 3

0

你的Do循环没有出口。

Do循环应该以Untilnot结束end

Do
    statements
    ...
Until <expression>

我相信你的while循环应该以WEnd

While <expression>
    statements
    ...
WEnd

所有这些都是这样的:

Do
  Local $i, 100, step = 1
  if not ( $i and 100 and 1) then error() EndFunc

  While (100>0 and $i<=100) or (100<=0 and $i>=100 do
    _ExcelWriteFormula($oExcel, $sFormula, $sRangeOrRow, $iColumn = $i)
    $i = $i + 1
  WEnd
Until $i = 100 'What ever your condition is to exit the do loop
于 2013-10-16T21:20:25.520 回答
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

请在 Autoit 帮助文件中查看 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
于 2013-10-17T14:35:17.853 回答
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

于 2014-10-13T12:39:18.337 回答