Example #1
0
    def test_mock_caller(self):
        _skip_if_not_default_xl()

        Workbook.set_mock_caller(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_workbook_1.xlsx'))
        wb = Workbook.caller()
        Range('A1', wkb=wb).value = 333
        assert_equal(Range('A1', wkb=wb).value, 333)
Example #2
0
    def test_mock_caller(self):
        # Can't really run this one with app_visible=False
        _skip_if_not_default_xl()

        Workbook.set_mock_caller(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_workbook_1.xlsx'))
        wb = Workbook.caller()
        Range('A1', wkb=wb).value = 333
        assert_equal(Range('A1', wkb=wb).value, 333)
Example #3
0
    def test_mock_caller(self):
        _skip_if_not_default_xl()

        Workbook.set_mock_caller(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         'test_workbook_1.xlsx'))
        wb = Workbook.caller()
        Range('A1', wkb=wb).value = 333
        assert_equal(Range('A1', wkb=wb).value, 333)
Example #4
0
    # Set initial values
    price[0, :] = starting_price
    percentiles[0, :] = starting_price

    # Simulation at each time step
    for t in range(1, num_timesteps + 1):
        rand_nums = np.random.randn(num_simulations)
        price[t, :] = price[t - 1, :] * np.exp((mu - 0.5 * vol**2) * dt +
                                               vol * rand_nums * np.sqrt(dt))
        percentiles[t, :] = np.percentile(price[t, :], perc_selection)
        if animate:
            Range((t + 2, 16)).value = percentiles[t, :]
            Range((t + 2, 19)).value = price[t, 0]  # Sample path
            if sys.platform.startswith('win'):
                wb.application.screen_updating = True

    if not animate:
        Range('P2').value = percentiles
        Range('S2').value = price[:, :1]  # Sample path


if __name__ == '__main__':
    if not hasattr(sys, 'frozen'):
        # The next two lines are here to run the example from Python
        # Ignore them when called in the frozen/standalone version
        path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'simulation.xlsm'))
        Workbook.set_mock_caller(path)
    main()
Example #5
0
        a, b = b, a + b
    return result


def xl_fibonacci():
    """
    This is a wrapper around fibonacci() to handle all the Excel stuff
    """
    # Create a reference to the calling Excel Workbook
    wb = Workbook.caller()

    # Get the input from Excel and turn into integer
    n = int(Range('B1').value)

    # Call the main function
    seq = fibonacci(n)

    # Clear output
    Range('C1').vertical.clear_contents()

    # Return the output to Excel
    # zip() is used to push a list over in column orientation (list() needed on PY3)
    Range('C1').value = list(zip(seq))

if __name__ == "__main__":
    if not hasattr(sys, 'frozen'):
        # The next two lines are here to run the example from Python
        # Ignore them when called in the frozen/standalone version
        path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'fibonacci.xlsm'))
        Workbook.set_mock_caller(path)
    xl_fibonacci()
Example #6
0
import xlwings

from xlwings import Workbook, Sheet, Range, Chart


if __name__ == '__main__':
	Workbook.set_mock_caller("C:\\Users\\Mike\\Desktop\\excel\\python\\use_battery.xlsm")

wb = Workbook.caller()
# wb = Workbook()  # Creates a connection with a new workbook

total = Range('D2').value
print total
vals = Range('A2:C2').value 
Range('A2:C2').value = [v/total for v in vals]

# from xlwings import Workbook
# Workbook.open_template()