1

足し算や引き算のような単純な数式をlibxlに追加できるようにしたいのですが、その方法がわかりません。簡単な足し算と引き算の式を追加する方法を知りたいだけです。

これが私のコードです:

- (IBAction)createExcel:(id)sender
{
    NSLog(@"createExcel");

    BookHandle book = xlCreateBook(); // use xlCreateXMLBook() for working with xlsx files

    SheetHandle sheet = xlBookAddSheet(book, "Sheet1", NULL);

これらは、数式を変更したい数値です。(100 & 150)

  xlSheetWriteStr(sheet, 1, 0, 100, 0);
  xlSheetWriteStr(sheet, 1, 0, 150, 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 =   self.personFirstnameTextField.text; //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]);


    }


}
4

2 に答える 2

1

「ドキュメントを読む」べきだと不満を漏らした人にとって、主な問題はObjective-Cには例がなく、単純な古いCだけであるということです.

これが私にとってうまくいくものです。列 D に 2 つの行を追加する数式文字列を作成し、それを適用します。

NSString *formula=[NSString stringWithFormat:@"SUM(D%d:D%d)",startRow,endrow]; 
xlSheetWriteFormula(sheet, row, 2, [formula cStringUsingEncoding: NSUTF8StringEncoding], cellFormat);

cellFormat は、目的のフォントと境界線の効果に対して定義した形式です。

人々が抱えている問題は、文字列のエンコーディングにあると思います。

LibXL のライセンスを購入した開発者には、Objective-C のサンプル コードも開発するよう奨励することをお勧めします。それなしで、私たちは数年経ちました。

于 2015-05-18T21:00:23.750 に答える
0

式の追加は簡単です。LibXl for iOS のダウンロードに付属するサンプル アプリの関連する行を次に示します。

xlSheetWriteFormula(sheet, 6, 1, "SUM(B5:B6)", boldFormat);

覚えておくべき唯一の重要なことは、式がObjective-C文字列ではなくC文字列である必要があるということです。ドキュメントの関連箇所は次のとおりです。 http://www.libxl.com/spreadsheet.html#writeFormula

于 2014-08-30T19:54:10.943 に答える