附加csv电子邮件xcode [英] Attach csv to email xcode

查看:151
本文介绍了附加csv电子邮件xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作的csv附件到电子邮件视图。问题是,当我在iPhone上打开csv时,它会将文件显示为不错的列。但是如果我在excel中打开它,它就在一个领域。我需要两列怎么办?试图用逗号分隔字段,但没有工作(显然)。以下行是不正确的,这是我建立我的字符串写入文件的地方

  [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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆