Create spreadsheets & documents with Swift
Create a shareable spreadsheet from Swift using URLSession — no third-party networking library. Useful in iOS/macOS apps and server-side Swift (Vapor) where you want to generate a report and hand the user a link. The example uses async/await.
var req = URLRequest(url: URL(string:
"https://openofficeai.com/api/v1/sheets")!)
req.httpMethod = "POST"
req.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.httpBody = try JSONSerialization.data(withJSONObject: [
"title": "Q3 Revenue",
"sheets": [["rows": [
["Month", "Revenue", "Growth"],
["July", 48200, "+12%"]
]]]
])
let (data, _) = try await URLSession.shared.data(for: req)
let json = try JSONSerialization.jsonObject(with: data) as! [String: Any]
print(json["url"] as! String)How to create a spreadsheet with Swift
- 1Build a URLRequest with the Authorization and Content-Type headers.
- 2Serialize the body with JSONSerialization.data(withJSONObject:).
- 3await URLSession.shared.data(for:) and parse the JSON.
- 4Read the url field and present or store the link.
Why use OpenOfficeAI with Swift
- Pure Foundation — no Alamofire or Excel library.
- Works in iOS/macOS apps and server-side Swift (Vapor).
- Hand users a shareable link instead of bundling a file viewer.
Frequently asked questions
Can I call this directly from an iOS app?
You can, but never ship your API key inside the app binary. Route the request through your own backend (or a serverless function) that holds the key, and have the app call that.
Does this work with Codable instead of JSONSerialization?
Yes. Define Encodable structs for the body and a Decodable struct with a url field, then use JSONEncoder/JSONDecoder for type safety instead of dictionaries.
How do I download the file on macOS?
Request /api/v1/download/{id}?format=pdf (or xlsx) with another URLSession call and write the returned Data to disk with the suggested filename.
Start creating documents with Swift
Free tier includes 500 API calls per month — no card required.
Related integrations