# Pricing with named ranges

Use named ranges in a C# Excel pricing model so formulas read like the business calculation. Inspect the rendered quote and download the workbook.

Excel · C# walkthrough

Make a small pricing calculation understandable to the next person who edits it. Named ranges give the formula meaningful terms and make the assumptions visible in the worksheet.

[Build this report](#example-code)[Download XLSX](/downloads/showcase/workflows/excel-named-range-pricing/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**

Quantity, unit price, and discount rate

**Generate**

XLSX

[!\[Generated Excel example: Pricing with named ranges\](/downloads/showcase/workflows/excel-named-range-pricing/preview.webp)](/downloads/showcase/workflows/excel-named-range-pricing/preview.png)

Generated worksheet · Generated by the example below

## How it works

1. ### Name the inputs
  
  Create workbook-scoped ranges for Quantity, UnitPrice, and DiscountRate, each pointing at its input cell.
2. ### Write a readable formula
  
  Use named formulas for gross total, discount amount, and net total. Each step has its own cell so a reader can inspect the calculation.
3. ### Format and inspect the result
  
  Evaluate the formula, apply numeric and percentage formats, and render the quote. The sample net total is 2,700.

## 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>Uses named ranges to keep a small pricing model readable as the sheet evolves.</summary>
internal static class NamedRangePricing {
    internal static void Create(string folder) {
        using ExcelDocument document = ExcelDocument.Create(Path.Combine(folder, "example.xlsx"));
        ExcelSheet sheet = document.AddSheet("Quote");
        sheet.SetColumnWidth(1, ExcelColumnWidth.Characters(32));
        sheet.SetColumnWidth(2, ExcelColumnWidth.Characters(23));
        sheet.SetColumnWidth(3, ExcelColumnWidth.Characters(42));
        sheet.Range("A1:C1").Merge();
        sheet.Cell(1, 1).SetValue("A quote with readable formulas");
        sheet.Cell(1, 1).SetFontSize(global::OfficeIMO.OfficeLength.Points(20));
        sheet.Cell(1, 1).SetBold(true);
        sheet.Cell(1, 1).SetColor(OfficeColor.Parse("17365D"));

        string[] labels = { "Quantity", "Unit price", "Discount rate", "Gross total", "Discount amount", "Net total" };
        string[] names = { "Quantity", "UnitPrice", "DiscountRate", "GrossTotal", "DiscountAmount", "NetTotal" };
        for (int index = 0; index < labels.Length; index++) {
            int row = index + 4;
            sheet.Cell(row, 1).SetValue(labels[index]);
            sheet.Cell(row, 3).SetValue(names[index]);
            sheet.Cell(row, 3).SetColor(OfficeColor.Parse("526179"));
            document.SetNamedRange(names[index], $"'Quote'!B{row}", save: false);
        }
        sheet.Cell(4, 2).SetValue(24).SetNumberFormat("#,##0");
        sheet.Cell(5, 2).SetValue(125).SetNumberFormat("#,##0.00");
        sheet.Cell(6, 2).SetValue(0.10).SetNumberFormat("0%");
        sheet.Cell(7, 2).SetFormula("Quantity*UnitPrice");
        sheet.Cell(8, 2).SetFormula("GrossTotal*DiscountRate");
        sheet.Cell(9, 2).SetFormula("GrossTotal-DiscountAmount");
        for (int row = 7; row <= 9; row++) {
            sheet.Cell(row, 2).SetNumberFormat("#,##0.00");
            sheet.Cell(row, 2).SetFillColor(OfficeColor.Parse("E7F6ED"));
        }
        sheet.Cell(9, 2).SetBold(true);
        sheet.Range("A12:C12").Merge();
        sheet.Cell(12, 1).SetValue("Gross total, discount, and net total each have a named result.");
        document.Calculate();
        sheet.Range("A1:C14").ToImage(OfficeImageExportFormat.Png)
            .Save(Path.Combine(folder, "preview.png"), OfficeImageExportFileConflictPolicy.Replace);
        document.Save();
    }
}
```

[Open the C# source file](/downloads/showcase/workflows/excel-named-range-pricing/NamedRangePricing.cs.txt)

## API used in this example

- [`ExcelColumnWidth`](/api/excel/officeimo-excel-excelcolumnwidth/)
- [`OfficeColor`](/api/core/officeimo-officecolor/)
- [`ExcelDocument`](/api/excel/officeimo-excel-exceldocument/)
- [`ExcelSheet`](/api/excel/officeimo-excel-excelsheet/)
- [`OfficeImageExportFileConflictPolicy`](/api/core/officeimo-drawing-officeimageexportfileconflictpolicy/)
- [`OfficeImageExportFormat`](/api/core/officeimo-drawing-officeimageexportformat/)
- [`OfficeLength`](/api/core/officeimo-officelength/)

## Use this in your project

Use names from your business vocabulary and keep their definitions near the inputs. Extend the model with separate named assumptions when the calculation grows.

The [Excel guide](/docs/excel/) 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 sample demonstrates one workbook-level calculation. It does not implement a pricing policy, tax engine, or negotiated-price approval process. Each calculation step uses the native formula engine supported by this example.

[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**Calculate a six-month forecast**](/showcase/#excel-formulas)
- [Excel**A structured expense register**](/showcase/excel-expense-register/)

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