1. Products
  2.   Spreadsheet
  3.   Swift
  4.   Objects2XLSX
 
  

Export SwiftObjects to Excel Files via Free Swift Library

Open Source Swift Library That allows Software Developers to Convert Swift Objects into Professional Excel (.xlsx) Files with Custom Styling.

What is Objects2XLSX?

Modern iOS, macOS, and server-side Swift applications often need to export structured data into Microsoft Excel spreadsheets. Whether you're generating sales reports, inventory lists, financial statements, or analytics dashboards, creating professional Excel files manually can quickly become complex. Objects2XLSX is an open-source Swift library designed to solve this problem. It allows developers to convert Swift objects directly into Excel (.xlsx) workbooks using a clean, type-safe, and declarative API. Instead of manually writing rows and columns, developers simply define how their Swift models map to spreadsheet columns and let the library handle the rest.

The library supports professional formatting, multiple worksheets, progress reporting, and a wide range of Swift data types, making it an excellent solution for report generation and business applications. According to the project's documentation, Objects2XLSX focuses on type safety, styling, multiple worksheets, and high-performance Excel generation. Objects2XLSX removes much of the boilerplate code traditionally required for Excel generation. Instead of manually creating cells, formatting worksheets, and managing data conversions, developers work directly with Swift objects. Some common use cases include exporting customer records, creating financial reports, inventory management, employee data exports, business analytics, sales reporting, educational grading systems and administrative dashboards.

Previous Next

Getting Started with Objects2XLSX

The recommend way to install Objects2XLSX is using Swift Package Manager (SPM) or Cocoapods. Please use the following command for a smooth installation.

Install Objects2XLSX via Swift Package Manager

  // Add Objects2XLSX to your Package.swift dependencies:

dependencies: [ .package(url: "https://github.com/fatbobman/Objects2XLSX.git", from: "1.3.0") ]

// Import the package
import Objects2XLSX

Install Objects2XLSX Via GitHub:

 git clone https://github.com/fatbobman/Objects2XLSX.git

You can download it directly from GitHub.

Declarative Workbook Construction via Swift

Building multi-tab spreadsheets historically demanded nested, step-by-step logic scripts that were difficult to scale or refactor. Objects2XLSX uses a declarative syntax layer that mimics modern domain-specific languages (DSLs). This allows engineers to state exactly what sheets, columns, and structural relationships should exist inside a workbook wrapper in a clean, visual hierarchy. This configuration greatly optimizes long-term codebase maintenance and simplifies collaborative code reviews.

How to Perform Declarative Workbook Construction via Swift API?

import Objects2XLSX
import Foundation

struct UserAccount: Sendable { let username: String; let rank: String }
struct LogEntry: Sendable { let timestamp: Date; let action: String }

func generateSystemWorkbook(users: [UserAccount], logs: [LogEntry]) -> Workbook {
    // Declarative assembly definition organizing multi-sheet data structures
    let workbook = Workbook(
        sheets: [
            Sheet(title: "Active Users", columns: [
                Column(header: "User Profile ID", keyPath: \.username),
                Column(header: "Access Group", keyPath: \.rank)
            ]).addRows(users),
            
            Sheet(title: "Security Audits", columns: [
                Column(header: "Event Time", keyPath: \.timestamp),
                Column(header: "Operation Details", keyPath: \.action)
            ]).addRows(logs)
        ]
    )
    return workbook
}

Apply Professional Excel Styling via Swift

Professional reports require more than raw data. The open source library Objects2XLSX provides extensive styling capabilities, allowing developers to customize fonts, colors, borders, alignments, and cell appearance. This makes it easy to generate business-ready spreadsheets without opening Excel afterward for manual formatting. The styling system is designed to produce polished workbooks suitable for presentations, reporting, and enterprise workflows.

How to Apply Customized Styling via Swift Library?

import Objects2XLSX
import CoreGraphics

// Define customized visual presets matching enterprise documentation needs
let boldHeaderStyle = Style()
    .font(.system(size: 11, weight: .bold))
    .alignment(.center)
    .background(.color(red: 0.12, green: 0.53, blue: 0.90)) // Corporate Blue

let currencyColumnStyle = Style()
    .numberFormat("$#,##0.00")
    .alignment(.right)

let customizedColumn = Column(
    header: "Gross Revenue", 
    keyPath: \FinancialRow.revenue,
    headerStyle: boldHeaderStyle,
    cellStyle: currencyColumnStyle,
    width: 22.0
)

struct FinancialRow: Sendable { let revenue: Double }

Apply Professional Excel Styling via Swift

Professional reports require more than raw data. The open source library Objects2XLSX provides extensive styling capabilities, allowing developers to customize fonts, colors, borders, alignments, and cell appearance. This makes it easy to generate business-ready spreadsheets without opening Excel afterward for manual formatting. The styling system is designed to produce polished workbooks suitable for presentations, reporting, and enterprise workflows.

How to Apply Customized Styling via Swift Library?

import Objects2XLSX
import CoreGraphics

// Define customized visual presets matching enterprise documentation needs
let boldHeaderStyle = Style()
    .font(.system(size: 11, weight: .bold))
    .alignment(.center)
    .background(.color(red: 0.12, green: 0.53, blue: 0.90)) // Corporate Blue

let currencyColumnStyle = Style()
    .numberFormat("$#,##0.00")
    .alignment(.right)

let customizedColumn = Column(
    header: "Gross Revenue", 
    keyPath: \FinancialRow.revenue,
    headerStyle: boldHeaderStyle,
    cellStyle: currencyColumnStyle,
    width: 22.0
)

struct FinancialRow: Sendable { let revenue: Double }

Progress Tracking for Large Exports

Generating Excel workbooks containing thousands of records may take noticeable time. Objects2XLSX includes progress tracking capabilities that allow developers to monitor export operations in real time. This feature is especially useful in desktop applications and enterprise systems where users expect visual feedback during lengthy report generation processes.