Skip to content

hugonote/WorkbookKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

status: experimental License: MIT Dependency: ZIPFoundation

WorkbookKit

WorkbookKit is a minimal Swift library for reading and writing .xlsx (Excel) files. Built on top of ZIPFoundation.

What it does

  • read .xlsx from local URL
  • list sheets (name, id)
  • read cells as Bool, Double, or String (Shared Strings and inline)
  • detect merged ranges when reading
  • create workbooks and sheets; write booleans, numbers, or text
  • address cells via CellAddress or Excel-style coordinates ("A1", "B2") in the subscript API
  • save valid .xlsx files that open in Excel and other spreadsheet apps

Limitations

  • writes only inline strings (no Shared Strings on write yet)
  • no formulas (ignored on read, not written)
  • only basic cell types; dates are not specially handled
  • no styling (a minimal styles.xml is generated for validity)
  • no charts/images/comments/pivot tables
  • simple error handling; no lazy loading or async I/O

Use it if:

  • you need to quickly extract or assemble a simple table;
  • you want a predictable structure and minimal dependencies.

Don’t use it if:

  • you need formulas, styles, dates, images, large datasets, or high performance.

Installation

dependencies: [
  .package(url: "https://github.com/hugonote/WorkbookKit.git", branch: "main")
]

dependency: ZIPFoundation you can also add it via the Xcode GUI.


Examples

Create and write an .xlsx file

import WorkbookKit

let workbook = Workbook()
workbook.addSheet(name: "Sheet1", id: 1)

workbook["Sheet1"]?["A1"] = .text("Hello!")
print(workbook["Sheet1"]?["A1"].asString()) // Hello!

workbook["Sheet1"]?["A2"] = .number(14)

let filePath: URL = URL(fileURLWithPath: "example.xlsx")
workbook.writeToFile(atPath: filePath)

Read an existing .xlsx file

import WorkbookKit

let filePath: URL = URL(fileURLWithPath: "example.xlsx")
let workbook = Workbook(fromPath: filePath)

print(workbook["Sheet1"]?["A1"].asString()) // Hello!

let sheet = workbook["Sheet1"]
print(sheet?["A2"].asString()) // 14.0

About

A lightweight Swift library for reading and writing .xlsx files

Resources

License

Stars

Watchers

Forks

Contributors

Languages