Sign in to follow this  
Followers 0
NickT

Array to Excel

23 posts in this topic

I believe it's time to consult the experts on what I am trying to do...I am trying to take a large text file and write it to an Excel spreadsheet. After 2 days of trial and error I finally got it to work. What I would like help with is on making it faster. In my opinion it is taking WAY too long to write these values to the worksheet.

SCRIPT:

test.au3

TEXT FILE:

aptsource.txt

Share this post


Link to post
Share on other sites



Didn't have a look at your script in detail. You could try my UDF (Attention! Alpha version!) and use the _Excel_RangeWrite function to write an array to a worksheet. Or use the _Excel_BookOpenText function to directly read the file into a sheet.

That's much faster!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Okay, I tried using the _Excel_BookOpenText function with no luck. I keep getting a failed object error on it.

Share this post


Link to post
Share on other sites

Can you post your code?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#include <Excel.au3>

#include <File.au3>

#include <String.au3>

#include <Array.au3>

Global $ext,$slnum = "-1"

Func write($book,$val,$row,$x,$y,$z)

$zVAL = _ExcelReadCell($book,$row - 1,3)

If _ExcelReadCell($book,$row,3) = $zVAL Then

_ExcelWriteCell($book,$slnum,$row,10)

Else

$slnum += 1

_ExcelWriteCell($book,$slnum,$row,10)

EndIf

_ExcelWriteCell($book,$x,$row,7)

_ExcelWriteCell($book,$y,$row,8)

_ExcelWriteCell($book,$z,$row,9)

If Number(Round(($row - 2) / $val * 100)) > "0" Then

$per = Round(($row - 2) / $val * 100)

ProgressSet($per,$per & " Percent complete")

EndIf

EndFunc

Func parse($file,$tmpfile,$book,$lcount)

ProgressOn("AptSource Conversion","","",1,1)

Local $line

If Not StringInStr(FileRead($file),"GOTO",1) Then

MsgBox(0,"ERROR",'This is not an "aptsource" file.')

ex($book,$tmpfile)

EndIf

_ExcelWriteCell($book,"in machine datum : xm=-zb ; ym=-xb ; zm=yb with rotation (0.223deg)",1,1)

_ExcelWriteCell($book,"Xc",2,1)

_ExcelWriteCell($book,"Yc",2,2)

_ExcelWriteCell($book,"Zc",2,3)

_ExcelWriteCell($book,"i",2,4)

_ExcelWriteCell($book,"j",2,5)

_ExcelWriteCell($book,"k",2,6)

_ExcelWriteCell($book,"x+i",2,7)

_ExcelWriteCell($book,"y+j",2,8)

_ExcelWriteCell($book,"z+k",2,9)

_ExcelWriteCell($book,"scan line " & @CRLF & "number",2,10)

_ExcelHorizontalAlignSet($book,1,1,1,1,"center")

$book.Range($book.Cells(1,1),$book.Cells(1,10)).MergeCells=True

$book.Columns.NumberFormat="@"

$read = StringReplace(FileRead($file),"GOTO","",0,1);_StringStripChr(FileRead($file),"GOTO/ ",8)

$read = StringReplace($read," ","",0,1)

$read = FileWrite($tmpfile,StringReplace($read,"/","",0,1))

For $i = 1 To $lcount

$read = FileReadLine($tmpfile,$i)

$read = _StringExplode($read,",")

$x = StringReplace($read[0] + $read[3],".",",")

$y = StringReplace($read[1] + $read[4],".",",")

$z = StringReplace($read[2] + $read[5],".",",")

$read = StringReplace(_ArrayToString($read),".",",")

$read = _StringExplode($read,"|")

_ExcelWriteArray($book, $i + 2, 1, $read)

write($book,$lcount,$i + 2,$x,$y,$z)

Next

$book.columns.autofit

$folder = FileSaveDialog("Save",@ScriptDir,"Excel (*.xlsx)",18)

$book.ActiveWorkbook.SaveAs($folder);,"","",False,False,1,2,False)

MsgBox(0,"",@error)

ex($book,$tmpfile)

EndFunc

Func lcount($file)

If $file = "" Then Exit

Local $line

_FileReadToArray($file,$line)

parse($file,_TempFile(),_ExcelBookNew(1),$line[0])

EndFunc

Func ex($book,$tmpfile)

ProgressOff()

_ExcelBookClose($book,0)

FileDelete($tmpfile)

EndFunc

lcount(FileOpenDialog("Open","","All(*.*)",3))

Edited by NickT

Share this post


Link to post
Share on other sites

Sorry, my bad.

I didn't mean the original code which you already posted in #1 but the code where _Excel_BookOpenText didn't work.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Apologies for taking so long, been busy. Here is my code with _Excel_BookOpenText not working.

#include <Excel.au3>
#include <File.au3>
#include <String.au3>
#include <Array.au3>

Global $ext,$slnum = "-1"

Func write($book,$val,$row,$x,$y,$z,$time)
Local $per,$min[1]
_ExcelWriteCell($book,$x,$row,7)
_ExcelWriteCell($book,$y,$row,8)
_ExcelWriteCell($book,$z,$row,9)
$zVAL = _ExcelReadCell($book,$row - 1,3)
If _ExcelReadCell($book,$row,3) = $zVAL Then
_ExcelWriteCell($book,$slnum,$row,10)
Else
$slnum += 1
_ExcelWriteCell($book,$slnum,$row,10)
EndIf
If Number(Round(($row - 2) / $val * 100)) > "0" Then
$per = Round(($row - 2) / $val * 100)
; ProgressSet($per,$per & " Percent complete" & @CRLF & @CRLF & Round(TimerDiff($time) / 1000))
EndIf
$dif = Round(TimerDiff($time) / 1000)
If $dif >= "60" Then
$min[0] = $dif / 60
If StringInStr($min[0],".") Then $min[0] = _StringBetween($min,"",".")
Else
$min[0] = 0
EndIf
$sec = $dif / 60
$sec = _StringBetween($sec,".","")
$sec = _StringInsert(_ArrayToString($sec),".",0)
$sec = Round($sec * 60)
ProgressSet($per,$per & " Percent complete" & @CRLF & @CRLF & "Time elapsed: " & $min[0] & " minutes and " & $sec & " seconds")
EndFunc

Func parse($file,$tmpfile,$book,$lcount)
$time = TimerInit()
ProgressOn("AptSource Conversion","","",1,1,18)
Local $line
If Not StringInStr(FileRead($file),"GOTO",1) Then
MsgBox(0,"ERROR",'This is not an "aptsource" file.')
ex($book,$tmpfile)
EndIf
_ExcelWriteCell($book,"in machine datum : xm=-zb ; ym=-xb ; zm=yb with rotation (0.223deg)",1,1)
_ExcelWriteCell($book,"Xc",2,1)
_ExcelWriteCell($book,"Yc",2,2)
_ExcelWriteCell($book,"Zc",2,3)
_ExcelWriteCell($book,"i",2,4)
_ExcelWriteCell($book,"j",2,5)
_ExcelWriteCell($book,"k",2,6)
_ExcelWriteCell($book,"x+i",2,7)
_ExcelWriteCell($book,"y+j",2,8)
_ExcelWriteCell($book,"z+k",2,9)
_ExcelWriteCell($book,"scan line " & @CRLF & "number",2,10)
_ExcelHorizontalAlignSet($book,1,1,1,1,"center")
$book.Range($book.Cells(1,1),$book.Cells(1,10)).MergeCells=True
$book.Columns.NumberFormat="@"
$read = StringReplace(FileRead($file),"GOTO","",0,1)
$read = StringReplace($read," ","",0,1)
$read = FileWrite($tmpfile,StringReplace($read,"/","",0,1))
_Excel_BookOpenText($book,$tmpfile,3,1,Default,Default,",",2,Default,Default,Default)
; For $i = 1 To $lcount
; $read = FileReadLine($tmpfile,$i)
; If @error Then
; MsgBox(0,"",$read & @CRLF & $i & @CRLF & $lcount)
; ExitLoop
; EndIf
; $read = _StringExplode($read,",")
; $x = StringReplace($read[0] + $read[3],".",",")
; $y = StringReplace($read[1] + $read[4],".",",")
; $z = StringReplace($read[2] + $read[5],".",",")
; $read = StringReplace(_ArrayToString($read),".",",")
; $read = _StringExplode($read,"|")
; _ExcelWriteArray($book, $i + 2, 1, $read)
; write($book,$lcount,$i + 2,$x,$y,$z,$time)
; Next
$book.columns.autofit
$folder = FileSaveDialog("Save",@ScriptDir,"Excel (*.xlsx)",18)
$book.ActiveWorkbook.SaveAs($folder)
ex($book,$tmpfile)
EndFunc

Func lcount($file)
If $file = "" Then Exit
Local $line
_FileReadToArray($file,$line)
parse($file,_TempFile(),_ExcelBookNew(0),$line[0])
EndFunc

Func ex($book,$tmpfile)
ProgressOff()
_ExcelBookClose($book,0)
FileDelete($tmpfile)
EndFunc

lcount(FileOpenDialog("Open","","All(*.*)",3))
Apologies for taking so long, been busy. Here is my code with _Excel_BookOpenText not working.

Share this post


Link to post
Share on other sites

You can't combine the Excel UDF that comes with AutoIt and my rewrite of the Excel UDF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I've tried it both ways, using your rewrite and $book.OpenText method.

-- Note that I have not only tried $book.OpenText but also $book.ActiveWorkbook.OpenText and $book.Workbooks.OpenText.

Share this post


Link to post
Share on other sites

If you run the _Excel_BookOpenText.au3 example of my rewritten Excel UDF. Does it work?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sweet! That works like I wanted it too! Is there any way to attach the "OpenText" book that is created to the previously created workbook instead of having two seperate books? I've looked around _ExcelBookAttach but it doesn't seem to be what I'm looking for. Of course I'm probably wrong.

Share this post


Link to post
Share on other sites

Not at the moment. The Excel method OpenText is only available for workbooks.

What should be possible is to copy the worksheet to another book.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I suppose what I could do is close the unused book and set my variable to the new book. Thank you for all of your help. It is greatly appreciated!

Share this post


Link to post
Share on other sites

I will test how to copy a worksheet from one workbook to another tomorrow.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

How to copy a worksheet from one workbook to another:

#include <Excel Rewrite.au3>
$oExcel = _Excel_Open()
$oBook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\_Excel1.xls")
$oSheet1 = $oBook1.Sheets(1)
$oBook2 = _Excel_BookOpen($oExcel, @ScriptDir & "\_Excel2.xls")
MsgBox(0, "", "Copying sheet1 of workbook1 before sheet1 of workbook2")
$oSheet1.Copy($oBook2.Sheets(1))
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I finally got the script to work. Thanks for your help. I have another question that pertains to the same script but this is more of a "want to know how" sort of deal. I'm wondering what makes this work:

dim $Array1[2]=[0,2]

dim $Array2[2]=[7,2]

dim $Array3[2]=[41,2]

dim $Array4[2]=[47,2]

dim $Array5[2]=[61,1]

dim $Array6[2]=[98,1]

dim $Array7[2]=[99,1]

dim $ArrayComplet[7]=[$Array1,$Array2,$Array3,$Array4,$Array5,$Array6,$Array7]

When I run _ArrayDisplay($ArrayComplet) I get 7 rows, 1 column, and no values. I use this in my script but I just want to know how this is working. This came from

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\..\..\Program Files (x86)\AutoIt3\Icons\au3.ico
#AutoIt3Wrapper_Outfile=AptSource_Converter.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include
#include
#include

Func parse($file,$tmpfile,$book,$lcount)
Dim $arr0[2] = [0,2]
Dim $arr1[2] = [1,2]
Dim $arr2[2] = [2,2]
Dim $arr3[2] = [3,2]
Dim $arr4[2] = [4,2]
Dim $arr5[2] = [5,2]
Dim $arr6[2] = [6,2]
Dim $arr7[2] = [7,2]
Dim $arr8[2] = [8,2]
Dim $arr9[2] = [9,2]
Dim $array[10] = [$arr0,$arr1,$arr2,$arr3,$arr4,$arr5,$arr6,$arr7,$arr8,$arr9]
$tmpfile2 = _TempFile()
If Not StringInStr(FileRead($file),"GOTO",1) Then
MsgBox(0,"ERROR",'This is not an "aptsource" file.')
ex($book,$tmpfile,$tmpfile2,"")
EndIf
ProgressOn("Converting","","",1,1,18)
$read = StringReplace(FileRead($file),"GOTO","",0,1)
$read = StringReplace($read," ","",0,1)
$read = FileWrite($tmpfile,StringReplace($read,"/","",0,1))
$book.Application.DisplayAlerts=0
$book.Workbooks.OpenText($tmpfile,Default,1,Default,1,False,False,False,True,False,False,"",$array, Default,Default,Default,True)
_ExcelWriteCell($book,0,1,10)
$book.Range($book.Cells(1,7),$book.Cells($lcount,9)).Formula="=A1:A" & $lcount & "+D1:D" & $lcount
$book.Range($book.Cells(2,10),$book.Cells($lcount,10)).Formula="=IF(C2=C1,J1,J1+1)"
MsgBox(0,"","")
$book.ActiveWorkbook.SaveAs($tmpfile,20,Default,Default,False,False,1,2)
_ExcelBookClose($book,0)
ProgressSet(25,"25 percent complete" & @CRLF & @CRLF & $file)
$read = StringReplace(FileRead($tmpfile),".",",")
FileWrite($tmpfile2,$read)
ProgressSet(50,"50 percent complete" & @CRLF & @CRLF & $file)
$book = _ExcelBookNew(0)
$book.Application.DisplayAlerts=0
$book.Application.ErrorCheckingOptions.NumberAsText=False
$book.Workbooks.OpenText($tmpfile2,Default,1,Default,1,False,True,False,False,False,False,"",$array, Default,Default,Default,True)
$book.ActiveSheet.Rows(1).Insert()
$book.ActiveSheet.Rows(1).Insert()
ProgressSet(75,"75 percent complete" & @CRLF & @CRLF & $file)
_ExcelWriteCell($book,"in machine datum : xm=-zb ; ym=-xb ; zm=yb with rotation (0.223deg)",1,1)
_ExcelWriteCell($book,"Xc",2,1)
_ExcelWriteCell($book,"Yc",2,2)
_ExcelWriteCell($book,"Zc",2,3)
_ExcelWriteCell($book,"i",2,4)
_ExcelWriteCell($book,"j",2,5)
_ExcelWriteCell($book,"k",2,6)
_ExcelWriteCell($book,"x+i",2,7)
_ExcelWriteCell($book,"y+j",2,8)
_ExcelWriteCell($book,"z+k",2,9)
_ExcelWriteCell($book,"scan line " & @CRLF & "number",2,10)
_ExcelHorizontalAlignSet($book,1,1,1,1,"center")
_ExcelHorizontalAlignSet($book,3,1,$lcount + 2,10,"right")
$book.Range($book.Cells(1,1),$book.Cells(1,10)).MergeCells=True
$book.Columns.AutoFit
ProgressSet(100,"100 percent complete" & @CRLF & @CRLF & $file)
$folder = FileSaveDialog("Save",@ScriptDir,"Excel (*.xlsx)",18)
ProgressOff()
If Not $folder Then ex($book,$tmpfile,$tmpfile2,"")
$book.ActiveWorkbook.SaveAs($folder,51,Default,Default,False,False,1,2)
ex($book,$tmpfile,$tmpfile2,$folder)
EndFunc

Func lcount($file)
If $file = "" Then Exit
Local $line
_FileReadToArray($file,$line)
For $i = UBound($line) - 1 To 0 Step -1
If $line[$i] = "" Then _ArrayDelete($line,$i)
Next
$line = UBound($line) - 1
parse($file,_TempFile(),_ExcelBookNew(1),$line)
EndFunc

Func ex($book,$tmpfile,$tmpfile2,$folder)
_ExcelBookClose($book,0)
Do
FileDelete($tmpfile)
FileDelete($tmpfile2)
Until Not FileExists($tmpfile) And Not FileExists($tmpfile2)
If Not $folder = "" Then MsgBox(0,"Conversion",'Apt Source conversion complete!!' & @CRLF & @CRLF & 'New file is located at: ' & $folder & ".xlsx")
Exit
EndFunc

lcount(FileOpenDialog("Open","","All(*.*)",3))
Edited by NickT

Share this post


Link to post
Share on other sites

Array in Array is not recommended. See the end of this page.

Function _ArrayDisplay doesn't know how to handle arrays in arrays.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Okay, that's understandable. Is there a way to do this without an array in an array?

Share this post


Link to post
Share on other sites

Use a two-dimensional array. Something like this:

#include <Array.au3>
Global $Array[7][2]=[[0,2],[7,2],[41,2],[47,2],[61,1],[98,1],[99,1]]
_ArrayDisplay($Array)

BTW: Don't use "DIM", use "Global"


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I tried that in my script but it doesn't work. I've also tried a 3-dimensional array as well.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • VeryGut
      By VeryGut
      I'm trying to insert the following formula in cell A2 using my script:
      =if(A1=""; "YES"; "NO")
      To my understanding, the line of code should be similar to this:
      _Excel_RangeWrite($MasterFile, Default, "=if(A1=""; "YES"; "NO")", "A2")
      However, it does not work, probably due to the multiple quotation marks that confuse the script :C
      How do I avoid this problem?
    • LoneWolf_2106
      By LoneWolf_2106
      Hi everybody,
      i have a question about Excel, i have to create several charts one below the other dynamically.
      I have thought to use:
       
      $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count  
      And then to use it in this way:
      $Graph_position = "=Test1!A"&$iRowCount+2&":K"&$iRowCount+24 But it doesn't work with charts.
      Does anyone have a suggestion?
       
    • LoneWolf_2106
      By LoneWolf_2106
      Hi all,
      i have an empty csv file, i have a non formatted text file.
      What do i want to do?
      I want to automate the process "get external data" in Excel, i want to import the data from the text file and basically create a csv file with a specific character encoding.
      Is it possible with AutoIT?
       
    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
    • RC86
      By RC86
      Afternoon!
      I have a requirement to return both a string and an array from a function so as a result I put them both into an array and returned that.  I can access them in their entirety after returning them but then I can't seem to access the array elements after this.  Should I be able to or is there a prettier way?
      #include <Array.au3> ;Memory info returned as a string and an array $memoryInfo = _getMemoryInfo() msgbox(0,"Memory Info",$memoryInfo[0]) _ArrayDisplay($memoryInfo[1],"Memory as an Array") Local $newArray[7] $memoryInfo[1] = $newArray msgbox(0,"Test element",$newArray[0]) _ArrayDisplay($newArray) Func _getMemoryInfo() Local $newArray[7] Local $array = MemGetStats() $newArray[0] = $array[0] ;% of memory in use $newArray[1] = Round($array[1]/1024 * 0.001,2) ;Total physical RAM $newArray[2] = Round($array[2]/1024 * 0.001,2) ;Availaible physical RAM $newArray[3] = Round($array[3]/1024 * 0.001,2) ;Total pagefile $newArray[4] = Round($array[4]/1024 * 0.001,2) ;Available pagefile $newArray[5] = Round($array[5]/1024 * 0.001,2) ;Total virtual $newArray[6] = Round($array[6]/1024 * 0.001,2) ;Available virtual $memoryUsage = $newArray[1] - $newarray[2] $pagefileUsage = $newArray[3] - $newarray[4] ;Output/Return Local $returnArray[2] $returnArray[0] = "Memory: " & $memoryUsage & " GB/" & $newArray[1] & " GB " & @CRLF & "Pagefile: " & $pagefileUsage & " GB/" & $newArray[3] & " GB " $returnArray[1] = $newArray return $returnArray EndFunc A bit messy but hopefully it's understandable what I'm trying to achieve.
      Thanks!