Skip to content

Commit

Permalink
added Application.calculate(), closes #207
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Jul 12, 2015
1 parent 2b24043 commit b5a00ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 5 additions & 1 deletion xlwings/_xlmac.py
Expand Up @@ -465,4 +465,8 @@ def get_calculation(xl_app):

def set_calculation(xl_app, value):
calculation_reverse = dict(zip(calculation.values(), calculation.keys()))
xl_app.calculation.set(calculation_reverse[value])
xl_app.calculation.set(calculation_reverse[value])


def calculate(xl_app):
xl_app.calculate()
6 changes: 5 additions & 1 deletion xlwings/_xlwindows.py
Expand Up @@ -498,4 +498,8 @@ def get_calculation(xl_app):


def set_calculation(xl_app, value):
xl_app.Calculation = value
xl_app.Calculation = value


def calculate(xl_app):
xl_app.Calculate()
3 changes: 3 additions & 0 deletions xlwings/main.py
Expand Up @@ -91,6 +91,9 @@ def calculation(self):
def calculation(self, value):
xlplatform.set_calculation(self.xl_app, value)

def calculate(self):
xlplatform.calculate(self.xl_app)


class Workbook(object):
"""
Expand Down
10 changes: 7 additions & 3 deletions xlwings/tests/test_xlwings.py
Expand Up @@ -110,11 +110,15 @@ def test_screen_updating(self):
def test_calculation(self):
Range('A1').value = 2
Range('B1').formula = '=A1 * 2'
Application(wkb=self.wb).calculation = Calculation.xlCalculationManual
Range('A1').value = 4

app = Application(wkb=self.wb)

app.calculation = Calculation.xlCalculationManual
Range('A1').value = 4
assert_equal(Range('B1').value, 4)
Application(wkb=self.wb).calculation = Calculation.xlCalculationAutomatic

app.calculation = Calculation.xlCalculationAutomatic
app.calculate() # This is needed on Mac Excel 2016 but not on Mac Excel 2011 (changed behaviour)
assert_equal(Range('B1').value, 8)

class TestWorkbook:
Expand Down

0 comments on commit b5a00ca

Please sign in to comment.