Jump to content

Array to Excel


Recommended Posts

What do you want to do with the array? I didn't find a statement refering to the arrays you defined.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The arrays are being called with the .OpenText object for Excel. They allow the worksheet columns to be imported as text values.

#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
$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)"
$book.ActiveWorkbook.SaveAs($tmpfile,20,Default,Default,False,False,1,2)
_ExcelBookClose($book,0)
$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
ProgressOn("Converting","","",1,1,18)
ProgressSet(25,"25 percent complete" & @CRLF & @CRLF & $file)
_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(0),$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
Link to comment
Share on other sites

Then please have a look at the_Excel_BookOpenText.au3 example script from my ExcelEX UDF. You can use function _Excel_BookOpenText with Autoit 3.3.8.1 if you like.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

×
×
  • Create New...