• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: I need to convert NSTableView data into something suitable for consumption by a spreadsheet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I need to convert NSTableView data into something suitable for consumption by a spreadsheet


  • Subject: Re: I need to convert NSTableView data into something suitable for consumption by a spreadsheet
  • From: Graham Cox <email@hidden>
  • Date: Wed, 19 Aug 2009 12:41:26 +1000


On 19/08/2009, at 7:27 AM, Michael A. Crawford wrote:

So, I'm looking for suggestions as to the best way to add this feature. I could iterate through the objects in the array and use some posix code to write the data out in CSV format but there must be a better, more Cocoa oriented, way.

Any one have a brilliant idea that leverages Cocoa in a way that will be relatively quick and easy?


I added code to write out data to a tab-delimited file recently, and I did this by adding a simple method to my controller:

- (NSString*) dataAsTabDelimitedString;

Internally it does the following (in my case):

- (NSString*) dataAsTabDelimitedString
{
// returns the current data content of the array as a tab-delimited string. The string is formatted into lines with each line representing a row. Each
// element in the array contributes by supplying its value using the - stringValue method.

unsigned j, k;
NSMutableString* string = [NSMutableString string];
id object;

for( j = 0; j < [self rows]; ++j )
{
for( k = 0; k < [self columns]; ++k )
{
object = [self objectAtRow:j column:k];
[string appendFormat:@"%@\t", [object stringValue]];
}
[string appendString:@"\n"];
}

return string;
}


This relies on each data object returning something useful in its - stringValue method, which depending on what your data is, you might need to write yourself. Some classes have this method already though, like NSNumber.

Once you have the data as a string, you can write it to a file using NSString's -writeToFile:atomically: method.


--Graham


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >I need to convert NSTableView data into something suitable for consumption by a spreadsheet (From: "Michael A. Crawford" <email@hidden>)

  • Prev by Date: I need to convert NSTableView data into something suitable for consumption by a spreadsheet
  • Next by Date: Re: I need to convert NSTableView data into something suitable for consumption by a spreadsheet
  • Previous by thread: I need to convert NSTableView data into something suitable for consumption by a spreadsheet
  • Next by thread: Re: I need to convert NSTableView data into something suitable for consumption by a spreadsheet
  • Index(es):
    • Date
    • Thread