附加csv电子邮件xcode [英] Attach csv to email xcode
问题描述
[csv appendFormat :@\\\
\表的总数:%@ \,对象总数:%d,\\\
\\\
,filteredTables,filteredTableRows]
[csv appendFormat:@\\\
\%@ \,%@,,key,value];
这是我的代码(复制,似乎是标准的)写入文件
BOOL res = [csv writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:& error];
if(!res){
NSLog(@写入文件%@时出错%@,[error localizedDescription],fileName);
}
为什么不按照我想要的方式工作,我如何将字符串分成不同的列?谢谢!
我自己的问题的解决方案很简单(如果有人碰巧碰到过我的帖子):
我以分号替换,,所以
[csv appendFormat:@\\\
%@;%@ ,,关键,价值];
(不需要\\因为它已经是字符串)
它现在适用于excel,但是不能在iPhone / iPad上正确显示,因为现场分隔符有一个,。
但是我的问题解决了。 p>
I got a working csv attachment to an email view. The problem is, that when I open the csv on the iPhone it displays the file really nice into separate columns. But if I open it in excel it's all in one field. I need two columns how can I do that? Tried to separate fields with commas but that didn't work (obviously). The following lines are the ones that must be incorrect somehow, this is where I build my string to write to file
[csv appendFormat:@"\n\"Total # of tables: %@\",Total # of objects: %d, \n \n", filteredTables,filteredTableRows]
[csv appendFormat:@"\n\"%@\",%@,", key, value];
And this is my code (copied and seems to be standard) for the writing to file
BOOL res = [csv writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (!res) {
NSLog(@"Error %@ while writing to file %@", [error localizedDescription], fileName);
}
Why is it not working the way I want it to, and how do I get the string to separate into different columns? Thanks!
The solution to my own problem was quite simple (if anyone ever happens to come across my post): I replaced the "," by a semicolon so
[csv appendFormat:@"\n%@ ;%@,", key, value];
(don't need the \" since it*'s a string already). It works with excel now but does not display correctly on iPhones/iPads anymore because the field separator there is a ",".
But my problem is solved.
这篇关于附加csv电子邮件xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!