コード例 #1
0
ファイル: test_vbproject.py プロジェクト: brotchie/excelbt
def test_vbproject(tmpdir):
    project = VBProject()

    m1 = Module('TestModule', 'Code')
    m2 = Module('ClassModule', 'Class Code')

    project.add_module(m1)
    project.add_module(m2)

    project.export(tmpdir.strpath)

    assert tmpdir.join('TestModule.bas').check()
    assert tmpdir.join('TestModule.bas').read() == 'Code'

    assert tmpdir.join('ClassModule.bas').check()
    assert tmpdir.join('ClassModule.bas').read() == 'Class Code'
コード例 #2
0
ファイル: helpers.py プロジェクト: brotchie/py2vba
def lift_vba_function(xl, workbook, ast, fname):
    assert fname in ast.function_namespace

    # Create a code stub that handles proxying of VBA return
    # value into Python.
    test_stub = _create_function_test_stub(ast.function_namespace[fname])
    ast.code.append(test_stub)

    project = VBProject()
    project.add_reference(*SCRIPTING_REFERENCE)
    export.add_procedural_module_to_vbproject(project, ast)
    for module in project.modules:
        print module.name
        print module.code

    import_vbproject(workbook, project)

    def lifted(*args):
        resultdict = Dispatch('Scripting.Dictionary')
        xl.Run(test_stub.name, resultdict, *args)
        return resultdict['ReturnValue']
    return lifted
コード例 #3
0
def test_import_vbproject(tmpdir, xl):
    m1 = Module('StandardModule', STANDARD_MODULE_CONTENTS)
    m2 = ClassModule('ClassModule', CLASS_MODULE_CONTENTS)
    project = VBProject([m1, m2])

    wb = xl.Workbooks.Add()
    components = import_vbproject(wb, project)

    assert components[0].Type == const.vbext_ct_StdModule
    assert components[0].Name == 'StandardModule'

    assert components[1].Type == const.vbext_ct_ClassModule
    assert components[1].Name == 'ClassModule'
コード例 #4
0
ファイル: helpers.py プロジェクト: shunya1016/py2vba
def lift_vba_function(xl, workbook, ast, fname):
    assert fname in ast.function_namespace

    # Create a code stub that handles proxying of VBA return
    # value into Python.
    test_stub = _create_function_test_stub(ast.function_namespace[fname])
    ast.code.append(test_stub)

    project = VBProject()
    project.add_reference(*SCRIPTING_REFERENCE)
    export.add_procedural_module_to_vbproject(project, ast)
    for module in project.modules:
        print module.name
        print module.code

    import_vbproject(workbook, project)

    def lifted(*args):
        resultdict = Dispatch('Scripting.Dictionary')
        xl.Run(test_stub.name, resultdict, *args)
        return resultdict['ReturnValue']

    return lifted