SwiftXLSX - A library focused creating Excel spreadsheet (XLSX) files directly on mobile devices

Related tags

Files SwiftXLSX
Overview

SwiftXLSX

Excel spreadsheet (XLSX) format writer on pure SWIFT.

SwiftXLSX is a library focused creating Excel spreadsheet (XLSX) files directly on mobile devices.

Generation example XLSX file

    // library generate huge XLSX file with three sheets.
    XWorkBook.test()

Requirements

Apple Platforms

  • Xcode 11.3 or later
  • Swift 5.5 or later
  • iOS 10.0

Installation

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies on all platforms.

Once you have your Swift package set up, adding SwiftXLSX as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
  .package(url: "https://github.com/3973770/SwiftXLSX", .upToNextMajor(from: "0.1.0"))
]

If you're using SwiftXLSX in an app built with Xcode, you can also add it as a direct dependency using Xcode's GUI.

Dependency

SSZipArchive ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS. https://github.com/ZipArchive/ZipArchive.git

Screenshots

screenshot of invoce

screenshot of performance test

Example for use

>>") print("\(fileid)")">
   let book = XWorkBook()

   let color:[UIColor] = [.darkGray, .green, .lightGray, .orange, .systemPink, .cyan, .purple, .magenta, .blue]
   let colortext:[UIColor] = [.darkGray, .black, .white, .darkText, .lightText]


   func GetRandomFont() -> XFontName {
       let cases = XFontName.allCases
       return cases[Int.random(in: 0..<cases.count)]
   }


   var sheet = book.NewSheet("Invoice")

   var cell = sheet.AddCell(XCoords(row: 2, col: 6))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.value = .text("INVOICE")
   cell.Font = XFont(.TrebuchetMS, 16,true)
   cell.alignmentHorizontal = .center

   cell = sheet.AddCell(XCoords(row: 3, col: 6))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.value = .text("#12345")
   cell.Font = XFont(.TrebuchetMS, 12,true)
   cell.alignmentHorizontal = .left

   cell = sheet.AddCell(XCoords(row: 2, col: 1))
   cell.value = .text("Your company name")
   cell.Font = XFont(.TrebuchetMS, 16,true)

   cell = sheet.AddCell(XCoords(row: 3, col: 1))
   cell.value = .text("[Address Line 1]")

   cell = sheet.AddCell(XCoords(row: 4, col: 1))
   cell.value = .text("[Address Line 2]")

   cell = sheet.AddCell(XCoords(row: 5, col: 1))
   cell.value = .text("[Address Line 3]")

   cell = sheet.AddCell(XCoords(row: 7, col: 1))
   cell.color = .systemOrange
   cell.value = .text("Bill To:")
   cell.Font = XFont(.TrebuchetMS, 12,true)

   cell = sheet.AddCell(XCoords(row: 8, col: 1))
   cell.value = .text("[Address Line 1]")

   cell = sheet.AddCell(XCoords(row: 9, col: 1))
   cell.value = .text("[Address Line 2]")

   cell = sheet.AddCell(XCoords(row: 10, col: 1))
   cell.value = .text("[Address Line 3]")

   /// date
   cell = sheet.AddCell(XCoords(row: 13, col: 1))
   cell.color = .systemOrange
   cell.value = .text("Invoice Date")
   cell.Font = XFont(.TrebuchetMS, 12,true)

   cell = sheet.AddCell(XCoords(row: 14, col: 1))
   cell.value = .text("01/22/2022")

   /// term
   cell = sheet.AddCell(XCoords(row: 13, col: 2))

   cell.value = .text("Terms")
   cell.Font = XFont(.TrebuchetMS, 12,true)

   cell = sheet.AddCell(XCoords(row: 14, col: 2))
   cell.value = .text("30 days")

   /// Due Date
   cell = sheet.AddCell(XCoords(row: 13, col: 3))
   cell.color = .systemOrange
   cell.value = .text("Due Date")
   cell.Font = XFont(.TrebuchetMS, 12,true)

   cell = sheet.AddCell(XCoords(row: 14, col: 3))
   cell.value = .text("02/20/2022")

   /// table
   /// title
   var line = 16
   cell = sheet.AddCell(XCoords(row: line, col: 1))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.Border = true
   cell.value = .text("Description")

   cell = sheet.AddCell(XCoords(row: line, col: 4))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.Border = true
   cell.value = .text("Qty")
   cell.Font = XFont(.TrebuchetMS, 10,true)

   cell = sheet.AddCell(XCoords(row: line, col: 5))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.Border = true
   cell.value = .text("Unit Price")
   cell.Font = XFont(.TrebuchetMS, 10,true)

   cell = sheet.AddCell(XCoords(row: line, col: 6))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.Border = true
   cell.value = .text("Amount")
   cell.Font = XFont(.TrebuchetMS, 10,true)

   /// line
   line += 1
   cell = sheet.AddCell(XCoords(row: line, col: 1))
   cell.Border = true
   cell.value = .text("item #1")

   cell = sheet.AddCell(XCoords(row: line, col: 4))
   cell.Border = true
   cell.value = .double(3)
   cell.alignmentHorizontal = .right

   cell = sheet.AddCell(XCoords(row: line, col: 5))
   cell.Border = true
   cell.value = .double(50)
   cell.alignmentHorizontal = .right

   cell = sheet.AddCell(XCoords(row: line, col: 6))
   cell.Border = true
   cell.value = .double(150)
   cell.alignmentHorizontal = .right

   /// line
   line += 1
   cell = sheet.AddCell(XCoords(row: line, col: 1))
   if #available(iOS 13.0, *) {
       cell.Cols(txt: .black, bg: .systemGray6)
   } else {
       cell.Cols(txt: .black, bg: .lightGray)
   }
   cell.Border = true
   cell.value = .text("item #2")

   cell = sheet.AddCell(XCoords(row: line, col: 4))
   if #available(iOS 13.0, *) {
       cell.Cols(txt: .black, bg: .systemGray6)
   } else {
       cell.Cols(txt: .black, bg: .lightGray)
   }
   cell.Border = true
   cell.value = .double(2)
   cell.alignmentHorizontal = .right

   cell = sheet.AddCell(XCoords(row: line, col: 5))
   if #available(iOS 13.0, *) {
       cell.Cols(txt: .black, bg: .systemGray6)
   } else {
       cell.Cols(txt: .black, bg: .lightGray)
   }
   cell.Border = true
   cell.value = .double(100)
   cell.alignmentHorizontal = .right

   cell = sheet.AddCell(XCoords(row: line, col: 6))
   if #available(iOS 13.0, *) {
       cell.Cols(txt: .black, bg: .systemGray6)
   } else {
       cell.Cols(txt: .black, bg: .lightGray)
   }
   cell.Border = true
   cell.value = .double(200)
   cell.alignmentHorizontal = .right

   /// line
   line += 1
   cell = sheet.AddCell(XCoords(row: line, col: 1))
   cell.Border = true
   cell.value = .text("item #3")

   cell = sheet.AddCell(XCoords(row: line, col: 4))
   cell.Border = true
   cell.value = .double(4)
   cell.alignmentHorizontal = .right

   cell = sheet.AddCell(XCoords(row: line, col: 5))
   cell.Border = true
   cell.value = .double(200)
   cell.alignmentHorizontal = .right

   cell = sheet.AddCell(XCoords(row: line, col: 6))
   cell.Border = true
   cell.value = .double(800)
   cell.alignmentHorizontal = .right

   line += 2

   cell = sheet.AddCell(XCoords(row: line, col: 1))
   cell.value = .text("Thank you for your business!")
   cell.Font = XFont(.TrebuchetMS, 10, false, true)
   cell.alignmentHorizontal = .left

   cell = sheet.AddCell(XCoords(row: line, col: 5))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.value = .text("Total")
   cell.Font = XFont(.TrebuchetMS, 11, true)
   cell.alignmentHorizontal = .left

   cell = sheet.AddCell(XCoords(row: line, col: 6))
   cell.Cols(txt: .white, bg: .systemOrange)
   cell.value = .double(1100)
   cell.Font = XFont(.TrebuchetMS, 11, true)
   cell.alignmentHorizontal = .right

   line += 2

   cell = sheet.AddCell(XCoords(row: line, col: 1))
   cell.value = .text("Payment Options")
   cell.Font = XFont(.TrebuchetMS, 12, true, false)
   cell.alignmentHorizontal = .left

   line += 1

   cell = sheet.AddCell(XCoords(row: line, col: 1))
   cell.value = .text("Enter PayPal email address or bank account number here")
   cell.Font = XFont(.TrebuchetMS, 10, false, true)
   cell.alignmentHorizontal = .left

   sheet.buildindex()

   sheet.MergeRect(XRect(2, 1, 5, 1))
   sheet.MergeRect(XRect(3, 1, 5, 1))
   sheet.MergeRect(XRect(4, 1, 5, 1))
   sheet.MergeRect(XRect(5, 1, 5, 1))

   sheet.MergeRect(XRect(16, 1, 3, 1))
   sheet.MergeRect(XRect(17, 1, 3, 1))
   sheet.MergeRect(XRect(18, 1, 3, 1))
   sheet.MergeRect(XRect(19, 1, 3, 1))

   sheet.MergeRect(XRect(23, 1, 3, 1))
   sheet.MergeRect(XRect(24, 1, 3, 1))


   sheet.ForColumnSetWidth(1, 100)
   sheet.ForColumnSetWidth(2, 70)
   sheet.ForColumnSetWidth(3, 60)
   sheet.ForColumnSetWidth(4, 70)
   sheet.ForColumnSetWidth(5, 70)
   sheet.ForColumnSetWidth(6, 90)


   sheet = book.NewSheet("Perfomance1 Sheet")
   for col in 1...20 {
       sheet.ForColumnSetWidth(col,Int.random(in: 50..<100))
       for row in 1...1000 {
           let cell = sheet.AddCell(XCoords(row: row, col: col))
           cell.value = .integer(Int.random(in: 100..<200000))
           cell.Font = XFont(GetRandomFont(), Int.random(in: 10..<20))
           cell.color = colortext[Int.random(in: 0..<colortext.count)]
           cell.colorbackground = color[Int.random(in: 0..<color.count)]
           cell.Border = true
           cell.alignmentHorizontal = .center
           cell.alignmentVertical = .center
       }
   }

   sheet = book.NewSheet("Perfomance2 Sheet")
   for col in 1...20 {
       sheet.ForColumnSetWidth(col,Int.random(in: 50..<100))
       for row in 1...1000 {
           let cell = sheet.AddCell(XCoords(row: row, col: col))
           cell.value = .text("\(row):\(col)")
           cell.Font = XFont(GetRandomFont(), Int.random(in: 10..<20))
           cell.color = colortext[Int.random(in: 0..<colortext.count)]
           cell.colorbackground = color[Int.random(in: 0..<color.count)]
           cell.Border = true
           cell.alignmentHorizontal = .center
           cell.alignmentVertical = .center
       }
   }

   let fileid = book.save("example.xlsx")
   print("<<
   
    >>
    "
   )
   print("\(fileid)")

License

SSZipArchive is protected under the MIT license and our slightly modified version of minizip-ng (formally minizip) 3.0.2 is licensed under the Zlib license.

Acknowledgments

You might also like...
Tool to debug layouts directly on iOS devices: inspect layers in 3D and debug each visible view attributes
Tool to debug layouts directly on iOS devices: inspect layers in 3D and debug each visible view attributes

Introduction Features Inspect layouts directly on iOS devices Inspection could be triggered only if app is running under DEBUG build configuration, so

Mobile-ios-ml - SBB Mobile Machine Learning for iOS devices
Mobile-ios-ml - SBB Mobile Machine Learning for iOS devices

ESTA library: Machine Learning for iOS This framework simplifies the integration

Switchboard - easy and super light weight A/B testing for your mobile iPhone or android app. This mobile A/B testing framework allows you with minimal servers to run large amounts of mobile users.

Switchboard - easy A/B testing for your mobile app What it does Switchboard is a simple way to remote control your mobile application even after you'v

SwiftUI Animation Library. Useful SwiftUI animations including Loading/progress, Looping, On-off, Enter, Exit, Fade, Spin and Background animations that you can directly implement in your next iOS application or project. The library also contains huge examples of spring animations such as Inertial Bounce, Shake, Twirl, Jelly, Jiggle, Rubber Band, Kitchen Sink and Wobble effects. Browse, find and download the animation that fits your needs. Spreadsheet CollectionViewLayout in Swift. Fully customizable. 🔶
Spreadsheet CollectionViewLayout in Swift. Fully customizable. 🔶

SwiftSpreadsheet Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Swift 5.0 Inst

Spreadsheet CollectionViewLayout in Swift. Fully customizable. 🔶
Spreadsheet CollectionViewLayout in Swift. Fully customizable. 🔶

SwiftSpreadsheet Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Swift 5.0 Inst

Reusable GridView with excellent performance and customization that can be time table, spreadsheet,  paging and more.
Reusable GridView with excellent performance and customization that can be time table, spreadsheet, paging and more.

GridView GridView can tile the view while reusing it. It has an API like UIKit that works fast. Even when device rotates it smoothly relayout. Appetiz

Super lightweight library that helps you to localize strings, even directly in storyboards!
Super lightweight library that helps you to localize strings, even directly in storyboards!

Translatio Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 9 or higher. Swi

Small library to easily run your tests directly within a Playground
Small library to easily run your tests directly within a Playground

[] (https://developer.apple.com/swift/) Build Status Branch Status master develop About PlaygroundTDD enables you to use TDD directly on Xcode Playgro

Package for creating, modifying, and managing subtitle files, such as SubRip (.srt).

SubtitleKit Package for creating, modifying, and managing subtitle files, such as SubRip (.srt). Supported formats Format File extension Is supported

PLHKit: A Swift DSL for Rendering and creating PDF Files.
PLHKit: A Swift DSL for Rendering and creating PDF Files.

PLHKit PLH is a tribute to Portsaid Light House, Port Said Lighthouse was the first building in the world created with reinforced concrete. 🌊 PLHKit

MicrofrontendGenerator - Script for creating micro frontends for Mobile in a simple and easy way

Introdução Template para a criação de SDK iOS. Existem duas opções de template:

📱 A comprehensive test task for creating an autolayout interface, requesting an API and JSON parsing from Effective Mobile.
📱 A comprehensive test task for creating an autolayout interface, requesting an API and JSON parsing from Effective Mobile.

ECOMMERCE A comprehensive test task for creating an autolayout interface, requesting an API and JSON parsing from Effective Mobile. 👩‍🎨 Design ✨ Fea

MultiPeer-Progress-iOS - Swift project to demo the use of the MultiPeer framework to send files between iOS devices and show the progress OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.
OpenTok Text Chat Accelerator Pack enables text messages between mobile or browser-based devices.

Text Chat Accelerator Pack iOS This project is deprecated The OpenTok Text Chat Accelerator Pack for iOS project is now a part of Accelerator Core iOS

Ported scrcpy for mobile platforms, to remotely control Android devices on your iPhone or Android phone.
Ported scrcpy for mobile platforms, to remotely control Android devices on your iPhone or Android phone.

scrcpy-mobile Ported scrcpy for mobile platforms, to remotely control Android devices on your iPhone or Android phone. Currently only supports control

Crossroad is an URL router focused on handling Custom URL Scheme
Crossroad is an URL router focused on handling Custom URL Scheme

Crossroad is an URL router focused on handling Custom URL Scheme. Using this, you can route multiple URL schemes and fetch arguments and parameters easily.

Comments
  • Generated files are broken

    Generated files are broken

    I tried running the test() to generate the example file, but when I try to open it I get:

    "Alert: We found a problem with some content in ’arrayToExcelTest.xlsx’. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes."

    I click Yes and Excel tries to recover the file, it opens and gives me this:

    "Excel was able to open the file by repairing or removing the unreadable content."

    I click on Veiw and get another error message:

    "No more new fonts may be applied. Please close some other documents and try again."

    No other documents are in fact open. Excel freezes at this point.

    Here is the repair log:

    " Repair Result to example1.xml

    Errors were detected in file ’example.xlsx’Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.Replaced Part: /xl/worksheets/sheet1.xml part with XML error. Load error. "

    I was once able to view the contents of the file, the invoice sheet was blank, but the other two sheets seemed fine. Most tries my excel becomes unresponsive though.

    To try and diagnose this, I simply created a blank book:

    let book = XWorkBook() var sheet = book.NewSheet("Test")

    This results in the exact same errors.

    opened by The-Johnson 1
  • Unable to add images and merge cells in the same sheet

    Unable to add images and merge cells in the same sheet

    This is working great for me, except when trying to add images and merging cells in the same sheet. I can either have images or have merged cells flawlessly. However, when trying to do both in the same sheet, all I get is a blank sheet.

    opened by david-palafox 0
  • Target version too low for ZipArchive

    Target version too low for ZipArchive

    Received the error:

    error build: The package product 'ZipArchive' requires minimum platform version 15.5 for the iOS platform, but this target supports 11.0

    I added SwiftXLSX to my XCode project using the built-in Swift Package Manager. In the package.swift for SwiftXLSX there is:

        name: "SwiftXLSX",
        platforms: [
            .iOS(.v10),
            .macOS(.v11),
        ],
    

    But in ZipArchive is:

        name: "ZipArchive",
        platforms: [
            .iOS("15.5"),
            .tvOS("15.4"),
            .macOS(.v10_15),
            .watchOS("8.4"),
        ],
    

    Before I fork and update SwiftXLSX I thought I would check to see if anyone else has solved this issue. I am unable (XCode won't let me) to change the package.swift for SwiftXLSX.

    opened by ctgreybeard 3
Releases(v0.1.4)
Owner
null
FileManager replacement for Local, iCloud and Remote (WebDAV/FTP/Dropbox/OneDrive) files -- Swift

This Swift library provide a swifty way to deal with local and remote files and directories in a unified way. This library provides implementaion of W

Amir Abbas Mousavian 890 Jan 6, 2023
ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

SSZipArchive ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS. Unzip zip files; Unzip password protected zi

ZipArchive 5.2k Jan 2, 2023
Swift framework for zipping and unzipping files.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Dec 30, 2022
FileExplorer is a powerful iOS file browser that allows its users to choose and remove files and/or directories

FileExplorer (iOS 9.0+) ?? Project created and maintained by Rafał Augustyniak. You can find me on twitter (@RaAugustyniak). Introduction FileExplorer

Rafał Augustyniak 717 Dec 19, 2022
NV_MVVM-C is a template file generator. This can reduce the time taken to write the boilerplate code and create the files.

NV_MVVM-C Template, is an MVVM-C Boilerplate generator which will help you generate all the necessary files for your project architected in MVVM-C.

Nikhil Vinod 9 Sep 6, 2022
zip file I/O library for iOS, macOS and tvOS

ZipZap is a zip file I/O library for iOS, macOS and tvOS. The zip file is an ideal container for compound Objective-C documents. Zip files are widely

Glen Low 1.2k Dec 27, 2022
CoreXLSX is a Excel spreadsheet (XLSX) format parser written in pure Swift

CoreXLSX Excel spreadsheet (XLSX) format parser written in pure Swift CoreXLSX is a library focused on representing the low-level structure of the XML

null 684 Dec 21, 2022
Excel spreadsheet (XLSX) format parser written in pure Swift

CoreXLSX Excel spreadsheet (XLSX) format parser written in pure Swift CoreXLSX is a library focused on representing the low-level structure of the XML

null 684 Dec 21, 2022
Full configurable spreadsheet view user interfaces for iOS applications. With this framework, you can easily create complex layouts like schedule, gantt chart or timetable as if you are using Excel.

kishikawakatsumi/SpreadsheetView has moved! It is being actively maintained at bannzai/SpreadsheetView. This fork was created when the project was mov

Kishikawa Katsumi 34 Sep 26, 2022
Full configurable spreadsheet view user interfaces for iOS applications. With this framework, you can easily create complex layouts like schedule, gantt chart or timetable as if you are using Excel.

kishikawakatsumi/SpreadsheetView has moved! It is being actively maintained at bannzai/SpreadsheetView. This fork was created when the project was mov

Kishikawa Katsumi 34 Sep 26, 2022