Creating Excel (.xlsx) files in Cocoa

前端 未结 3 382
离开以前
离开以前 2020-12-05 11:09

I\'m writing a Cocoa application and I\'m trying to export to the Excel XML format (ISO/IEC 29500-1) which is basically a zip file with a bunch of XML files in it named with

相关标签:
3条回答
  • 2020-12-05 11:35

    I've worked with the OpenOffice API and it works great. I would suggest you work with that to create your Excel files. If you don't have time time/patience to do that, a workaround could be to have 2 links to export files, the XLSX version hack for the Excels of the world and then a separate exported CSV file for the Numbers application.

    0 讨论(0)
  • 2020-12-05 11:50

    Wikipedia offers some links to libraries, which would probably give you a good start.

    If the Office Open XML format isn't a requirement, and you don't need overly complex files exported, I also suggest checking saving the files as stylesheet formatted HTML which Excel can also read. A simple way to learn how to format the HTML you want as a spreadsheet is creating the file in Excel, and saving it as HTML.

    0 讨论(0)
  • 2020-12-05 11:51

    How about encapsulating HTML table in Excel file? I have checked that this works and I can open it with Excel.

    NSURL * documentsDirectory = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].lastObject;
    NSURL *file = [documentsDirectory URLByAppendingPathComponent:@"contacts.xls"];
    NSString* string = @"<table><tr><td>FOO</td><td>BAR</td></tr></table>";
    [string writeToFile:file.path atomically:YES encoding:NSUTF8StringEncoding error:nil];
    
    0 讨论(0)
提交回复
热议问题