# Rolling cash-flow forecast

Calculate opening cash, monthly net flow and closing cash in a six-month Excel forecast, with editable inputs and visible planning formulas.

Excel · C# walkthrough

See how monthly receipts and payments affect the cash available in the next period.

[Build this report](#example-code)[Download XLSX](/downloads/showcase/workflows/excel-cash-flow-forecast/example.xlsx) [Try this file in your browser](/browser/excel-to-pdf/)

Opens the generated download in a local browser tool. The C# example below creates the document.

**Start with**

Opening cash, receipts and payments

**Generate**

XLSX

[!\[Generated Excel example: Rolling cash-flow forecast\](/downloads/showcase/workflows/excel-cash-flow-forecast/preview.webp)](/downloads/showcase/workflows/excel-cash-flow-forecast/preview.png)

Generated worksheet · Generated by the example below

## How it works

1. ### Enter cash assumptions
  
  Keep editable receipts and payments visible.
2. ### Roll balances forward
  
  Link each opening balance to the previous closing balance.
3. ### Inspect calculations
  
  Calculate cached values and validate formula support before exporting a range preview.

## The C# source

The example below shows the document API and layout used for this report. Follow the Excel guide for package setup in your own project.

```csharp
using OfficeIMO.Drawing;
using OfficeIMO.Excel;

namespace OfficeIMO.Examples.Showcase.Workflows {
    /// <summary>Creates an editable cash-flow forecast with visible calculations and a native range preview.</summary>
    internal static class CashFlowForecast {
        internal static void Create(string folder) {
            using var document = ExcelDocument.Create(Path.Combine(folder, "example.xlsx"));
            var sheet = document.AddSheet("Cash flow");
            sheet.SetColumnWidth(1, ExcelColumnWidth.Characters(29));
            for (int column = 2; column <= 6; column++) sheet.SetColumnWidth(column, ExcelColumnWidth.Characters(22));
            sheet.Range("A1:F1").Merge(); sheet.Cell(1, 1).SetValue("Cash-flow forecast");
            sheet.Cell(1, 1).SetFontSize(global::OfficeIMO.OfficeLength.Points(22)); sheet.Cell(1, 1).SetBold(true); sheet.Cell(1, 1).SetColor(OfficeColor.Parse("17365D"));
            sheet.Range("A2:F2").Merge(); sheet.Cell(2, 1).SetValue("Six-month illustrative forecast / amounts in EUR");
            string[] headers = { "Month", "Opening", "Receipts", "Payments", "Net flow", "Closing" };
            for (int column = 1; column <= 6; column++) sheet.Cell(4, column).SetValue(headers[column - 1]);
            double[] receipts = { 24000, 26000, 22000, 29000, 27000, 31000 };
            double[] payments = { 21000, 28000, 25000, 24000, 26000, 27000 };
            for (int index = 0; index < 6; index++) {
                int row = index + 5;
                sheet.Cell(row, 1).SetValue(new[] { "January", "February", "March", "April", "May", "June" }[index]);
                if (index == 0) sheet.Cell(row, 2).SetValue(18000); else sheet.Cell(row, 2).SetFormula($"F{row - 1}");
                sheet.Cell(row, 3).SetValue(receipts[index]); sheet.Cell(row, 4).SetValue(payments[index]);
                sheet.Cell(row, 5).SetFormula($"C{row}-D{row}");
                sheet.Cell(row, 6).SetFormula($"B{row}+E{row}");
                for (int column = 2; column <= 6; column++) sheet.Cell(row, column).SetNumberFormat("#,##0");
            }
            sheet.AddTable("A4:F10", true, "CashForecast", ExcelTableStyle.TableStyleMedium2);
            sheet.Range("C5:D10").Validation().WholeNumber(ExcelDataValidationOperator.Between, 0, 1000000);
            sheet.Range("A12:F12").Merge(); sheet.Cell(12, 1).SetValue("Edit receipts and payments; closing cash rolls into the following month.");
            sheet.Range("A13:F13").Merge(); sheet.Cell(13, 1).SetValue("Planning example only. Tax, financing and bank reconciliation are excluded.");
            sheet.View.ShowGridlines = false;
            for (int row = 1; row <= 16; row++) {
                sheet.SetRowHeight(row, ExcelColumnWidth.Length(OfficeIMO.OfficeLength.Points(row == 1 ? 34 : row == 3 ? 12 : 25)));
                for (int column = 1; column <= 6; column++) {
                    if (row > 1) sheet.Cell(row, column).SetFontSize(global::OfficeIMO.OfficeLength.Points(11));
                }
            }
            sheet.SetRowHeight(4, ExcelColumnWidth.Length(OfficeIMO.OfficeLength.Points(30)));
            for (int column = 1; column <= 6; column++) {
                sheet.Cell(4, column).SetColor(OfficeColor.Parse("FFFFFF"));
                sheet.Cell(4, column).SetBold(true);
                sheet.Cell(4, column).SetFillColor(OfficeColor.Parse("17365D"));
            }
            document.Calculate();
            document.InspectFormulas().EnsureAllSupported().EnsureAllHaveCachedResults().EnsureNoDependencyIssues();
            sheet.Range("A1:F14").ToImage(OfficeImageExportFormat.Png, new ExcelImageExportOptions { ShowGridlines = false })
                .Save(Path.Combine(folder, "preview.png"), OfficeImageExportFileConflictPolicy.Replace);
            document.Save();
        }
    }
}
```

[Open the C# source file](/downloads/showcase/workflows/excel-cash-flow-forecast/CashFlowForecast.cs.txt)

## API used in this example

- [`ExcelColumnWidth`](/api/excel/officeimo-excel-excelcolumnwidth/)
- [`OfficeLength`](/api/core/officeimo-officelength/)
- [`OfficeColor`](/api/core/officeimo-officecolor/)
- [`ExcelDataValidationOperator`](/api/excel/officeimo-excel-exceldatavalidationoperator/)
- [`ExcelDocument`](/api/excel/officeimo-excel-exceldocument/)
- [`ExcelImageExportOptions`](/api/excel/officeimo-excel-excelimageexportoptions/)
- [`ExcelTableStyle`](/api/excel/officeimo-excel-exceltablestyle/)
- [`OfficeImageExportFileConflictPolicy`](/api/core/officeimo-drawing-officeimageexportfileconflictpolicy/)
- [`OfficeImageExportFormat`](/api/core/officeimo-drawing-officeimageexportformat/)

## Use this in your project

Use actual forecast assumptions and reconcile separately; this sample excludes tax and financing.

The [Excel guide](/docs/excel/) explains package setup and related document APIs.

## Documents and scope

### What the preview shows

The C# source generates the downloadable file. The runner validates the workbook and supported formulas, cached results and dependencies. The PNG is a native range export.

### What to keep in mind

Use actual forecast assumptions and reconcile separately; this sample excludes tax and financing.

[Excel API reference](/api/excel/) · [Artifact hashes and provenance](/downloads/showcase/manifest.json)

## Continue with another example

- [Excel**Budget scenario comparison**](/showcase/excel-budget-scenarios/)
- [Excel**Pricing with named ranges**](/showcase/excel-named-range-pricing/)

<!-- PowerForge markdown artifact sha256:B99BEB3908344DA6F640E3001C2432EFABAD878A59E554748B0DFFD817623353 -->
