tags:

views:

2225

answers:

4

I have a pretty straightforward excel document in which I need to use the data in an iPhone app. The xls document has 6 columns, 200 plus rows.

I would like to create a plist from the xls document and other than manual copy/paste, is there a means to convert one to the other?

Anyone written a macro on the excel side or a utility (perl, etc) to make such a conversion?

Thanks

John iPhoneDevTips

A: 

Hi John,

I am in the same boat you are... Have you found a solution?

Thanks, Peter

Peter T
So far Peter I've created a csv file that I've opened in Textmate. From there I've written a bunch of macros to add tags and format the data. Not too bad, but way more manual work than I had hoped for. I think a script will be the best solution to convert the csv file to XML.
John
Your answer does not answer the question.
kirk.burleson
+2  A: 

You could do this using a simple formula that you copy and pasted down a column beside each of your 200+ rows.

For example, assuming colum A contains a list of names, and column B contains a matching set of ages you could use a formula such as the following to end up with most of the XML for a plist based dictionary.

=CONCATENATE("<key>Name</key><string>", A1,"</string><key>Age</key><integer>",B1,"</integer>")

You then select all the cells within this new column you can copy and paste into notepad or another text editor to save it as a plist file (you may want to put some hardcoded text into a cell above and below your 200+ rows, in order to get the required tags etc as well...

Christopher Fairbairn
Without a full-fledged script, this approach will definitely save some time. Thanks.
John
this was faster than writing a script for me too. "Excel: the poor man's scripting language" :D
unsorted
+4  A: 

I'm late to the party but I built a desktop utility that will convert CSV to a plist. You can download the binary or use this code, which requires cCSVParse. It uses whatever is in row 0 to create key names, then generates dictionaries for each successive row.

    CSVParser *parser = [CSVParser new];
[parser openFileWithPath:pathAsString];
NSMutableArray *csvContent = [parser parseFile];
[parser closeFile];

if (pathAsString != nil)
{

 NSArray *keyArray = [csvContent objectAtIndex:0];

 NSMutableArray *plistOutputArray = [NSMutableArray array];

 NSInteger i = 0;

 for (NSArray *array in csvContent)
 {



  NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];

  NSInteger keyNumber = 0;

  for (NSString *string in array)
  {

   [dictionary setObject:string forKey:[keyArray objectAtIndex:keyNumber]];

   keyNumber++;

  }

  if (i > 0)
  {
   [plistOutputArray addObject:dictionary];
  }

  i++;

 }

 NSMutableString *mutableString = [NSMutableString stringWithString:pathAsString];
 [mutableString replaceOccurrencesOfString:@".csv" withString:@".plist" options:nil range:NSMakeRange([mutableString length]-4, 4)];

 NSURL *url = [NSURL fileURLWithPath:mutableString];


 [plistOutputArray writeToURL:url atomically:YES];
Danilo Campos
A: 

Hello I just want to know how to make xls file in iphone is it possible or not if so Any kind of related help is appreiated....

umer sufyan
Create a new question. Answers are for answering questions.
kirk.burleson