Working with XLSX Packaging

Working with XLSX Packaging

Working with XLSX Packaging

Aspose.Cells FOSS for C++ reads and writes the .xlsx Open XML format through a dedicated serialization layer. The XlsxWorkbookSerializer class orchestrates loading and saving of all workbook parts including worksheets, styles, defined names, document properties, and auto-filters.


Loading and Saving XLSX Files

Use the Workbook class for all load and save operations. Internally, XlsxWorkbookSerializer handles the Open XML packaging:

#include "aspose/cells_foss/Workbook.h"

using namespace Aspose::Cells_FOSS;

int main() {
    // Load existing XLSX
    Workbook workbook("input.xlsx");

    // Modify content...

    // Save back to XLSX
    workbook.Save("output.xlsx");
    return 0;
}

Document Properties

XLSX files carry core and extended document properties (title, author, creation date). These are managed by XlsxDocumentProperties, which builds and loads the docProps/core.xml and docProps/app.xml parts:

PartManaged byContains
docProps/core.xmlXlsxDocumentProperties::BuildCorePropertiesDocumentTitle, author, created, modified
docProps/app.xmlXlsxDocumentProperties::BuildExtendedPropertiesDocumentApplication name, version

Workbook Metadata and Settings

Workbook-level metadata — calculation settings, book views, and workbook protection — is managed by XlsxWorkbookProperties:

  • BuildWorkbookPropertiesElement — writes workbook calculation and iteration settings
  • BuildWorkbookProtectionElement — writes workbook-level password protection
  • BuildBookViewsElement — writes window position and active sheet settings

Styles and Number Formats

The styles part (xl/styles.xml) is managed by XlsxWorkbookStyles. It maps Style objects from the in-memory model to serialized font, fill, border, and number-format records:

  • BuildStylesheet — serializes all styles to XML
  • LoadStylesheet — reads styles from an existing XLSX file
  • StylesEqual — checks whether two style objects would produce identical XML

Auto-Filter Packaging

Auto-filter state per worksheet is serialized by XlsxWorkbookAutoFilter:

  • BuildAutoFilterElement — writes the <autoFilter> XML element
  • LoadAutoFilter — reads auto-filter configuration from a worksheet part

Defined Names

Named ranges and formulas are packaged in the workbook part and loaded by XlsxWorkbookDefinedNames:

  • BuildDefinedNames — writes all DefinedName entries to the workbook XML
  • LoadWorkbookDefinedNames — reads defined names during file load

Tips and Best Practices

  • Use Workbook::Save(fileName) as the single exit point — do not invoke serializer classes directly unless extending the library.
  • The .xlsx format is the only fully supported format; saving to other formats is not available in v0.1.
  • File paths passed to Workbook(filePath) or Save(filePath) must use the platform path separator and be fully qualified when running in environments where the working directory may vary.
  • Workbook protection applied via XlsxWorkbookProperties::BuildWorkbookProtectionElement is independent of worksheet-level protection set through Worksheet::Protect.

Common Issues

IssueCauseFix
File fails to loadInvalid or encrypted XLSXEnsure the file is a plain (non-password-protected) XLSX
Styles lost after saveStyle not applied before SaveCall Cell::SetStyle(style) before Workbook::Save
Defined names missing after round-tripScope set to wrong sheetUse DefinedName::SetFormula with full range address

API Reference Summary

Class/MethodDescription
Workbook(filePath)Load an XLSX file
Workbook::Save(fileName)Save to XLSX
XlsxWorkbookSerializer::SaveInternal: serializes model to Open XML
XlsxWorkbookSerializer::LoadInternal: deserializes Open XML to model
XlsxDocumentPropertiesCore and extended document property packaging
XlsxWorkbookPropertiesWorkbook metadata and settings serialization
XlsxWorkbookStylesStyle sheet packaging
XlsxWorkbookAutoFilterAuto-filter XML packaging
XlsxWorkbookDefinedNamesDefined name XML packaging

See Also