Export Categories to .csv

Bryan Kaiser's Avatar

Bryan Kaiser

23 Jan, 2025 06:24 PM

I need to be able to export my categories to a .csv file. I have found online references that this is possible, but there is no explanation on how I can get this accomplished.

Your help would be appreciated.

Regards,

Bryan Kaiser

  1. 1 Posted by Stuart Beesley ... on 23 Jan, 2025 07:40 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    I couldn't find one.. Anyway to help you out, here is a quick way.

    Menu, Window, Developer console.

    Paste this code into the python snippet area

    from com.infinitekind.moneydance.model import *
    allAccounts = sorted(AccountUtil.allMatchesForSearch(moneydance_data, AcctFilter.ALL_ACCOUNTS_FILTER), key=lambda sort_x: (sort_x.getAccountType(), sort_x.getFullAccountName().upper()))
    print "-----"
    print "income/expense" + "," + "category name" + ","
    for cat in allAccounts:
     if not cat.getAccountType().isCategory(): continue
     print "%s" %(cat.getAccountType()) + "," + cat.getFullAccountName() + ","
    print "-----"
    
    then click "Run Snippet" (NOT run)

    In the console area below that you will get a csv dump. You can select this and copy/paste into a text editor or file..

    Let me know if this helps?

  2. 2 Posted by Bryan Kaiser on 24 Jan, 2025 04:31 PM

    Bryan Kaiser's Avatar

    Hey Stuart,
    Thanks for the help, but I get this error
    Error running snippet...: Traceback (most recent call last):
      File "<string>", line 2, in <module>
    NameError: name 'AccountUtil' is not defined
    Let me know if this a simple fix as I really appreciate the help.

    Regards,
    Bryan

        On Thursday, January 23, 2025 at 01:40:29 PM CST, Stuart Beesley (Mr Toolbox) <[email blocked]> wrote:
     
       
    |

  3. 3 Posted by Stuart Beesley ... on 24 Jan, 2025 05:32 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Sorry about that. It's a quirk of Mac that makes this work, whereas I suspect you're on Windows/Linux and for some reason it requires more class imports.. No matter.. Try this:

    from com.infinitekind.moneydance.model import AccountUtil, AcctFilter
    allAccounts = sorted(AccountUtil.allMatchesForSearch(moneydance_data, AcctFilter.ALL_ACCOUNTS_FILTER), key=lambda sort_x: (sort_x.getAccountType(), sort_x.getFullAccountName().upper()))
    print "-----"
    print "income/expense" + "," + "category name" + ","
    for cat in allAccounts:
     if not cat.getAccountType().isCategory(): continue
     print "%s" %(cat.getAccountType()) + "," + cat.getFullAccountName() + ","
    print "-----"
    
  4. 4 Posted by Stuart Beesley ... on 24 Jan, 2025 05:39 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    [sorry, copy/paste issue]

    from com.infinitekind.moneydance.model import AccountUtil, AcctFilter
    allAccounts = sorted(AccountUtil.allMatchesForSearch(moneydance_data, AcctFilter.ALL_ACCOUNTS_FILTER), key=lambda sort_x: (sort_x.getAccountType(), sort_x.getFullAccountName().upper()))
    print "-----"
    print "income/expense" + "," + "category name" + ","
    for cat in allAccounts:
     if not cat.getAccountType().isCategory(): continue
     print "%s" %(cat.getAccountType()) + "," + cat.getFullAccountName() + ","
    print "-----"
    
  5. 5 Posted by Stuart Beesley ... on 24 Jan, 2025 05:59 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    I made you a better one... Just edit line two with the path to the csv file you want to create (make sure the path is valid):

    # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #
    file_name = "/Users/xxx/Downloads/text.csv"
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
    
    import csv
    from com.infinitekind.moneydance.model import AccountUtil, AcctFilter
    from java.io import File
    
    
    
    countCats=0
    if True:
        # Ensure the file has a .csv extension
        if not file_name.endswith(".csv"):
            file_name += ".csv"
    
        allAccounts = sorted(AccountUtil.allMatchesForSearch(moneydance_data, AcctFilter.ALL_ACCOUNTS_FILTER), key=lambda sort_x: (sort_x.getAccountType(), sort_x.getFullAccountName().upper()))
        data=[]
        data.append(["income/expense","category name","status","tax related"])
        for cat in allAccounts:
            if not cat.getAccountType().isCategory(): continue
            countCats+=1
            data.append(["%s" %(cat.getAccountType()), cat.getFullAccountName(), "I" if cat.getAccountOrParentIsInactive() else "A", "TAX" if cat.isTaxRelated() else ""])
    
    
        # Write the data to the CSV file
        with open(file_name, "wb") as csv_file:
            writer = csv.writer(csv_file)
            writer.writerows(data)
        print "%s categories written to:" %(countCats), file_name
        moneydance.getPlatformHelper().openDirectory(File(file_name))
    else:
        print "Operation canceled!"
    
  6. 6 Posted by Bryan Kaiser on 24 Jan, 2025 06:27 PM

    Bryan Kaiser's Avatar

    Hey Stuart,
    Perfectamundo!!!
    Just what I needed and it worked like a champ. Thanks so much for your assistance.

        On Friday, January 24, 2025 at 11:59:49 AM CST, Stuart Beesley (Mr Toolbox) <[email blocked]> wrote:

    |

  7. 7 Posted by Stuart Beesley ... on 24 Jan, 2025 06:40 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    +1 👍 😀

  8. 8 Posted by dwg on 24 Jan, 2025 09:58 PM

    dwg's Avatar

    Stuart,

    Something to add to Toolbox perhaps?

    You could have Chart of Accounts extract options

  9. 9 Posted by Stuart Beesley ... on 24 Jan, 2025 10:08 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    Perhaps. Or perhaps extract_data.

  10. 10 Posted by dwg on 24 Jan, 2025 10:49 PM

    dwg's Avatar

    Good point.

    Extract data I think would be a better fit.

  11. 11 Posted by Stuart Beesley ... on 25 Jan, 2025 06:53 PM

    Stuart Beesley (Mr Toolbox)'s Avatar

    DONE. Added to extract_data.... Signed PREVIEW available here:

    https://github.com/yogi1967/MoneydancePythonScripts/raw/master/sign...

    @Bryan Kaiser - perhaps you could run it and confirm it works ok? Let me know?

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac