Git Product home page Git Product logo

pyvba's Introduction

pyvba

PyPI - Python Version PyPI GitHub

The pyvba package was designed to gather data from VBA-based applications (e.g. Microsoft Excel, CATIA, etc.). It may also be used to assist programming VBA macro scripts using the Python language.

Getting Started

Install the Python Package:

pip install pyvba

To export data from a VBA program:

import pyvba

catia = pyvba.Browser("CATIA.Application")
active_document = catia.ActiveDocument

exporter = pyvba.XMLExport(active_document)
exporter.save("output", r"C:\Documents")

The current supported output types are XML and JSON formats. Both support a form the imitates the VBA object tree as well as a dictionary form where each unique object is in the outermost layer.

Example Output:

Note: BrowserObject denotes an object defined elsewhere in the output.

{ "MainBody": [
	{ "Pad": [
		{ "Shapes": [
			{ "DirectionOrientation": 0 },
			{ "DirectionType": 0 },
			{ "FirstLimit": "BrowserObject" },
			{ "IsSymmetric": false },
			{ "IsThin": false },
			{ "MergeEnd": false },
			{ "Name": "Pad.1" },
			{ "NeutralFiber": false },
			{ "SecondLimit": "BrowserObject" },
			{ "Sketch": "BrowserObject" }
		]},
		{ "Shapes": [
			{ "DirectionOrientation": 0 },
			{ "DirectionType": 0 },
			{ "FirstLimit": "BrowserObject" },
			{ "IsSymmetric": false },
			{ "IsThin": false },
			{ "MergeEnd": false },
			{ "Name": "Pad.1" },
			{ "NeutralFiber": false },
			{ "SecondLimit": "BrowserObject" },
			{ "Sketch": "BrowserObject" }
		]},
		{ "Shapes": [
			{ "DirectionOrientation": 0 },
			{ "DirectionType": 0 },
			{ "FirstLimit": "BrowserObject" },
			{ "IsSymmetric": false },
			{ "IsThin": false },
			{ "MergeEnd": false },
			{ "Name": "Pad.3" },
			{ "NeutralFiber": false },
			{ "SecondLimit": "BrowserObject" },
			{ "Sketch": "BrowserObject" }
		]}
	]}
]}

Developer Notes

This package is in beta. Therefore, there are still some problematic bugs and issues that cause errors in certain applications. Contributors are welcome! The project is hosted on GitHub. Report any issues at the issue tracker, but please check to see if the issue already exists!

pyvba's People

Contributors

wolfpackwilson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

vb6hobbyst7

pyvba's Issues

JSON illegal formatting with duplicates

The JSON exporter has no method of dealing with duplicate items. These typically come in the form of Function or Error due to the processing of these types. It may be worthwhile tossing them into an array from the git-go.

Kwargs documentation

The docstring documentation for the keyword arguments is severely lacking, especially since there are useful tools for them. Add information the user should know to the docstrings.

Add search, goto, and view_vba methods to Browser

The following methods could be useful in the future and may be worth implementing.

def search(self, name: str, exact: bool = False):
    """Return a dictionary in format {item: [paths]} matching the name.

    Search for all instances of a method or object containing a name.

    Parameters
    ----------
    exact: bool
        A flag that searches for exact matches.
    name: str
        The name of the attribute to search for.

    Returns
    -------
    dict
        The results of the search in format {item: [paths]}.
    """
    ...

def goto(self, path: list):
    """Retrieve an object at a given location.

    Parameters
    ----------
    path: list
        The steps to take to arrive to an object.

    Examples
    --------
    `goto(['Bodies','Item','HybridShapes','GetItem'])` yields the 'GetItem' function.

    """
    ...

def view_vba(self) -> str:
    """Returns a string that replicates the VBA tree."""
    ...

Create official package documentation

The only existent documentation that exists is docstrings within the package. Formal documentation would be beneficial for others. A documentation generator may be useful.

Testing automation using CI

The testing occurs client-side only. Create an action or CI to fix this. #6 must be resolved first to make this possible.

Excel mining memory error

When running the exporter on Microsoft Excel, the code hangs when reading "MergeArea", "EntireColumn" and a few others. The result is a memory error on the recursive function. This issue needs to be investigated further and handled.

Unit tests lack depth

Most of the test cases lack depth. Many edge cases aren't covered and many tests lack depth.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.