I having problem using CHCSVwriter
to export my arrays to CSV or excel file.
I have several Arrays
that are in Persian language
( it's localized and this must be UTF-8, at least in windows ).
With using CHCSVWriter ( thanks, Dave ) I am able to do export my arrays into CSV file BUT not with default settings.
Because of my array encodings ( UTF8 Did not work , I don't know why !! ) but changing CHCSVwriter.m I am able to write the files with my localized language.
I have a strange Problem :
1- If I use NSUTF8StringEncoding
then开发者_如何学C I have one standard Comma separated CSV file that is able to be opened with Excel very well with correct columns separation BUT table cells are in unknown encoding ( I am using persian language)
2- If I use NSUTF16StringEncoding
then I have a CSV file that whole columns of each row writes into one column ! but the language and encoding is right ! the strange thing is that commas are NOT detectable for excel and it's open a table with just One column that each row contains whole columns that I designed to be separated with commas that are existing there !!!
Also, I have another problem that I don't find a way to set encoding for CHCSVWriter and I have to change it manually from CHCSVWriter.m file !
part of CHCSVWriter.m:- (void)_writeString:(NSString *)string {
// if (encoding == 0) {
// encoding = NSUTF8StringEncoding;
encoding = NSUTF16StringEncoding;
//}
And part of my code :
NSString * tempFileName = [NSString stringWithFormat:@"sellExport.csv"];
NSString * tempFile =[NSHomeDirectory() stringByAppendingPathComponent:tempFileName];
NSLog(@"Writing to file: %@", tempFile);
error = nil;
CHCSVWriter *sellExporting = [[CHCSVWriter alloc] initWithCSVFile:tempFile atomic:NO];
[sellExporting writeLine];
for (int i = 0; i<=[purchaseCodes count] ; i++) {
[sellExporting writeLineOfFields:[purchaseCodes objectAtIndex:i],[purchaseDates objectAtIndex:i],[purchaseCarBrands objectAtIndex:i],[purchaseCarSystems objectAtIndex:i],[purchaseCarModels objectAtIndex:i],[purchaseCarColors objectAtIndex:i],[purchaseCarChassis objectAtIndex:i],[purchaseCustomerNames objectAtIndex:i],[purchaseSharedNames objectAtIndex:i],[purchaseTotals objectAtIndex:i],[sellCodes objectAtIndex:i],[sellCustomerNames objectAtIndex:i],[sellDates objectAtIndex:i],[sellTotals objectAtIndex:i],[sellProfits objectAtIndex:i],[sellShareProfits objectAtIndex:i],nil];
}
[sellExporting closeFile];
[sellExporting release];
As nobody could resolve my problem,
I found that Unicode encoding is not very well supported with Microsoft Excell ( mac ).
In other hand, because of this fact that I'm using Perisan language for my data entries so I have to use NSUTF16StringEncoding
( why UTF8StringEncoding
didn't work ? I don't know !! ) and when I open the .csv file I have all my data in just one column ( I have 16 column ) and Microsoft Excell can not detect comma (,) as separation delimiter !!!
Anyway, now, I am able to open the UTF16 Encoded CSV file using NeoOffice or OpenOffice that well supported Unicode .csv files without any problem !
So, this all about Microsft not Dave deLong's CHCSVWriter. ( thank you Dave, Again )
this my 5th question that I solved by myself !!!
Thank you all anyway.
精彩评论