Jump to content

Expanding Column width


Recommended Posts

Hi everybody,

I'm a intermediary programmer and is evaluating AutoIt. As so far I do have great achievement with this language. But nevertheless I have one struggle point with AutoIt.

In VB (VBA and VBS) I could change the width of column in Excel, but I could figure out to do this with Auto It. I could use a combination of autoIT with vbs, but I like to avoid that practice.

Another program that I'm running, display result of database queries in grid window, like Excel. I try everything to change to column width of this program but with no success.

Therefore, if someone could help me with one of this options:

1 - Function that could help change the column width of running program

or

2 function to click on menu when right click the column header.

I will highly appreciate your input.

Edited by PpsSupport
Link to comment
Share on other sites

For no.1:

#include <Excel.au3>

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

For $i = 1 To 5 ;Loop
 _ExcelWriteCell($oExcel, $i, $i, 1) ;Write to the Cell Vertically using values 1 to 5
Next

ToolTip("Inserting Column(s) Soon...")
Sleep(3500) ;Pause to let user view action

_ExcelColumnInsert($oExcel, 1, 1) ;Insert 1 Column at column 1

$ColA = $oExcel.Columns("A");get the column 1
$ColA.ColumnWidth = 40; set width to 40 for the column 1

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

Another program that I'm running, display result of database queries in grid window, like Excel. I try everything to change to column width of this program but with no success.

Why another program if you can use AI to do it for you?

Adding to the example from taietel:

#include <Excel.au3>
#Include <Array.au3>
Local $oExcel = _ExcelBookNew() ;Create new book, make it visible
For $i = 1 To 5 ;Loop
 _ExcelWriteCell($oExcel, $i, $i, 1) ;Write to the Cell Vertically using values 1 to 5
Next
ToolTip("Inserting Column(s) Soon...")
Sleep(2500) ;Pause to let user view action
_ExcelColumnInsert($oExcel, 1, 1) ;Insert 1 Column at column 1
$ColA = $oExcel.Columns("A");get the column 1
$ColA.ColumnWidth = 40; set width to 40 for the column 1
MsgBox(0, "Exiting", "Press OK to Save File and Exit")
$aArray1 = _ExcelReadSheetToArray($oExcel)
_ArrayDisplay($aArray1, "Info in a Grid like Excel?")
_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
Link to comment
Share on other sites

  • 1 year later...

This thread is 2 years old, who are you supposed to be commenting to?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Sorry, being lazy here. Was looking through threads to find a way to resize columns in my script.

I used:

$ColA = $oExcel.Columns("A");get the column 1
$ColA.ColumnWidth = 40; set width to 40 for the column 1

but modified it for my excel and multiplied it for columns A thro P and it crashed my script :

So I'll give it up for now, got more important things to do. When I get a moment, I'll get back to making the sheets look nice :)

thanks

Sorry for the trouble Govner

Dan

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...