### Configure Cells and Formatting Source: https://github.com/3973770/swiftxlsx/blob/main/README.md Examples of setting cell values, borders, alignment, and fonts within a worksheet. ```swift 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() ``` -------------------------------- ### Generate Large XLSX File Source: https://github.com/3973770/swiftxlsx/blob/main/README.md Use this method to generate a large XLSX file with multiple sheets. No specific setup is required beyond importing the library. ```swift // library generate huge XLSX file with three sheets. XWorkBook.test() ``` -------------------------------- ### List Available Font Families with XFontName Source: https://context7.com/3973770/swiftxlsx/llms.txt Utilize the XFontName enum to specify font families for cells. This example demonstrates assigning various common fonts to cells for visual distinction. ```swift import SwiftXLSX let book = XWorkBook() let sheet = book.NewSheet("Fonts") // Common font families let fonts: [(XFontName, String)] = [ (.Arial, "Arial - Sans-serif"), (.HelveticaNeue, "Helvetica Neue - Clean"), (.TimesNewRoman, "Times New Roman - Serif"), (.Georgia, "Georgia - Elegant Serif"), (.Verdana, "Verdana - Screen-friendly"), (.CourierNew, "Courier New - Monospace"), (.TrebuchetMS, "Trebuchet MS - Modern"), (.Futura, "Futura - Geometric"), (.Baskerville, "Baskerville - Classic"), (.Menlo, "Menlo - Code Font"), (.Zapfino, "Zapfino - Script"), (.Chalkduster, "Chalkduster - Playful"), ] for (index, (fontName, description)) in fonts.enumerated() { let cell = sheet.AddCell(XCoords(row: index + 1, col: 1)) cell.value = .text(description) cell.Font = XFont(fontName, 14) } sheet.ForColumnSetWidth(1, 200) let filePath = book.save("font_families.xlsx") ``` -------------------------------- ### Create and Populate Excel Sheet with SwiftXLSX Source: https://github.com/3973770/swiftxlsx/blob/main/README.md This snippet demonstrates creating a new Excel workbook, adding a sheet, and populating it with various data types and formatting. It includes setting cell values, text, numbers, colors, fonts, and alignment. Use this for generating reports or data exports. ```swift 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..>>") print("\(fileid)") ``` -------------------------------- ### Manage Cell Positioning and Regions with XCoords and XRect Source: https://context7.com/3973770/swiftxlsx/llms.txt Define specific cell locations using 1-indexed XCoords and create merged cell regions using XRect. ```swift import SwiftXLSX let book = XWorkBook() let sheet = book.NewSheet("Positioning") // XCoords: row and column are 1-indexed // Row 1, Column 1 = Cell A1 let a1 = sheet.AddCell(XCoords(row: 1, col: 1)) a1.value = .text("A1") // Row 1, Column 3 = Cell C1 let c1 = sheet.AddCell(XCoords(row: 1, col: 3)) c1.value = .text("C1") // Row 5, Column 2 = Cell B5 let b5 = sheet.AddCell(XCoords(row: 5, col: 2)) b5.value = .text("B5") // XRect for merging: XRect(startRow, startCol, width, height) // Merge A3:D3 (row 3, columns 1-4, span 4 wide, 1 tall) let mergedHeader = sheet.AddCell(XCoords(row: 3, col: 1)) mergedHeader.value = .text("Merged Header A3:D3") mergedHeader.Cols(txt: .white, bg: .darkGray) mergedHeader.alignmentHorizontal = .center sheet.MergeRect(XRect(3, 1, 4, 1)) // Merge B7:C9 (start at B7, 2 columns wide, 3 rows tall) let verticalMerge = sheet.AddCell(XCoords(row: 7, col: 2)) verticalMerge.value = .text("Vertical Merge B7:C9") verticalMerge.Cols(txt: .black, bg: .yellow) verticalMerge.alignmentHorizontal = .center verticalMerge.alignmentVertical = .center sheet.MergeRect(XRect(7, 2, 2, 3)) // Check if coordinate is within a rectangle let rect = XRect(7, 2, 2, 3) let testCoord = XCoords(row: 8, col: 2) let isInRect = rect.inrect(testCoord) // Returns true (inside but not origin) let filePath = book.save("positioning.xlsx") ``` -------------------------------- ### Merge Cells and Set Column Widths Source: https://github.com/3973770/swiftxlsx/blob/main/README.md Methods for merging rectangular cell areas and defining specific column widths. ```swift 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) ``` -------------------------------- ### Embed Images in Cells with XImages and XImageCell Source: https://context7.com/3973770/swiftxlsx/llms.txt Use XImages to register image assets and XImageCell to define their placement and display size within a worksheet. ```swift import SwiftXLSX #if os(iOS) import UIKit typealias PlatformImage = UIImage #else import Cocoa typealias PlatformImage = NSImage #endif let book = XWorkBook() let sheet = book.NewSheet("Images") // Load an image (from bundle, file, or create programmatically) if let logoImage = PlatformImage(named: "company_logo") { // Register image with XImages and get a unique key if let imageKey = XImages.append(with: logoImage) { // Create a cell with the image let imageCell = sheet.AddCell(XCoords(row: 1, col: 1)) let imageCellValue = XImageCell( key: imageKey, size: CGSize(width: 200, height: 75) // Display size in pixels ) imageCell.value = .icon(imageCellValue) // Same image at different size let largeImageCell = sheet.AddCell(XCoords(row: 5, col: 1)) let largeImageValue = XImageCell( key: imageKey, // Reuse same image key size: CGSize(width: 400, height: 150) ) largeImageCell.value = .icon(largeImageValue) } } // Add multiple different images let iconNames = ["icon1", "icon2", "icon3"] for (index, iconName) in iconNames.enumerated() { if let iconImage = PlatformImage(named: iconName), let iconKey = XImages.append(with: iconImage) { let cell = sheet.AddCell(XCoords(row: 1, col: index + 2)) cell.value = .icon(XImageCell(key: iconKey, size: CGSize(width: 32, height: 32))) } } // Set column width to accommodate images sheet.ForColumnSetWidth(1, 250) let filePath = book.save("images.xlsx") // Clean up image cache when done XImages.removeAll() ``` -------------------------------- ### Insert Image into Cell Source: https://github.com/3973770/swiftxlsx/blob/main/README.md To insert an image into a cell, use the XValue.icon initializer with an XImageCell object. Ensure the image is appended to XImages first. ```swift //new kind value of XValue for icons/images XValue.icon(XImageCell) ``` ```swift let cell = sheet.AddCell(XCoords(row: 1, col: 1)) let ImageCellValue:XImageCell = XImageCell(key: XImages.append(with: logoicon!)!, size: CGSize(width: 200, height: 75)) // CGSize(width: 200, height: 75) - size display image in pixel cell.value = .icon(ImageCellValue) ``` -------------------------------- ### Assign Different Data Types with XValue Source: https://context7.com/3973770/swiftxlsx/llms.txt Represent various data types within cells using the XValue enum. This includes text, integers, doubles, floats, and large numbers (UInt64). ```swift import SwiftXLSX let book = XWorkBook() let sheet = book.NewSheet("Value Types") // Text value let textCell = sheet.AddCell(XCoords(row: 1, col: 1)) textCell.value = .text("Hello, World!") // Integer value let intCell = sheet.AddCell(XCoords(row: 2, col: 1)) intCell.value = .integer(12345) // Double value (formatted to 3 decimal places in output) let doubleCell = sheet.AddCell(XCoords(row: 3, col: 1)) doubleCell.value = .double(3.14159265) // Float value let floatCell = sheet.AddCell(XCoords(row: 4, col: 1)) floatCell.value = .float(2.718) // Long (UInt64) value for large numbers let longCell = sheet.AddCell(XCoords(row: 5, col: 1)) longCell.value = .long(9223372036854775807) // Labels for clarity let labels = ["Text:", "Integer:", "Double:", "Float:", "Long:"] for (index, label) in labels.enumerated() { let labelCell = sheet.AddCell(XCoords(row: index + 1, col: 2)) labelCell.value = .text(label) labelCell.Font = XFont(.Arial, 10, true) } let filePath = book.save("value_types.xlsx") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.