Introduction

Aspose.Cells FOSS for C++ is an open-source library for creating, loading, editing, and saving Excel .xlsx workbooks from native C++ code, without requiring Microsoft Excel or any COM automation. It integrates into a CMake-based build as a source library — there is no external runtime dependency to install or link against beyond the C++ standard library.

The library is MIT licensed and targets C++17. It builds with add_subdirectory or FetchContent from a git clone, since it is not distributed through a package manager such as vcpkg or Conan. The API surface is organized around a Workbook that owns a WorksheetCollection, worksheets that expose a Cells object for cell-level access, and a Style facade for fonts, fills, and borders. If you build backend services, report generators, or data-export pipelines in C++ and need to produce or read .xlsx files without shelling out to Excel, this library gives you a native way to do it.

Aspose.Cells FOSS is also available for .NET, Go, Java, Python, Rust, and TypeScript. The C++ library follows the same approach as the rest of the family: an XLSX-focused API grounded in what is actually implemented, under a permissive license.


What’s Included

Workbook and Worksheet Structure

A Workbook starts with one worksheet. Additional sheets are created with WorksheetCollection::Add, and existing sheets are reached by index or by name through the collection’s indexer. Each Worksheet exposes its cells through GetCells().

#include "aspose/cells_foss/Workbook.h"
#include "aspose/cells_foss/Worksheet.h"

using namespace Aspose::Cells_FOSS;

Workbook workbook;
workbook.GetWorksheets()[0].SetName("Data");
workbook.GetWorksheets().Add("Summary");

Worksheet& data = workbook.GetWorksheets()["Data"];
data.GetCells()["A1"].PutValue("Product");
data.GetCells()["B1"].PutValue("Price");

Cell Values, Formulas, and Number Formats

Cell::PutValue has overloads for strings, integers, doubles, booleans, and other value kinds, so no manual string conversion is required. SetFormula accepts a formula with or without a leading = and normalizes it; GetType then reports a CellValueType of Formula. Number formatting is applied through Style::SetNumberFormat and affects only the display text returned by GetDisplayStringValue — the underlying stored value is unchanged.

auto& sheet = workbook.GetWorksheets()[0];
auto cell = sheet.GetCells()["B2"];
cell.PutValue(1234.567);

auto style = cell.GetStyle();
style.SetNumberFormat("#,##0.00");
cell.SetStyle(style);

sheet.GetCells()["B3"].SetFormula("B2*2");
// GetFormula() now returns "=B2*2"; GetType() reports CellValueType::Formula

std::cout << cell.GetDisplayStringValue() << std::endl; // "1,234.57"

Styling with Fonts, Fills, and Borders

Cell::GetStyle() and SetStyle() read and write a Style object that groups Font, Borders, and fill settings. Colors are constructed with Color::FromArgb, and fill patterns are set through FillPattern.

Style headerStyle = sheet.GetCells()["A1"].GetStyle();
Font font;
font.SetBold(true);
font.SetColor(Color::FromArgb(255, 255, 255, 255));
headerStyle.SetFont(font);
headerStyle.SetPattern(FillPattern::Solid);
headerStyle.SetForegroundColor(Color::FromArgb(255, 34, 120, 212));
sheet.GetCells()["A1"].SetStyle(headerStyle);

Data Validation and Conditional Formatting

ValidationCollection::Add scopes a Validation rule to a CellArea; setting its ValidationType to List with a Formula1 value produces an in-cell dropdown. ConditionalFormattingCollection::Add creates a formatting group that is scoped with AddArea and populated with AddCondition, which takes a FormatConditionType, an OperatorType, and one or two formulas.

int validationIndex = sheet.GetValidations().Add(CellArea::CreateCellArea("B1", "B3"));
auto validation = sheet.GetValidations()[validationIndex];
validation.SetType(ValidationType::List);
validation.SetFormula1("\"Open,Closed\"");
validation.SetShowError(true);

int cfIndex = sheet.GetConditionalFormattings().Add();
auto formatting = sheet.GetConditionalFormattings()[cfIndex];
formatting.AddArea(CellArea::CreateCellArea("C1", "C3"));
int conditionIndex = formatting.AddCondition(
    FormatConditionType::CellValue, OperatorType::Between, "1", "9");

auto condition = formatting[conditionIndex];
auto conditionStyle = condition.GetStyle();
conditionStyle.SetPattern(FillPattern::Solid);
conditionStyle.SetForegroundColor(Color::FromArgb(255, 255, 199, 206));
condition.SetStyle(conditionStyle);

Page Setup and Print Layout

Worksheet::GetPageSetup() returns a PageSetup object controlling paper size, orientation, scaling, print area, and print title rows/columns. Values are validated on assignment — for example, an out-of-range SetScale call raises a CellsException.

auto& pageSetup = sheet.GetPageSetup();
pageSetup.SetOrientation(PageOrientationType::Landscape);
pageSetup.SetPaperSize(PaperSizeType::PaperA4);
pageSetup.SetFitToPagesWide(1);
pageSetup.SetFitToPagesTall(3);
pageSetup.SetPrintArea("$A$1:$D$20");
pageSetup.SetPrintTitleRows("$1:$2");

Quick Start

Aspose.Cells FOSS for C++ is not distributed through a package manager — clone the repository and add it to your CMake project:

git clone https://github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Cpp.git

Add the library as a subdirectory of your own CMakeLists.txt and link against the aspose_cells_foss target:

add_subdirectory(path/to/Aspose.Cells-FOSS-for-Cpp/Aspose.Cells.Foss.Cpp)
target_link_libraries(MyApp PRIVATE aspose_cells_foss)

Then create, style, and save a workbook:

#include "aspose/cells_foss/Workbook.h"
#include "aspose/cells_foss/Worksheet.h"
#include "aspose/cells_foss/Cell.h"
#include "aspose/cells_foss/Style.h"
#include "aspose/cells_foss/Font.h"
#include "aspose/cells_foss/Color.h"

using namespace Aspose::Cells_FOSS;

int main() {
    Workbook workbook;
    Worksheet& sheet = workbook.GetWorksheets()[0];
    sheet.SetName("Products");

    sheet.GetCells()["A1"].PutValue("Product");
    sheet.GetCells()["B1"].PutValue("Price");
    sheet.GetCells()["A2"].PutValue("Apple");
    sheet.GetCells()["B2"].PutValue(2.99);
    sheet.GetCells()["A3"].PutValue("Orange");
    sheet.GetCells()["B3"].PutValue(1.99);
    sheet.GetCells()["B4"].SetFormula("SUM(B2:B3)");

    Style header = sheet.GetCells()["A1"].GetStyle();
    Font font;
    font.SetBold(true);
    header.SetFont(font);
    sheet.GetCells()["A1"].SetStyle(header);

    workbook.Save("products.xlsx");
    return 0;
}

Supported Formats

FormatExtensionReadWrite
XLSX.xlsx

XLSX is the only format the current release reads and writes. Workbook’s file and stream constructors load .xlsx data, and Save writes it back out; LoadFormat and SaveFormat enums govern explicit format selection on those calls.


Open Source & Licensing

Aspose.Cells FOSS for C++ is MIT licensed. The complete source is available on GitHub, and the license permits commercial use, modification, and redistribution.


Getting Started