2014-03-02 3 views
1

내가 묻는 질문을 더 잘 이해할 수 있도록 만든 그림을 봅니다. 내가 엑셀 ​​정보의 모든 IOS를 가지고 웹 사이트는 여기구문 분석에서 Excel 파일로 데이터를 저장하고 전자 메일로 보내기

http://www.appcoda.com/ios-programming-save-data-parse-cloud-tutorial/

을 그리고 :

enter image description here 또한, 여기에 내가 구문 분석하는 텍스트 필드의 구원을 얻었다 튜토리얼입니다

http : // libxl.com/download.html

구문 분석 할 데이터를 저장하고 표시 할 수도 있습니다. 또한 수동으로 .xls (Excel) 파일을 만들어 이메일을 통해 다른 사람에게 보낼 수도 있습니다. 지금해야 할 일은 .xls 파일에 내가 파싱 한 데이터를 채우는 것입니다. 여기

이 프로젝트는 거의

뭐든지 도움이 될 것입니다 난 그냥 도움이 마지막 비트를 필요로 이루어집니다

// 
// DataViewController.m 
// libxl-example 
// 
// Created by dmytro on 12/25/12. 
// Copyright (c) 2012 xlware. All rights reserved. 
// 

#import "DataViewController.h" 

#include "LibXL/libxl.h" 
#import "RecipeBookViewController.h" 
#import "RecipeDetailViewController.h" 
#import "Recipe.h" 

@interface RecipeBookViewController() 

@end 

@implementation RecipeBookViewController { 

} 

- (id)initWithCoder:(NSCoder *)aCoder 
{ 
    self = [super initWithCoder:aCoder]; 
    if (self) { 
     // Custom the table 

     // The className to query on 
     self.parseClassName = @"Recipe"; 

     // The key of the PFObject to display in the label of the default cell style 
     self.textKey = @"name"; 

     // Whether the built-in pull-to-refresh is enabled 
     self.pullToRefreshEnabled = YES; 

     // Whether the built-in pagination is enabled 
     self.paginationEnabled = NO; 

     // The number of objects to show per page 
     //self.objectsPerPage = 10; 
    } 
    return self; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(refreshTable:) 
               name:@"refreshTable" 
               object:nil]; 
} 

- (void)refreshTable:(NSNotification *) notification 
{ 
    // Reload the recipes 
    [self loadObjects]; 
} 


- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"refreshTable" object:nil]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (PFQuery *)queryForTable 
{ 
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; 

    // If no objects are loaded in memory, we look to the cache first to fill the table 
    // and then subsequently do a query against the network. 
    /* if ([self.objects count] == 0) { 
    query.cachePolicy = kPFCachePolicyCacheThenNetwork; 
    }*/ 

    // [query orderByAscending:@"name"]; 

    return query; 
} 



// Override to customize the look of a cell representing an object. The default is to display 
// a UITableViewCellStyleDefault style cell with the label being the first key in the object. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object 
{ 
    static NSString *simpleTableIdentifier = @"RecipeCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
    } 

    // Configure the cell 
    PFFile *thumbnail = [object objectForKey:@"imageFile"]; 
    PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100]; 
    thumbnailImageView.image = [UIImage imageNamed:@"placeholder.jpg"]; 
    thumbnailImageView.file = thumbnail; 
    [thumbnailImageView loadInBackground]; 

    UILabel *nameLabel = (UILabel*) [cell viewWithTag:101]; 
    nameLabel.text = [object objectForKey:@"name"]; 

    UILabel *prepTimeLabel = (UILabel*) [cell viewWithTag:102]; 
    prepTimeLabel.text = [object objectForKey:@"prepTime"]; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Remove the row from data model 
    PFObject *object = [self.objects objectAtIndex:indexPath.row]; 
    [object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { 
     [self refreshTable:nil]; 
    }]; 
} 

- (void) objectsDidLoad:(NSError *)error 
{ 
    [super objectsDidLoad:error]; 

    NSLog(@"error: %@", [error localizedDescription]); 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) { 
     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     RecipeDetailViewController *destViewController = segue.destinationViewController; 

     PFObject *object = [self.objects objectAtIndex:indexPath.row]; 
     Recipe *recipe = [[Recipe alloc] init]; 
     recipe.name = [object objectForKey:@"name"]; 
     recipe.imageFile = [object objectForKey:@"imageFile"]; 
     recipe.prepTime = [object objectForKey:@"prepTime"]; 
     recipe.ingredients = [object objectForKey:@"ingredients"]; 
     destViewController.recipe = recipe; 

    } 
} 


@end 
@interface DataViewController() 
@end 
@implementation DataViewController 

- (void)dealloc 
{ 

} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    self.dataLabel.text = [self.dataObject description]; 
} 

- (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, "Hello World !", 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:@"out.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:@"out.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 = @"out.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)mailComposeController:(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 

내하는 .m 파일 내 .H 파일 여기

// DataViewController.h 
// libxl-example 
// 
// Created by dmytro on 12/25/12. 
// Copyright (c) 2012 xlware. All rights reserved. 
// 

#import <UIKit/UIKit.h> 
#import <MessageUI/MessageUI.h> 
#import <Parse/Parse.h> 
@interface DataViewController : UIViewController <MFMailComposeViewControllerDelegate> 

@property (strong, nonatomic) IBOutlet UILabel *dataLabel; 
@property (strong, nonatomic) id dataObject; 

- (IBAction)createExcel:(id)sender; 



@end 

입니다 ! 미리 감사드립니다!

답변

0

// 여기에을 편집하면 PFQuery를 사용하여 Parse.com에서 데이터를 검색 할 수 있습니다. 이 https://parse.com/docs/ios_guide#objects-retrieving/iOS을 따르고 데이터 구조에 맞게 수정하십시오.

데이터 구조가 확실하지 않은 경우. 구문 분석에 로그인하여 앱의 데이터 브라우저로 이동하십시오. https://parse.com/apps/YOUR_APP_NAME/collections과 같아야합니다. 필드를 클릭하고 JSON 데이터를 찾으십시오. PFQuery는 NSDictionary를 얻을 것이다. NSString을 사용하여 원하는 데이터를 검색 할 수 있습니다.

+0

내 코드를 다시 살펴보고 싶다면보기 컨트롤러에 반대되는 Excel 스프레드 시트로 구문 분석 필드를 내보내는 것에 대한 정보를 제게 제공해 주시면 답변을 완료했음을 알 수 있습니다. – user3371917

+0

queryForTable이 self.objects와 연결되는 방법을 찾을 수 없지만 prepareForSegue :: method를 보면 모든 구문 분석 데이터가 self.objects에 있어야한다고 가정합니다. http : // libxl.com/download.html을 사용하여 데이터 (self.objects)를 Excel 셀로 변환하는 방법을 알고 싶습니까? –

+0

쉼표를 구분 기호로 사용하여 파일을 생성하고 * .xls 파일로 이름을 지정하는 것이 좋습니다. 그것은 엑셀 파일로 열립니다. –

관련 문제