I am using core data and libxl. Whenever i implement a Core Data string into libxl it gives me the error "incompatible pointer types passing nsstring to parameter of type const char"
Dont know why...
Here is my code, namelabel.text is the core data NSString that produces the error incompatible pointer types passing nsstring to parameter of type const char.
- (IBAction)createExcel:(id)sender
{
NSLog(@"createExcel");
BookHandle book = xlCreateBook(); // use xlCreateXMLBook() for working with xlsx files
SheetHandle sheet = xlBookAddSheet(book, "Sheet1", NULL);
xlSheetWriteStr(sheet, 1, 1, namelabel.text, 0);
xlSheetWriteNum(sheet, 4, 1, 1000, 0);
xlSheetWriteNum(sheet, 5, 1, 2000, 0);
FontHandle font = xlBookAddFont(book, 0);
xlFontSetColor(font, COLOR_RED);
xlFontSetBold(font, true);
FormatHandle boldFormat = xlBookAddFormat(book, 0);
xlFormatSetFont(boldFormat, font);
xlSheetWriteFormula(sheet, 6, 1, "SUM(B5:B6)", boldFormat);
FormatHandle dateFormat = xlBookAddFormat(book, 0);
xlFormatSetNumFormat(dateFormat, NUMFORMAT_DATE);
xlSheetWriteNum(sheet, 8, 1, xlBookDatePack(book, 2011, 7, 20, 0, 0, 0, 0), dateFormat);
xlSheetSetCol(sheet, 1, 1, 12, 0, 0);
NSString *documentPath =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [documentPath stringByAppendingPathComponent:@"insuranceclaim.xls"];
xlBookSave(book, [filename UTF8String]);
xlBookRelease(book);
if (![MFMailComposeViewController canSendMail]) {
//Show alert that device cannot send email, this is because an email account hasn't been setup.
}
else {
//**EDIT HERE**
//Use this to retrieve your recently saved file
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [documentPath stringByAppendingPathComponent:@"insuranceclaim.xls"];
//**END OF EDIT**
NSString *mimeType = @"application/vnd.ms-excel"; //This should be the MIME type for els files. May want to double check.
NSData *fileData = [NSData dataWithContentsOfFile:filename];
NSString *fileNameWithExtension = @"insuranceclaim.xls"; //This is what you want the file to be called on the email along with it's extension:
//If you want to then delete the file:
NSError *error;
if (![[NSFileManager defaultManager] removeItemAtPath:filename error:&error])
NSLog(@"ERROR REMOVING FILE: %@", [error localizedDescription]);
//Send email
MFMailComposeViewController *mailMessage = [[MFMailComposeViewController alloc] init];
[mailMessage setMailComposeDelegate:self];
[mailMessage addAttachmentData:fileData mimeType:mimeType fileName:fileNameWithExtension];
[self presentViewController:mailMessage animated:YES completion:nil];
}
}
- (void)mailComposeControllerone:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(@"Mail not sent.");
break;
}
[controller dismissViewControllerAnimated:YES completion:nil];
}
@end
To convert to const char *
try
const char *s = [namelabel.text UTF8String];
and pass it wherever you need to.
Edit:
xlSheetWriteStr(sheet, 1, 1, [namelabel.text UTF8String], 0);