Jump to content

question about automating excel


Recommended Posts

Hello group,

I was trying to use Excel to open a tab delimited text file. The applicable method is Workbooks.OpenText and the syntax is:

OpenText(FileName, Origin, StartRow, DataType, TextQualifier, ConsecutiveDelimiter, Tab, Semicolon, Comma, Space, Other, OtherChar, FieldInfo, TextVisualLayout, DecimalSeparator, ThousandsSeparator, TrailingMinusNumbers, Local)

Where I'm having trouble is the argument for FieldInfo. In VBA, the argument is something like this: Array(Array(1, 2), Array(2, 2), Array(3, 2) ...). In each nested array, the first item is the column number (1 based), the second item (2) is for data type. Here 2 is for Text.

I tried something like this:

Dim $array[256][2]

Dim $i

For $i = 0 To 255

$array[$i][0] = $i+1

$array[$i][1] = 2

Next

and pass $array as the FieldInfo argument. Excel fails to open the text file, but no error was reported. Any ideas?

Thanks for your help.

wcc

Link to comment
Share on other sites

  • 5 months later...

Unfortunately, to my knowledge, it is not possible to pass arrays (let alone 2 dimensional arrays) via AutoIt to COM objects through method parameters.

The best solution I can think of is to omit the parameter or use the "Default" keyword to skip over it -- then format the appropriate columns after the import.

-S

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
Link to comment
Share on other sites

Unfortunately, to my knowledge, it is not possible to pass arrays (let alone 2 dimensional arrays) via AutoIt to COM objects through method parameters.

The best solution I can think of is to omit the parameter or use the "Default" keyword to skip over it -- then format the appropriate columns after the import.

-S

Have you tried? I'm pretty sure there's an AutoIt array to SAFEARRAY conversion that takes place.
Link to comment
Share on other sites

  • 5 months later...

Hi,

I had the same problem and here is how I solved that problem:

;This is the initial VB line for delimited text file

;Array(Array(0, 2), Array( _

;7, 2), Array(41, 2), Array(47, 2), Array(61, 1), Array(98, 1), Array(99, 1))

Here is the solution for AutoIt

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]

;----------------------------------------------------------------;

.workbooks.opentext($SetLeaf,$xlwindows,1,$xlFixedWidth,$xlTextQualifierNone,False,False,False,False,False,False,"",$ArrayComplet)

Hope it helps.

Link to comment
Share on other sites

  • 5 years later...

This thread is nearly 6 years old!

AutoIt has evolved during this time so the solutiong might be completely different.

Please open a new thread describing your problem. If necessary point to this thread.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...