1)我正在尝试使用 NSMutableArray(数组数组)创建 CSV 文件,我想使用 MFMailComposeViewController 将其作为邮件附件发送。以下是我为它编写的代码 -
//Export Data to excel
-(NSString*)ExportToExcelClicked
{
dataToSend = @"";
@try {
for(int cntHeader = 0;cntHeader< [NamesArray count];cntHeader++)
{
dataToSend = [NSString stringWithFormat:@"%@%@\n",dataToSend,[NamesArray objectAtIndex:cntHeader]];
dataToSend = [NSString stringWithFormat:@"\nAccount Number,Engine Number,Chasssis Number,Registration,Vehicle Type,Vehicle Model,Vehicle Make\n"];
for(int cntData = 0;cntData< [appDelegate.arrEmailRepossessionDetail count];cntData++)
{
NSMutableArray *thearr = [appDelegate.arrEmailRepossessionDetail objectAtIndex:cntData];
NSString *strVehicleDetail = @"";
strVehicleDetail = [NSString stringWithFormat:@"%@%@,",strVehicleDetail,[thearr objectAtIndex:0]];
strVehicleDetail = [NSString stringWithFormat:@"%@%@,",strVehicleDetail,[thearr objectAtIndex:1]];
strVehicleDetail = [NSString stringWithFormat:@"%@%@,",strVehicleDetail,[thearr objectAtIndex:2]];
strVehicleDetail = [NSString stringWithFormat:@"%@%@,",strVehicleDetail,[thearr objectAtIndex:3]];
strVehicleDetail = [NSString stringWithFormat:@"%@%@,",strVehicleDetail,[thearr objectAtIndex:4]];
strVehicleDetail = [NSString stringWithFormat:@"%@%@,",strVehicleDetail,[thearr objectAtIndex:5]];
strVehicleDetail = [NSString stringWithFormat:@"%@%@,",strVehicleDetail,[thearr objectAtIndex:6]];
dataToSend = [NSString stringWithFormat:@"%@%@\n",dataToSend,strVehicleDetail];
}
dataToSend = [NSString stringWithFormat:@"%@\n\n",dataToSend];
return dataToSend;
}
}
@catch (NSException *exception) {
NSLog(@"NSException: %@", exception.reason);
}
}
邮件附件代码
NSString *strCSVData = [self ExportToExcelClicked];
if ([strCSVData isEqualToString:@""] || strCSVData.length > 0)
{
NSData *dataObj = [strCSVData dataUsingEncoding:NSUTF8StringEncoding];
}
问题是 csv 文件正在为大约 800 到 900 条记录正确创建,但除此之外,应用程序正在崩溃。是否有任何有效的方法是创建 csv 记录。
2)csv文件也在excel中正确显示数据,但在开放式办公室中却没有, 例如:-
Open Office 输出
帐号
19824:38:00
Excel 输出(预期输出) 帐号 019465:021578
不明白为什么OpenOffice没有显示正确的输出。
提前致谢。