Sign in to follow this  
Followers 0
barrikid

Formatting cells in Excel

3 posts in this topic

#1 ·  Posted (edited)

I am currently trying to format some cells in Excel.

I found _ExcelNumberFormat(), but that seems to only be able to convert the cells to a number based format.

I want the cells to be formatted to Text.

#include <excel.au3>
#include <array.au3>

$oExcel = _ExcelBookNew()
_ExcelNumberFormat($oExcel, "@", 1, 1, 500)
If @error Then
    MsgBox(0, "err")
EndIf

$MyClip = ClipGet()

Send("^v")

Why? Copy and paste "4/4" into excel (without quotes). You will get 4-Apr instead of 4/4. If it is in the Text format, it will paste as 4/4

Is there a way to get it to format to Text?

Thanks,

BK

Edited by barrikid

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the forums!

When doing anything in Excel, recording macros is your best friend because it will essentially give you the code - you then just have to convert it to AutoIt's style of COM.

Here's an example of how to do what you want to do:

#include <Excel.au3>

$oExcel = _ExcelBookNew()
$oExcel.Range("A1").Select
$oExcel.Selection.NumberFormat = "@" ; To set a Text format
;~ $oExcel.Selection.NumberFormat = "0.00" ; To set a Number format

_ExcelWriteCell($oExcel, "4/4", "A1")

**Note that you need to set the cell format before you write to it, otherwise you end up with something different.

Edited by exodius

Share this post


Link to post
Share on other sites

Ah, thanks. I didn't realize that I got a reply till I solved it myself, heh.

Ill check out the macro recording though,

Thanks,

BK

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