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

Free Swift Library to Read, Write & Convert Excel XLSX Files

Create, Edit, Manipulate and Convert Excel XLSX Spreadsheet Files Directly on Mobile Devices using Open Source Swift library.

What is SwiftXLSX ?

In the world of modern software development, the ability to work with various file formats is essential. One of the most ubiquitous file formats in business and data analysis is the Excel spreadsheet. Whether you are parsing data, generating reports, or simply need to interact with Excel files in your Swift application, the SwiftXLSX library is a valuable tool in your toolkit. It is an open source Swift library designed to simplify the process of reading and writing Excel files in the XLSX format. If you're a Swift developer tasked with parsing data, generating reports, or managing Excel files within your application, SwiftXLSX can be very helpful in making it easy for you.

SwiftXLSX is designed to be easy to use and integrates seamlessly into your Swift projects. This library simplifies the process of working with Excel files, making tasks such as data extraction, manipulation, and report generation straightforward. There are several important features part of the library, such as reading and writing Excel XLSX documents, extracting data from specific cells, rows or columns, data sorting, filtering data and calculating values within Excel sheets, applying formatting and styling to cells, and many more. The library is designed to work across different platforms, including iOS, macOS, and Linux.

The SwiftXLSX library is a powerful and versatile tool for Swift developers who need to work with Excel files. Being written in Swift, the library seamlessly integrates with your existing Swift codebase. This means you can leverage the full power of the Swift programming language while working with Excel files. Whether you're building a data analysis tool, a reporting feature, or simply need to interact with Excel files in your application, it simplifies the process and provides a robust set of features to handle your Excel-related tasks. With its ease of use, cross-platform support, and strong integration with Swift, it's a valuable addition to any Swift developer's toolbox.

Previous Next

Getting Started with SwiftXLSX

The recommend way to install SwiftXLSX is using CocoaPods. Please use the following command for a smooth installation.

Install SwiftXLSX via CocoaPods

 pod "SwiftXLSX"

pod install

You can download it directly from GitHub.

Reading & Writing Excel Files via Swift API

The open source SwiftXLSX library allows software developers to create a new file from the scratch with just a couple of lines of Swift code. Software developers can load and read data from existing Excel files with ease. There are several other important features part of the library, such as importing Excel files, extracting data from existing files, making modifications, and saving the results back into Excel format with ease. The following example shows how software developers can read data from an Excel file using SwiftXLSX library.

How to Read Data from an Excel File using Swift API?

import SwiftXLSX
import SwiftXLSX

do {
    let filePath = "path/to/your/excel-file.xlsx"
    let file = try XLSXFile(filepath: filePath)
    for path in try file.parseWorksheetPaths() {
        let ws = try file.parseWorksheet(at: path)
        for row in ws.data?.dropFirst() ?? [] {
            for cell in row {
                print(cell)
            }
        }
    }
} catch {
    print("Error reading Excel file: \(error)")
}

Apply Styling & Formatting to Excel File via Swift

Applying styling and formatting to Excel files using the SwiftXLSX library allows you to customize the appearance of your Excel sheets, making them more visually appealing and informative. Software developers can format cells, change font settings, apply borders, and set background colors to highlight specific data. Here's how you can apply styling and formatting to an Excel file inside Swift Applications.

How to Apply Styling and Formatting to Excel Worksheet using Swift?

import SwiftXLSX

// Create a new Excel file
let file = XLSXFile()

do {
    let ws = try file.parseWorksheet(at: 0) // Replace 0 with the index of the worksheet you want to format
} catch {
    print("Error parsing worksheet: \(error)")
}

// Font Settings

let font = Font(family: .roman, bold: true, size: 12)
ws.cell(at: CellReference("A1")).style.font = font

// Background Color:

ws.cell(at: CellReference("B2")).style.fill = Fill(patternType: .solid, fgColor: Color(.yellow))

// Borders:
let border = Border(style: .thin, color: Color(.black))
ws.cell(at: CellReference("C3")).style.borders = Borders(left: border, right: border, top: border, bottom: border)

// Number Format:

ws.cell(at: CellReference("D4")).style.numberFormat = .number

//Save the File:

let savePath = "path/to/save/your/excel-file.xlsx"
do {
    try file.save(to: savePath)
} catch {
    print("Error saving Excel file: \(error)")
}

Data Extraction & Manipulation via Swift API

The open source SwiftXLSX library allows software developers to manipulate data inside Excel Spreadsheet using Swift API. The library allows to perform various data manipulation operations, such as sorting, filtering, and calculating values within Excel sheets. This makes it an ideal tool for tasks like data analysis and reporting. Moreover, software developers can easily extract data from specific cells, rows, or columns within an Excel sheet using Swift API. This is incredibly useful when dealing with large datasets and only needing specific information.