通过邮件编辑器使用CHCSVParser(由Dave DeLong)将核心数据导出到csv中, [英] Exporting the core data into csv via mail composer using CHCSVParser(by Dave DeLong)

查看:125
本文介绍了通过邮件编辑器使用CHCSVParser(由Dave DeLong)将核心数据导出到csv中,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CHCSVParser(Dave DeLong)通过邮件编辑器将核心数据导出到csv中,但是问题是它使用核心数据表名而不是行值。

I am exporting the core data into csv via mail composer using CHCSVParser(by Dave DeLong) but the issue is that it is taking the core data table name instead of row values.

此外,我希望他们在一个特定的order.eglike下水道,井1,井2

Also, i want them in a particular order.e.g.like "Sewer No", "Manhole 1", "Manhole 2"

我使用:

//从核心数据获取数据

//fetching the data from the core data

NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription
                                          entityForName:@"Input_Details" inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc] init];


request.predicate = [NSPredicate predicateWithFormat:@"rs_Input_project.name = %@", self.projectObject.name];


[request setEntity:entityDescription];
request.resultType = NSDictionaryResultType;

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sewer_No" ascending:YES];
[request setSortDescriptors:@[sortDescriptor]];

NSError *error;

NSArray *fetchedObjects = [moc executeFetchRequest:request error:&error];



 //creating a csv CHCSVWriter
NSOutputStream *output = [NSOutputStream outputStreamToMemory];
CHCSVWriter *writer = [[CHCSVWriter alloc] initWithOutputStream:output encoding:NSUTF8StringEncoding delimiter:','];

for (id object in fetchedObjects)
{
    if ([object conformsToProtocol:@protocol(NSFastEnumeration)])
    {
        [writer writeLineOfFields:object];

    }
}

[writer closeStream];


NSData *buffer = [output propertyForKey:NSStreamDataWrittenToMemoryStreamKey];

NSString *string = [[NSString alloc] initWithData:buffer encoding:NSUTF8StringEncoding];

NSLog(@"Length of Buffer:%d Error:%@",[buffer length],[error localizedDescription]);

if ( [MFMailComposeViewController canSendMail] )
{


    MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
    mailComposer.mailComposeDelegate = self;

    NSData *myData = [string dataUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"myData csv:%@",myData);
     NSLog(@"string csv:%@",string);

// Fill out the email body text
    NSString *emailBody = @"Sewer_Output";
    [mailComposer setMessageBody:emailBody isHTML:NO];

    //attaching the data and naming it Sewer_Output
    [mailComposer addAttachmentData:myData  mimeType:@"text/cvs" fileName:@"Sewer_Output.csv"];

[self presentModalViewController:mailComposer animated:YES];
}


推荐答案

for (ObjectClass *object in fetchedObjects)
{
    if ([object conformsToProtocol:@protocol(NSFastEnumeration)])
    {
        [writer writeField:object.text];
        [writer writeField:[NSString stringWithFormat:@"%i",object.sewer_No.intValue]];
        [writer finishLine];
    }
}

这篇关于通过邮件编辑器使用CHCSVParser(由Dave DeLong)将核心数据导出到csv中,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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