I've built budget.xlsx, but I haven't recalculated it. LibreOffice isn't installed here, so Excel will calculate the formulas when you open the file. The script that generates it is build_xlsx.py, in the same folder.
What's in it
- Inputs sheet: the assumptions are in yellow cells and labelled "Sample". They are monthly income 4,500, rent 1,400, food 600, transport 250, utilities 200 and a savings goal of 15%.
- Budget sheet:
- Categories: rent, food, transport and utilities. Each amount is a formula pointing at the Inputs sheet (for example
=Inputs!B5), and each has a "% of income" column. - Totals: a total spent row (
=SUM(B4:B7)), income, and the remaining amount (income minus total spent). - Savings check: it compares the remaining amount with income × savings goal %. It shows "On track - surplus of …" or "Short by …".
- Categories: rent, food, transport and utilities. Each amount is a formula pointing at the Inputs sheet (for example
- Chart: a bar chart of spending by category, titled as sample, next to the table.
What I checked
- I reopened the saved file and confirmed there are two sheets, one chart, and no hard-coded numbers on the Budget sheet. Every amount and total is a formula.
- I read each formula's cell references by hand and they point at the right inputs.
- Working it out by hand with the sample numbers, total spent is 2,450, remaining is 2,050, and the savings goal is 675. The check should therefore read "On track - surplus of 1,375.00".
Not checked
- No recalculation, so I haven't seen the computed values or confirmed the chart renders correctly.
- If a number looks off when you open it, tell me.
Your call: the savings goal isn't counted as a spending category. It's only compared against what's left over. I can add it as a category if you'd rather see it in the total and the chart.
Test run: a sample household budget built with openpyxl in a temporary folder. The run was allowed to write files and run python3 only. The formulas were inspected by re-opening the file and by hand calculation, but not recalculated, because LibreOffice was not installed. Excel calculates them on opening. All numbers are sample.
できること
ブックを作成または変更する Python スクリプトを書いて実行し、本物のスプレッドシートとして動くようにします。計算は、ラベル付きの入力シートや名前付き範囲を参照する数式にし、数式に埋め込んだ数字や貼り付けた値にはしません。見出しの書式、数値の書式、列幅、ウィンドウ枠の固定、入力規則、条件付き書式、グラフを設定します。既存ファイルの編集では、まずシート、数式、名前付き範囲を一覧にし、頼まれたセルだけを変え、保存時に openpyxl が失うことのあるもの(ピボットテーブル、スライサー、一部の書式)を警告し、別名で保存します。エラー値、文字列として保存された数字、数式に直書きされた数字、データに届いていない範囲の点検もできます。openpyxl は再計算できないため、数式を再計算したのか確認しただけなのかを伝えます。
出力
.xlsx ファイル、スクリプト、計算した点としていない点を示す確認レポート、確認が必要な前提。
こんな場面に
データから予算、管理表、レポート用のブックを作成・修正したいとき、エラーが出ている表をすばやく点検したいとき。
中リスク:指示のみのファイルで自前のスクリプトはありませんが、Python を書いて実行し、作業フォルダーにファイルを作り、仮想環境への openpyxl のインストールを勧めることがあります。元のファイルは上書きせず、マクロや外部リンクは作りません。一時フォルダーでサンプルの数字を使って一度試用し、数式とグラフ付きの2シートの予算表を作りました。数式は点検と手計算で確認しましたが、LibreOffice がなく再計算はしていません。Excel で開くと計算されます。財務や税務の判断の根拠にはしないでください。AIBars 制作(MIT)。