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

Comments

Projects
None yet
2 participants
@kmatt

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

This comment has been minimized.

kmatt commented Sep 26, 2014

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

@kmatt

This comment has been minimized.

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 fzumstein added this to the v0.2.3 milestone Sep 26, 2014

@fzumstein

This comment has been minimized.

Member

fzumstein commented Sep 26, 2014

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

@fzumstein fzumstein changed the title from Range() times out on Mac to Range().autofit() times out on Mac Oct 6, 2014

@fzumstein fzumstein changed the title from Range().autofit() times out on Mac to Mac: Range().autofit() times out Oct 14, 2014

@fzumstein

This comment has been minimized.

Member

fzumstein commented Oct 14, 2014

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