Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_ExcelBookClose() problems


  • Please log in to reply
4 replies to this topic

#1 ShawnW

ShawnW

    Prodigy

  • Active Members
  • PipPipPip
  • 187 posts

Posted 16 March 2010 - 06:31 PM

I have an application I wrote that has the option to export some results to an excel sheet. The problem is that even though I close the book, I cannot open the excel file until the script exits.

The order of excel function calls (in case it helps) are as follows.

$oExcel = _ExcelBookNew(0) _ExcelWriteSheetFromArray($oExcel,$user,1,1,0,1) _ExcelRowInsert($oExcel,1,1) ;several _ExcelWriteCell() calls adding column names $oExcel.ActiveSheet.Columns("A:M").AutoFit _ExcelBookSaveAs($oExcel, $filePath,"xls",0,1) _ExcelBookClose($oExcel)


Now it all looks good once I close the program and open the saved file. But I'd like to be able to open the file as soon as it is saved without closing the application.

Thanks
Shawn

Edited by ShawnW, 16 March 2010 - 06:31 PM.








#2 enaiman

enaiman

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,922 posts

Posted 16 March 2010 - 11:13 PM

I think you have an error somewhere; check your code again.
This works very well:

#include <excel.au3> $oExcel = _ExcelBookNew(0) _ExcelWriteCell($oExcel, "test 123", 1, 1) _ExcelBookSaveAs($oExcel, "c:\temp\test.xls") _ExcelBookClose($oExcel) $oExcel = _ExcelBookOpen("c:\temp\test.xls", 0) MsgBox(0, "Cell 1:1 content", _ExcelReadCell($oExcel, 1, 1)) _ExcelBookClose($oExcel)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)


#3 ShawnW

ShawnW

    Prodigy

  • Active Members
  • PipPipPip
  • 187 posts

Posted 17 March 2010 - 01:20 PM

Thanks for the reply, I realize now I wasn't completely clear. Yes opening the excel file again from within the program and reading it works, but I was talking about the physical file. For example try changing that code to this.

#include <excel.au3> $oExcel = _ExcelBookNew(0) _ExcelWriteCell($oExcel, "test 123", 1, 1) _ExcelBookSaveAs($oExcel, "c:\temp\test.xls") _ExcelBookClose($oExcel) MsgBox(0, "blah", "blah")


Now the file is closed before the MsgBox call, but try opening it from your computer before you close the MsgBox so the script is still running.

The odd thing is it does not look like a normal file lock error. Doesn't even open in read only mode, it just bugs up.

#4 picaxe

picaxe

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 475 posts

Posted 17 March 2010 - 01:40 PM

_ExcelBookClose does not release object $oExcel, AutoIt automatically releases objects on script exit but if you need the xls file to be accessible before the script exits, you must specifically delete the object.
#include <excel.au3> $oExcel = _ExcelBookNew(0) _ExcelWriteCell($oExcel, "test 123", 1, 1) _ExcelBookSaveAs($oExcel, "c:\temp\test.xls") _ExcelBookClose($oExcel) $oExcel = 0 ; delete object MsgBox(0, "blah", "blah")


#5 ShawnW

ShawnW

    Prodigy

  • Active Members
  • PipPipPip
  • 187 posts

Posted 17 March 2010 - 01:55 PM

_ExcelBookClose does not release object $oExcel, AutoIt automatically releases objects on script exit but if you need the xls file to be accessible before the script exits, you must specifically delete the object.

#include <excel.au3> $oExcel = _ExcelBookNew(0) _ExcelWriteCell($oExcel, "test 123", 1, 1) _ExcelBookSaveAs($oExcel, "c:\temp\test.xls") _ExcelBookClose($oExcel) $oExcel = 0 ; delete object MsgBox(0, "blah", "blah")

Nice! Just what I needed, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users