Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

A project workbook with a summary

Let one worksheet own the detailed numbers while a second presents the review view. This workbook demonstrates cross-sheet references without manually copying the same figures into two places.

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

Start with
Planned and used days by workstream
Generate
XLSX
Generated Excel example: A project workbook with a summary
Generated worksheet · Generated by the example below

How it works

  1. Separate detail from presentation

    Create Summary first for the opening view, and Delivery for the data table.

  2. Calculate in the owning sheet

    Compute remaining days beside each delivery row, then point the summary formulas at those cells.

  3. Keep the detail usable

    Add a table and freeze its heading row. Calculate before creating the summary image and saving the workbook.

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.

using System.IO;
using OfficeIMO.Drawing;
using OfficeIMO.Excel;

namespace OfficeIMO.Examples.Showcase.Workflows;

/// <summary>Separates delivery detail from a summary with cross-sheet formulas.</summary>
internal static class ProjectWorkbook {
    internal static void Create(string folder) {
        using ExcelDocument document = ExcelDocument.Create(Path.Combine(folder, "example.xlsx"));
        ExcelSheet summary = document.AddSheet("Summary");
        ExcelSheet delivery = document.AddSheet("Delivery");
        summary.Range("A1:D1").Merge();
        summary.Cell(1, 1).SetValue("Project workbook / weekly delivery");
        summary.Cell(1, 1).SetFontSize(global::OfficeIMO.OfficeLength.Points(20));
        summary.Cell(1, 1).SetBold(true);
        summary.Cell(1, 1).SetFontColor("17365D");
        string[] labels = { "Discovery", "Build", "Pilot", "Handover" };
        string[] headers = { "Workstream", "Planned days", "Used days", "Remaining" };
        for (int column = 0; column < headers.Length; column++) {
            delivery.Cell(1, column + 1).SetValue(headers[column]);
            summary.Cell(4, column + 1).SetValue(headers[column]);
            summary.Cell(4, column + 1).SetFillColor("17365D");
            summary.Cell(4, column + 1).SetFontColor("FFFFFF");
            summary.SetColumnWidth(column + 1, ExcelColumnWidth.Characters(column == 0 ? 30 : 22));
            delivery.SetColumnWidth(column + 1, ExcelColumnWidth.Characters(column == 0 ? 30 : 22));
        }
        for (int index = 0; index < labels.Length; index++) {
            int row = index + 2;
            delivery.Cell(row, 1).SetValue(labels[index]);
            delivery.Cell(row, 2).SetValue(new[] { 12, 30, 10, 8 }[index]);
            delivery.Cell(row, 3).SetValue(new[] { 12, 18, 3, 0 }[index]);
            delivery.Cell(row, 4).SetFormula($"B{row}-C{row}");
            summary.Cell(index + 5, 1).SetValue(labels[index]);
            for (int column = 2; column <= 4; column++) {
                string letter = ((char)('A' + column - 1)).ToString();
                summary.Cell(index + 5, column).SetFormula($"'Delivery'!{letter}{row}");
            }
            summary.Cell(index + 5, 4).SetFillColor("E7F6ED");
        }
        delivery.AddTable("A1:D5", true, "DeliveryPlan", ExcelTableStyle.TableStyleMedium2);
        delivery.View.Freeze(topRows: 1);
        summary.Range("A11:D11").Merge();
        summary.Cell(11, 1).SetValue("Edit the Delivery sheet; Summary references the same values.");
        document.Calculate();
        summary.Range("A1:D13").ExportImage(OfficeImageExportFormat.Png)
            .Save(Path.Combine(folder, "preview.png"), OfficeImageExportFileConflictPolicy.Replace);
        document.Save();
    }
}
Open the C# source file

API used in this example

Use this in your project

Add workstreams to the detail sheet and extend the corresponding summary references. The sample remaining-day values are 0, 12, 7, and 8.

The Excel guide explains package setup and related document APIs.

Documents and scope

What the preview shows

The linked C# example generates this file. The runner reopens and validates the XLSX. The image is a native rendering of the specified worksheet range.

What to keep in mind

The image shows the Summary sheet. Open the XLSX to inspect and edit Delivery; the preview is not an interactive workbook.

Excel API reference · Artifact hashes and provenance

Continue with another example

Example source