MarkersExtractor icon indicating copy to clipboard operation
MarkersExtractor copied to clipboard

Switch to XLKit

Open IAmVigneswaran opened this issue 6 months ago • 14 comments

@orchetect

With the help of an AI agent, I created a Swift library called XLKit. I didn’t write a single line of code. It was all vibe coded, just out of curiosity to see if it was even possible.

XLKit can embed images into Excel files with dynamic and automatic sizing while preserving the image’s aspect ratio. Everything appears to be working on first glance.

When you have time, could you review it? Thank you.

IAmVigneswaran avatar Jul 07 '25 14:07 IAmVigneswaran

I'm not sure I have the bandwidth to review an entire framework built by AI. While it may be capable, my first concern would be any potential security issues.

orchetect avatar Jul 07 '25 20:07 orchetect

I am not really sure what potential security issues there might be? On first glance everything seems to be working and all the test are passing?

IAmVigneswaran avatar Jul 07 '25 20:07 IAmVigneswaran

We don't need to use any macros to embed images. Hence security concerns is mitigated?

IAmVigneswaran avatar Jul 07 '25 21:07 IAmVigneswaran

Every line of code written by AI has to be manually vetted for security vulnerabilities in what the code is doing. It's possible that code can be poisoned by vulnerability injection while the code itself also appears to work correctly. I would not use anything written by AI until it is checked in its entirety.

orchetect avatar Jul 07 '25 21:07 orchetect

I see!

IAmVigneswaran avatar Jul 07 '25 21:07 IAmVigneswaran

I have updated XLKit to v1.0.2 with some security enhancements. 🤞



Regarding your point about manually vetting AI-generated code for security vulnerabilities and concerns.

While it can be contradicting, I tried to the same Cursor AI agent to analyse XLKit's codebase. It identified few potential issues and suggested refactoring improvements.

  • The key addition is a new SecurityManager providing rate limiting, security logging, file quarantine, and checksum verification, all integrated throughout XLSXEngine, ImageUtils, and the main API.
  • It replaced the system zip command with a pure Swift ZIP library to eliminate command injection risks and fixed Swift 6.0 concurrency issues with proper @MainActor implementation and error handling.

I hope this at least acts as first round security review of XLKit codebase before proper human verification and vetting?



Cursor AI updated XLSX Export Utils.swift and ExcelProfile Export.swift to reflect the API changes with proper commenting for any future reference.

It also automatically added the necessary updates await and async to ExportProfile.swift and ExportProfile Export.swift to prevent build failures.

After the updates, I was able to build MarkersExtractor successfully. And I was able to generate the excel file with embedded images.

With XLKit 1 0 2 Update

IAmVigneswaran avatar Jul 09 '25 01:07 IAmVigneswaran

That's some good first steps.

suggested refactoring improvements

When I originally looked at the 1.0.0 codebase very briefly, I noticed a coding pattern it decided to use that certainly works but is not very Swifty. It does a lot of static method calls on a central XLKit namespace which I'm guessing it learned from various other coding languages where that pattern may be more consistent with those languages, but is very unusual for Swift. Just one thing I noticed, and would be nice to refactor in future.

orchetect avatar Jul 10 '25 23:07 orchetect

I noticed a coding pattern it decided to use that certainly works but is not very Swifty.

Interesting!

Since I do not possess the fundamental knowledge (What to do and what not to do) about Swift coding and all its paradigm, I certainly would not know how to give specific prompts so that it adheres to proper Swift standards and what it should look for.

While it might be building without errors, you right about the human verification and vetting. There is certainly a level of hallucination inherent in the LLMs?

Just one thing I noticed, and would be nice to refactor in future.

When you have time, maybe you can update the AGENT.MD and .cursorrules to give proper instructions on how the codebase structure should be.

IAmVigneswaran avatar Jul 11 '25 00:07 IAmVigneswaran

I have updated XLKit to 1.0.3 to address inconsistencies between XLKit and MarkersExtractor integration.

I have also tweak XLSX Export Utils.swift to reflect the changes.

Now XLKit will handle all column and image sizing tasks.

We don't need to specify any manual cell Width or Hight in XLSX Export Utils.swift. It will be done automatically by XLKit.

We would only adjust Image scaling factor in XLSX Export Utils.swift. The default value in XLKit is 0.5.

However, I felt it would be nice to keep it at 1.0 for MarkersExtractor integration for larger visibility and referencing in real-world workflows. Hence, I have exposed the API to control this in XLSX Export Utils.swift.

try sheet.embedImageAutoSized(
                        imageData, 
                        at: coordinate, 
                        of: workbook, 
                        format: imageFormat,
                        scale: 1.0  // Increase scale factor to 100% (larger visible images)
                    )

16:9

Scale Factor 1 A

9:16

Scale Factor 1 B

IAmVigneswaran avatar Jul 12 '25 06:07 IAmVigneswaran

I have updated XLKit to 1.0.4. I have tried to address several issues and to make the codebase better. 🤞

I tried my best to refactor the entire codebase to make it more "swift-like" and following swift paradigms.

It took several many attempts with Cursor AI to get it working without breaking any functionality, features and also making sure that the build is passing without any errors or warnings. All the APIs are now updated reflected in the Readme.

I have also added CodeQL Analysis to the repo.

I believe it now gives us an extra layer of security review of XLKit's codebase.

I have also updated XLSX Export Utils.swift and ExcelProfile Export.swift adapting with the new XLKit's API changes.

I have also exposed the Cell Header colour and Font Colour. I have set font colour to white against a light-black background.

 var boldFormat = CellFormat()
        boldFormat.fontWeight = .bold
        boldFormat.fontSize = 12
        boldFormat.backgroundColor = "#333333" // Light black (dark gray) background
        boldFormat.fontColor = "#FFFFFF" // White text

16:9

XLKit - 104A

9:16

XLKit - 104B

IAmVigneswaran avatar Jul 14 '25 07:07 IAmVigneswaran

I have now updated XLKit to 1.0.5 which now supports all 6 text alignment that are supported by Excel.

// CellFormat allows customization of font properties, borders, colors, etc.
        var boldFormat = CellFormat()
        boldFormat.fontWeight = .bold
        boldFormat.fontSize = 12
        boldFormat.backgroundColor = "#333333" // Light black (dark gray) background
        boldFormat.fontColor = "#FFFFFF" // White text
        boldFormat.horizontalAlignment = .center // Center text horizontally
        boldFormat.verticalAlignment = .center // Center text vertically
// Set up cell formatting for data rows (centered text)
        var dataFormat = CellFormat()
        dataFormat.horizontalAlignment = .center // Center text horizontally
        dataFormat.verticalAlignment = .center // Center text vertically
        
        // Write data rows with centered formatting
        let dataRows = rows.dropFirst()
        for (rowIndex, rowValues) in dataRows.enumerated() {
            for (columnIndex, value) in rowValues.enumerated() {
                let coordinate = CellCoordinate(row: rowIndex + 2, column: columnIndex + 1).excelAddress
                sheet.setCell(coordinate, string: value, format: dataFormat)
            }
        }

I have set both the horizontal and vertical alignment to .center for a cleaner appearance. These values can be hard-coded? But if users wishes a different alignment, they can easily adjust it directly in Excel.

Text-Aligment

IAmVigneswaran avatar Jul 15 '25 12:07 IAmVigneswaran

I have also checked XLKit against Xcode 26, it seems to build without errors.

IAmVigneswaran avatar Sep 19 '25 01:09 IAmVigneswaran

FYI, I was attempting to merge codebase from main branch to this update-excel branch. I encountered error during build. However, with the help of AI Agent, I was able to build the codebase without any errors. It added async to all the profiles.

IAmVigneswaran avatar Sep 25 '25 04:09 IAmVigneswaran

My stance on integration hasn't changed. This PR can't be merged until the XLKit framework is thoroughly vetted in its entirety by a human, and I won't be in a position to do that for quite some time. If this feature is important, I might suggest getting someone you trust that has experience to vet the framework.

orchetect avatar Sep 25 '25 21:09 orchetect