Excel XLSX फ़ाइलों को पढ़ने और लिखने के लिए मुफ्त Swift लाइब्रेरी
ओपन सोर्स मजबूत Swift 5 लाइब्रेरी जो डेवलपरों को XLSX फ़ाइलें बनाने और पढ़ने, शीट कॉपी करने, हटाने, स्टाइल और फॉर्मेट लागू करने आदि में मुफ्त में सक्षम बनाती है।
XlsxReaderWriterSwift क्या है?
क्या आप अपने Swift प्रोजेक्ट्स में जटिल स्प्रेडशीट फ़ॉर्मेट से जूझते-थक रहे हैं? कल्पना करें कि आपका ऐप विस्तृत रिपोर्ट बनाने, टेम्पलेट से उपयोगकर्ता डेटा आयात करने, या यहां तक कि एक गतिशील वित्तीय मॉडल बनाने की आवश्यकता है—सभी सीधे iOS पारिस्थितिकी तंत्र में। CSV फ़ाइलों को मैन्युअल रूप से पार्स करना सीमित है, और बाहरी सेवाओं पर निर्भर रहना अक्षम है। यहाँ XlsxReaderWriterSwift आता है, एक शक्तिशाली और मूल ओपन-सोर्स लाइब्रेरी, जो Microsoft Excel के आधुनिक .xlsx फ़ॉर्मेट को पढ़ने और लिखने के लिए एक सहज और मजबूत टूलकिट प्रदान करता है, सीधे आपके iOS, macOS और visionOS एप्लिकेशन में।
XlsxReaderWriterSwift एक मजबूत Swift 5 लाइब्रेरी है जो सॉफ़्टवेयर डेवलपर्स को XLSX फ़ाइलें बनाने और पढ़ने में सक्षम बनाती है, जो आधुनिक Excel स्प्रेडशीट्स का मानक है। इस लाइब्रेरी ने Microsoft Excel XLSX फ़ाइलों के साथ काम करने के लिए कई महत्वपूर्ण सुविधाएँ प्रदान की हैं, जैसे XLSX फ़ाइल पढ़ना, नई XLSX फ़ाइलें बनाना, कोशिकाओं पर शैली और फ़ॉर्मेटिंग लागू करना, कोशिकाओं में छवियां जोड़ना और प्रबंधित करना, रिपोर्ट बनाना, स्प्रेडशीट एम्बेड करना आदि। यह C लाइब्रेरी libxlsxwriter पर निर्मित है, जिससे Apple पारिस्थितिकी तंत्र के लिए व्यापक सुविधाएँ उपलब्ध होती हैं। इसका मतलब है कि आप अपने iOS या macOS एप्लिकेशन से सीधे पूरी‑फीचर, 100% संगत Excel फ़ाइलें उत्पन्न कर सकते हैं।
XlsxReaderWriterSwift से शुरू करना
XlsxReaderWriterSwift स्थापित करने का अनुशंसित तरीका CocoaPods का उपयोग करना है। कृपया सुगम स्थापना के लिए नीचे दिया गया कमांड उपयोग करें।
CocoaPods के माध्यम से XlsxReaderWriterSwift स्थापित करें
pod "XlsxReaderWriterSwift"
pod install
GitHub के माध्यम से XlsxReaderWriterSwift स्थापित करें
git clone https://github.com/mehulparmar4ever/XlsxReaderWriterSwift.git
You can download it directly from GitHub.
Swift लाइब्रेरी के माध्यम से नई XLSX फ़ाइल बनाना और लिखना
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 लाइब्रेरी के माध्यम से एक नई Excel XLSX वर्कशीट कैसे बनाएं?
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)")
}
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.
Swift लाइब्रेरी का उपयोग करके Excel कोशिकाओं पर उन्नत शैली कैसे लागू करें?
// ... (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
}
Swift लाइब्रेरी के माध्यम से XLSX फ़ाइल पढ़ना
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.
एक Excel XLSX फ़ाइल से डेटा मुफ्त Swift API के माध्यम से कैसे पढ़ें?
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)")
}
}
}