3

I need to create excel file through code in iPhone i have two array first array contain names of fruit and second array contain image of that fruit.I want to create excel file some thing like that

apple image of apple here mango image of mango here . . . . . . . . . . . . . . . . . .

something like that please help me to create this

Testing Testing
  • 95
  • 2
  • 11
  • 1
    refer to this question [link](http://stackoverflow.com/questions/3587004/is-there-a-library-or-example-for-creating-excel-xlsx-files) – Bonnie Jan 04 '12 at 05:21

1 Answers1

-8

Try following code to generate Excel File:

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.xls", @"userdata"]]; //add our file to the path
[fileManager createFileAtPath:fullPath contents:[xlsString dataUsingEncoding:NSUTF8StringEncoding] attributes:nil]; //finally save the path (file)

Remember, here xlsString is the content of Excel file. you need to create xlsString in such a way that if you insert , (comma) or /t (tab) or other delimiter.. it will go to next cell in Excel File. for Next row use \n (new Line character) in xlsString.

halfer
  • 19,824
  • 17
  • 99
  • 186
DShah
  • 9,768
  • 11
  • 71
  • 127
  • and how to insert image in this excel file? – Testing Testing Jan 09 '12 at 08:26
  • I haven't tried this but you can use `NSData` Representation of the Image. Passing NSData in contents will interpret it... But i am not sure whether Image will be seen when Excel File is open or not... But i will say this should work... Please let me know the result of this .... – DShah Jan 09 '12 at 09:16
  • 2
    This only describes how to write a _file_ (with just about any data) and not an Excel-formatted file (which is in either binary `.xls` or zipped-XML `.xlsx` file). Naming the file `.xls` does not automatically make it an Excel file. – adib Apr 25 '12 at 08:47
  • @adib: Please read my answer carefully i have explained it how to make Excel String. This is accepted answer and you can also try and this will work. – DShah Apr 25 '12 at 12:17
  • 3
    This does not generate an excel file, but a CSV (comma separated values) file. This is basically a flat text file that most spreadsheets can import. (On a windows system, Excel will open it, but not import the rows correctly.) The question about the image shows that your answer is misleading. – Mundi Apr 25 '12 at 22:59