# Ledger 转 Beancount 转换器

粘贴一个 Ledger 或 hledger 的账本文件，即可获得可运行的 Beancount。两者格式非常接近，这使得手动转换存在风险——任何无法映射的内容都会附带行号报告出来，而不会默默丢弃。

一切都在你的浏览器中运行。你的账本文件绝不会上传到任何地方。

[打开转换器](https://beancount.io/zh/tools/ledger-to-beancount#converter)

## Beancount 输出

粘贴账本文件后，转换后的内容会立刻显示在这里。

## 关于此工具的常见问题

**我的账本文件会上传到任何地方吗？**

不会。转换完全在你的浏览器中用此页面的 JavaScript 进行——你的账本文件绝不会发送给 beancount.io 或其他人，也不会被存储。你可以断开网络连接后继续转换来验证：它仍然可以工作。

**Ledger 和 Beancount 之间实际有哪些区别？**

实际上有三个地方容易出问题。账户名称：Ledger 允许空格和小写，Beancount 要求以五个根之一开头，后跟大写且无空格的分段——所以 'expenses:home:rent' 变成 'Expenses:Home:Rent'。金额：Beancount 总是先写数字再写商品，所以 '$84.23' 变成 '84.23 USD'。还有，账户在 Beancount 中必须先开户才能使用，而 Ledger 从不要求。这个工具处理了所有这三个问题，并告诉你每个重命名的账户。

**哪些内容无法转换？**

虚拟分录——即括号或方括号中的内容——在 Beancount 中没有对应项，因为 Beancount 要求每笔交易平衡。自动交易（'='）和周期性交易（'\~'）同样没有直接对应项。包含的文件必须首先被内联，因为转换器只看到你粘贴的内容。这些内容都会在输出中被注释掉，并附带行号列出，因此不会无声无息地消失。

**如何检查结果是否正确？**

对输出运行 bean-check——'uvx --from beancount bean-check main.bean' 无需永久安装即可工作。它会捕获不平衡的交易、未开户的账户和语法问题。然后比较 Balances 报告与 Ledger 的同一报告：如果总数一致，说明转换完整地保留了你的历史记录。

## 文件已转换。现在永久保存它。

Beancount.io 托管你的纯文本账本，提供银行同步、报告和移动应用——并且文件始终属于你，可随时下载。

[免费开始→](https://beancount.io/sign-up/?next=%2Fledger%2F) [查看 Beancount 与 hledger 的对比](https://beancount.io/zh/compare/beancount-vs-hledger)

## Where to look next

- [Sitemap](https://beancount.io/sitemap.xml) - all pages with hreflang alternates
- [LLMs index](https://beancount.io/llms.txt) - curated links for AI agents (also /llms-full.txt for full docs)
- [Documentation](https://beancount.io/docs) - every doc is also available as text/markdown via .md suffix or Accept negotiation
- [REST API reference](https://beancount.io/docs/api-reference) - interactive endpoints, schemas, authentication, and code samples
- [OpenAPI spec](https://beancount.io/openapi.json) - OpenAPI 3.1 spec for this website's public content endpoints; the product contract for ledger operations is at https://beancount.io/api-gateway/v1/openapi.json
- [GraphQL](https://beancount.io/graphql) - public, read-only content API over the blog and research logs (no credentials, no ledger data): 12 query fields over 23 types
- [MCP server](https://beancount.io/mcp) - Model Context Protocol at https://beancount.io/api-gateway/mcp
