Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with initForWritingToCSVFile #49

Open
ijacob opened this issue Jul 25, 2013 · 6 comments
Open

Problem with initForWritingToCSVFile #49

ijacob opened this issue Jul 25, 2013 · 6 comments
Labels

Comments

@ijacob
Copy link

ijacob commented Jul 25, 2013

Hi Dave,

I was assuming when I do something like this:

CHCSVWriter *writer = [[CHCSVWriter alloc] initForWritingToCSVFile:@"export.csv"];

for (Tbl_ExpenseRecords *noteInfo in xpenseData) {
    // NSLog(@"%@",noteInfo.cardname01);
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.expensedate]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.title]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.value]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.currency]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.cardname01]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.name_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.address_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.postalCode_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.city_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.country_]];
    [writer finishLine];
}
[writer closeStream];

It would create a file in the Apps DocumentDirectory but there is no file, am I doing something wrong? Need some advise because I'm not very familiar with the stream method.

Thanks in advance
Ingemar

@davedelong
Copy link
Owner

Off the top of my head, I believe the “CSVFile” parameter needs to be a full path, not just the name of a file.

Dave

On Jul 25, 2013, at 10:01 AM, ijacob [email protected] wrote:

Hi Dave,

I was assuming when I do something like this:

CHCSVWriter *writer = [[CHCSVWriter alloc] initForWritingToCSVFile:@"export.csv"];

for (Tbl_ExpenseRecords *noteInfo in xpenseData) {
// NSLog(@"%@",noteInfo.cardname01);
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.expensedate]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.title]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.value]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.currency]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.cardname01]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.name_]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.address_]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.postalCode_]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.city_]];
[writer writeField:[NSString stringWithFormat:@"%@",noteInfo.country_]];
[writer finishLine];
}
[writer closeStream];
It would create a file in the Apps DocumentDirectory but there is no file, am I doing something wrong? Need some advise because I'm not very familiar with the stream method.

Thanks in advance
Ingemar


Reply to this email directly or view it on GitHub.

@ijacob
Copy link
Author

ijacob commented Jul 25, 2013

I tried this:
NSURL *datapath = [[self applicationDocumentDirectory] URLByAppendingPathComponent:@"export.csv"];
NSString *urlString = [datapath absoluteString];

CHCSVWriter *writer = [[CHCSVWriter alloc] initForWritingToCSVFile:urlString];

worked neither

@davedelong
Copy link
Owner

In that case, I think you're running in to Issue #46. I don't have a quick answer to that right now. I'll perhaps have some time to work on this in a couple of days.

@ijacob
Copy link
Author

ijacob commented Jul 25, 2013

Can you tell me how to do the stream thing to create that file? I went through the documentation and also the Apple docs but it honestly it makes no sense to me

@ijacob
Copy link
Author

ijacob commented Jul 25, 2013

Got it, just needed a few minutes fresh air :)

NSURL *datapath = [[self applicationDocumentDirectory] URLByAppendingPathComponent:@"export.csv"];

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

for (Tbl_ExpenseRecords *noteInfo in xpenseData) {
    // NSLog(@"%@",noteInfo.cardname01);
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.expensedate]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.title]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.value]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.currency]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.cardname01]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.name_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.address_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.postalCode_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.city_]];
    [writer writeField:[NSString stringWithFormat:@"%@",noteInfo.country_]];
    [writer finishLine];
}
[writer closeStream];

NSData *buffer = [output propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
[buffer writeToURL:datapath atomically:NO];

@davedelong
Copy link
Owner

Yep, that will definitely work if you have a small-to-moderate amount of data. If you've got lots and lots and lots of data, you'll notice you're memory usage grow commensurately. Like I said, I'll try and deal with this in a couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants