Excel XLSX Dosyalarını Okumak ve Yazmak için Ücretsiz Swift Kütüphanesi
Açık Kaynak, sağlam Swift 5 Kütüphanesi, Geliştiricilerin XLSX Dosyalarını Oluşturup Okumasını, Sayfaları Kopyalamasını, Kaldırmasını, Stil ve Biçimlendirme Uygulamasını ve daha fazlasını ücretsiz olarak sağlar.
XlsxReaderWriterSwift Nedir?
Swift projelerinizde karmaşık tablo formatlarıyla uğraşmaktan bıktınız mı? Uygulamanızın ayrıntılı bir rapor üretmesi, bir şablondan kullanıcı verilerini içe aktarması veya dinamik bir finansal model oluşturması gerektiğini hayal edin—tüm bunlar iOS ekosistemi içinde gerçekleşiyor. CSV dosyalarını manuel olarak ayrıştırmak sınırlı bir çözüm sunar ve dış hizmetlere güvenmek XLSX dosyalarını işlemek açısından verimsizdir. İşte XlsxReaderWriterSwift devreye giriyor. Bu güçlü ve yerel açık kaynak kütüphane, Swift geliştiricilerine Microsoft Excel'in modern .xlsx formatını doğrudan iOS, macOS ve VisionOS uygulamalarında sorunsuz bir şekilde okuma ve yazma imkanı sağlayan sezgisel ve sağlam bir araç seti sunar.
XlsxReaderWriterSwift, modern Excel tablolarının standardı olan XLSX dosyalarını oluşturma ve okuma yeteneğiyle yazılım geliştiricilerini güçlendiren sağlam bir Swift 5 kütüphanesidir. Kütüphane, Microsoft Excel XLSX dosyalarıyla çalışmak için bir dizi önemli özellik sunar: XLSX dosyası okuma, yeni XLSX dosyaları oluşturma, hücrelere stil ve biçimlendirme uygulama, hücrelerde resim ekleme ve yönetme, rapor oluşturma, gömülü tablolar ve daha fazlası. C kütüphanesi libxlsxwriter üzerine inşa edilmiş olup Apple ekosistemine kapsamlı bir özellik seti getirir. Bu sayede iOS veya macOS uygulamanızdan doğrudan tamamen işlevsel ve %100 uyumlu Excel dosyaları oluşturabilirsiniz.
XlsxReaderWriterSwift'e Başlarken
XlsxReaderWriterSwift'ı kurmanın önerilen yolu CocoaPods kullanmaktır. Lütfen sorunsuz bir kurulum için aşağıdaki komutu kullanın.
SwiftPackage'ı CocoaPods ile kurun
pod "XlsxReaderWriterSwift"
pod install
SwiftPackage'ı GitHub üzerinden kurun
git clone https://github.com/mehulparmar4ever/XlsxReaderWriterSwift.git
You can download it directly from GitHub.
Yeni Bir XLSX Dosyası Oluşturma ve Yazma (Swift Kütüphanesi)
Creating a new file from scratch and populating it with data is just as easy. The open source XlsxReaderWriterSwift library has provided complete support for creating and managing new Excel XLSX spreadsheet inside Swift applications. Software developers can create new worksheet, rename existing worksheet, copy worksheet data, save document to specific place and so on. The following example shows, how software developers can create a new Excel XLSX worksheet using Swift library.
Swift paketini kullanarak yeni bir Excel XLSX sayfası nasıl oluşturulur?
import XlsxReaderWriterSwift
// 1. Create a new, empty document
let document = BRAOfficeDocumentPackage()
// 2. Get the first worksheet and give it a name
guard let worksheet = document.workbook.worksheets.first as? BRAWorksheet else {
return
}
worksheet.name = "User Data"
// 3. Write different types of data to cells
worksheet.cell(forCellReference: "A1", shouldCreate: true).stringValue = "Name"
worksheet.cell(forCellReference: "B1", shouldCreate: true).stringValue = "Score"
worksheet.cell(forCellReference: "A2", shouldCreate: true).stringValue = "Alice"
worksheet.cell(forCellReference: "B2", shouldCreate: true).integerValue = 95
worksheet.cell(forCellReference: "A3", shouldCreate: true).stringValue = "Bob"
worksheet.cell(forCellReference: "B3", shouldCreate: true).integerValue = 87
// 4. Define a file path to save the document
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL = documentsDirectory.appendingPathComponent("NewReport.xlsx")
// 5. Save the document to the specified path
do {
let data = document.save()
try data?.write(to: fileURL)
print("Spreadsheet saved successfully at: \(fileURL.path)")
} catch {
print("Failed to save spreadsheet: \(error)")
}
İleri Düzey Hücre Stilini Uygulama (Swift)
A spreadsheet isn\'t just about data; presentation matters. The open source XlsxReaderWriterSwift API provides extensive control over cell styling. It goes beyond simple data entry. You can apply a wide range of formatting options, including, cell alignment and number formatting, creating new cells, creating new styles, accessing existing styles, applying a border to a range of cells, and so on. Here is a simple example that show how software developers can Apply advance styles to an Excel cells using Swift commands.
Excel hücrelerine ileri düzey stiller nasıl uygulanır?
// ... (after creating a worksheet and cell)
// Get or create a cell
let headerCell = worksheet.cell(forCellReference: "A1", shouldCreate: true)
headerCell.stringValue = "Sales Report"
// Access the cell's style
let style = headerCell.cellStyle()
// Configure the style
style.font.bold = true
style.font.size = 18
style.fill.foregroundColor = .blue // Background color
style.fill.patternType = .solid
style.alignment.horizontal = .center
// Apply a border to a range of cells
let borderStyle = BRABorderStyle()
borderStyle.lineStyle = .medium
borderStyle.color = .darkGray
let dataRange = worksheet.cells(inRows: 1...3, columns: 1...2)
for cell in dataRange {
(cell as? BRACell)?.cellStyle().bottomBorder = borderStyle
}
XLSX Dosyasını Okuma (Swift Kütüphanesi)
The open source XlsxReaderWriterSwift 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.
Ücretsiz Swift API ile bir Excel XLSX dosyasından veri nasıl okunur?
import XlsxReaderWriterSwift
// 1. Locate the .xlsx file in your app's bundle
guard let filePath = Bundle.main.path(forResource: "SampleData", ofType: "xlsx") else {
print("File not found!")
return
}
// 2. Create a BRAOfficeDocumentPackage object from the file
let document = BRAOfficeDocumentPackage.open(filePath)
// 3. Get the first worksheet
guard let worksheet = document.workbook.worksheets.first as? BRAWorksheet else {
print("No worksheets found!")
return
}
// 4. Read data from specific cells
if let cellA1 = worksheet.cell(forCellReference: "A1") {
let stringValue = cellA1.stringValue() // Gets the value as a String
print("A1: \(stringValue)")
}
if let cellB2 = worksheet.cell(forCellReference: "B2") {
let numberValue = cellB2.floatValue() // Gets the value as a Float
print("B2: \(numberValue)")
}
// 5. Iterate over a range of cells
for row in 1...5 {
for column in 1...3 {
let cellReference = "\(UnicodeScalar(64 + column)!)\(row)" // Creates refs like A1, B1, etc.
if let cell = worksheet.cell(forCellReference: cellReference),
let value = cell.stringValue() {
print("\(cellReference): \(value)")
}
}
}