Sign in to follow this  
Followers 0
Fraser

IniRead / _ExcelWriteCell issue

11 posts in this topic

#1 ·  Posted (edited)

Hello All,

I'm having an issue getting the column and row numbers, which have been read from a ini file, to work in the _ExcelWriteCell function.

I get this in the output of SciTE:

$oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value = $sValue

$oExcel.Activesheet.Cells($sRangeOrRow, $iColumn)^ ERROR

Could someone let me know where i'm going wrong please?

The .ini:

[TEST]
row=3
column=4

and the autoit code:

#include <Excel.au3>

Local $excel = @scriptdir & "test.xlsx"
Local $column = IniRead($ini, "TEST", "column", "NotFound")
Local $row = IniRead($ini, "TEST", "row", "NotFound")

$oExcel = _ExcelBookOpen($excel, 1)
_ExcelWriteCell($oExcel, $date, $row, $column)
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel)

exit

Any help will be greatly appreciated!

Thanks

Fraser

Edited by Fraser

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't have Excel here at home but if that is an exact copy of the code you are using I don't see where you set the $ini variable to the file location at. I also don't see where you are trapping the "Not Found" default setting in case it doesn't find the info you are wanting to read.

I did a quick test on the IniRead function and if the file I set $ini to doesn't exist, it doesn't give a file not found error, and assigns the default setting to the $row and $column. I would think that might cause the _ExcelWriteCell to error out since "Not Found" aren't valid cell locations.

Try setting $row and $column to 1's in your _ExcelWriteCell statement and see if you get the same error to make sure it works.

You can also use

Msgbox(0,"", $row & " - " & $column)
just before you open the Excel book to verify it is reading the ini correctly.

I won't be back at work until Wednesday so this is the best advice I have at the moment since I can't actually test the Excel parts now.

Edited by wyzzard

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Change this line from

Local $excel = @scriptdir & "test.xlsx"

to

Local $excel = @scriptdir & "test.xlsx"
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Bowmore might be on the right track... I'm always forgetting the slash in the file name when I'm using the file name constants myself too...

don't know how many times it's caused me issues :bonk:

Share this post


Link to post
Share on other sites

Hi,

Thank you both for the speedy reesponses!

I'm sorry that isn't a direct copy of the code, the location for the in is set to @scriptdir & "test.ini" and i've check and the xlsx file location is correct. My bad!! :doh:

I've changed the $row and $column varable to just $row = 3 and $column = 4 and it works fine, it seems like something wrong with the variable that is grabbed from the ini file!

Thanks

Fraser

Share this post


Link to post
Share on other sites

Modifying your above snippet with this and creating a ini file that was a copy/paste of your above example

#include <Excel.au3>

;Local $excel = @scriptdir & "test.xlsx"
Local $ini = @scriptdir & "\test.ini"
Local $column = IniRead($ini, "TEST", "column", "NotFound")
Local $row = IniRead($ini, "TEST", "row", "NotFound")

MsgBox(0,"",$row & " - " & $column)

;$oExcel = _ExcelBookOpen($excel, 1)
;_ExcelWriteCell($oExcel, $date, $row, $column)
;_ExcelBookSave($oExcel)
;_ExcelBookClose($oExcel)

exit

I was able to get the row and columns to display correctly in the msgbox.

Put the msgbox into your original code and see what it's assigning to them. That might help you narrow it down since you know it's not the ExcelWriteCell function now.

Share this post


Link to post
Share on other sites

Hi,

I've tryed that now and it seems to be ok, returns the correct values in the Msgbox, however when i try to use them in the ExcelWriteCell function it doesn't work!

I'm confused, mind you doesn't take much! :D

The script dies at the point of trying to locate the cell to write the data.

#include 

Local $excel = @scriptdir & "test.xlsx"
local $ini = @ScriptDir & "test.ini"
Local $column = IniRead($ini, "TEST", "column", "NotFound")
Local $row = IniRead($ini, "TEST", "row", "NotFound")
local $date = @MDAY & "/" & @MON & "/" & @YEAR

MsgBox(0, "TEST", "Row: " & $isa_row & @CRLF & "Column: " & $isa_column)

$oExcel = _ExcelBookOpen($excel, 1)
_ExcelWriteCell($oExcel, $date, $row, $column)
_ExcelBookSave($oExcel)
_ExcelBookClose($oExcel)

exit

Thanks

Fraser

Share this post


Link to post
Share on other sites

Well I can't help beyond this at the moment. Sorry

I use OpenOffice at home and so would have to wait until I get in to work to try the Excel parts out.

Share this post


Link to post
Share on other sites

Thank you for your help thus far!

Fraser

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Took me way too long to figure this out.. The function is apparently passing the value to excel as an string and excel doesn't like that. Try

_ExcelWriteCell($oExcel, $date, Int($row), Int($column))

edit - or

Local $column = Int(IniRead($ini, "TEST", "column", "NotFound"))
Local $row = Int(IniRead($ini, "TEST", "row", "NotFound"))
Edited by Danith

Share this post


Link to post
Share on other sites

Thank you very much! Worked a treat! :thumbsup:

Thanks

Fraser

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