我需要通过 iPhone 中的代码创建 excel 文件我有两个数组,第一个数组包含水果名称,第二个数组包含该水果的图像。我想创建类似这样的 excel 文件
apple 这里是苹果的图片 芒果图片芒果在这里 . . . . . . . . . . . . . . . . . .
类似的东西请帮我创建这个
最佳答案
尝试使用以下代码生成 Excel 文件:
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)
记住,这里的xlsString是Excel文件的内容。您需要以这样的方式创建 xlsString:如果您插入 ,(逗号)或/t(制表符)或其他定界符。它将转到 Excel 文件中的下一个单元格。对于下一行,在 xlsString 中使用\n(换行符)。
关于iphone - 通过代码创建excel文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8722030/