Roger
Roger

Reputation: 7610

iOS create Numbers (CSV) file and open?

Anyone know if I create a CSV file, store it in the App's Document folder, if you can open it with Apple's Numbers App?

Any example code for opening the Numbers app, much appreciated.

Thanks.

Upvotes: 0

Views: 1668

Answers (2)

Roger
Roger

Reputation: 7610

OK, after some more digging around i found the answer.

If you implement the QuickLook QLPreviewController (). Then you can pretty easy open a url by:

#import <QuickLook/QuickLook.h>
- (IBAction)previewCSV:(id)sender
{
    [_previewController reloadData]; // triggers the refresh (if your file changes)
    [self presentModalViewController:_previewController animated:YES];
}

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
    return 1;
}

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
    NSLog(@"%s", __FUNCTION__);
    return [NSURL fileURLWithPath:@"path/to/your/app/document/folder/file.csv"];
}

This opens the preview window and you get (for free ;-) a action button (top right) that allows you to open the file with apps that are installed (Email, PDF, Numbers, etc.). You can also print (AirPrint).

Upvotes: 2

WhoaItsAFactorial
WhoaItsAFactorial

Reputation: 3558

Anyone know if I create a CSV file, store it in the App's Document folder, if you can open it with Apple's Numbers App?

No you can't. You could create one and store it to the users iCloud to have it accesible from the Numbers app. Items stored in your applications directories are not accessible by other applications due to the sandbox limitations place by Apple.

Any example code for opening the Numbers app, much appreciated.

Numbers doesn't have a custom URL scheme publically available. Only way to launch the Numbers app from within your own application is by having the user open a compatible file exension (.xls, .numbers, .csv) and choose Numbers as the application to open it.

Upvotes: 0

Related Questions