gdemin/excel.link

xl.get.excel() creates workbook of it's own

Closed this issue · 2 comments

Using Excel 2013, I noticed xl.workbook.add() creates two separate books instead of one if excel is not already running when the function is called.

Specifically, when the function is called it executes ex = xl.get.excel(), which starts the excel process and opens "Book1" if excel is not running. If it is running, another workbook is created. Then when ex[['Workbooks']]$Add() executes it creates yet another workbook. The same behavior happens with xl.workbook.open() and also seems to be due to the xl.get.excel() function creating it's own workbook when executed, then the rest of the function appropriately opening the file you specify.

It's this line right here at the end of the xl.get.excel() function causing the duplication:

if (xls[['workbooks']][['count']] == 0) xls[['workbooks']]$add()

I could be wrong but in cases where we are calling workbook.add() or open() without excel running, this line isn't necessary as the rest of those functions will create the initial workbook.

Great package though, thanks!

Thank you for your feedback. I know about this behavior. I made it to avoid any initiation calls before transferring data. So one can write something like xl[a1] = 1 just after the package loading. But with xl.workbook.add it looks rather weird. I will try to fix this behavior with next release.

Fixed in 0.9.5.