Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Range().autofit() times out #74

Closed
kmatt opened this issue Sep 26, 2014 · 4 comments
Closed

Mac: Range().autofit() times out #74

kmatt opened this issue Sep 26, 2014 · 4 comments

Comments

@kmatt
Copy link

kmatt commented Sep 26, 2014

In attempting to auto fit a range of columns, Excel 2011 on Mac stops responding, and the Python call times out.

Could this be due to the block selection instead of a column selection?

.workbooks[1].active_sheet.cells['$A$1:$D$1048576'].rows.autofit()

IPython session:

from xlwings import Workbook, Sheet, Range, Chart
wb = Workbook()
Range('A1').value = [['Foo 1', 'Foo 2', 'Foo 3'], [10.0, 20.0, 30.0]]
Range('A1').autofit()  # this works
Range('A:D').autofit()  # Excel stops responding

---------------------------------------------------------------------------
CommandError                              Traceback (most recent call last)
<ipython-input-13-44bc97f3eefb> in <module>()
----> 1 Range('A:D').autofit()

//anaconda/lib/python2.7/site-packages/xlwings/main.pyc in autofit(self, axis)
    620
    621         """
--> 622         xlplatform.autofit(self, axis)
    623
    624     def __repr__(self):

//anaconda/lib/python2.7/site-packages/xlwings/_xlmac.pyc in autofit(range_, axis)
    274             range_.xl_range.columns.autofit()
    275         if not range_.is_column():
--> 276             range_.xl_range.rows.autofit()
    277
    278

//anaconda/lib/python2.7/site-packages/aeosa/appscript/reference.pyc in __call__(self, *args, **kargs)
    496                                                 return
    497                                         raise CommandError(self, (args, kargs), e, self.AS_appdata)
--> 498                         raise CommandError(self, (args, kargs), e, self.AS_appdata)
    499
    500         def AS_formatcommand(self, args):

CommandError: Command failed:
        OSERROR: -1712
        MESSAGE: Apple event timed out.
        COMMAND: app(u'/Applications/Microsoft Office 2011/Microsoft Excel.app').workbooks[1].active_sheet.cells['$A$1:$D$1048576'].rows.autofit()

@kmatt
Copy link
Author

kmatt commented Sep 26, 2014

It becomes necessary to force close Excel in this case, or the Python interpreter does not exit.

@kmatt
Copy link
Author

kmatt commented Sep 26, 2014

Specifying columns or rows seems to work fine, perhaps a safety is needed to avoid autofitting a very large block of cells, or require columns or rows to be specified, as in the menu commands?

Range('A:D').autofit('columns')

@fzumstein
Copy link
Member

Good catch, thanks! This is really just a problem on Mac, Windows works fine...

@fzumstein fzumstein changed the title Range() times out on Mac Range().autofit() times out on Mac Oct 6, 2014
@fzumstein fzumstein changed the title Range().autofit() times out on Mac Mac: Range().autofit() times out Oct 14, 2014
@fzumstein
Copy link
Member

The problem is a wrong specification of the appscript command, needs to work like this and not through the range object:

app('Microsoft Excel').workbooks['workbook1'].active_sheet.rows['1:1048576'].autofit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants