iosjxlsxlslib

Clickable link in xls with JXLS


I`m using JXLS v1.0 for creating xls files in my ios-project, and i can not understand how to make a clickable link in some cell in the spreadsheet, is there any way to make this with JXLS, or maybe there is some other free xls framework exists


Solution

  • Ok, i have found the way to resolve link issue for JXLS ios framework.

    The problem was in Objective-C wrapper, there is no methods to add a link in some cell in this wrapper, but there is "hyperLink" method in worksheet class, so the decision was to make a wrapper method in class JXLSWorkSheet(which you can use in your Objective-C code). Implementation looks like: JXLSWorkSheet.h: just add this method in header

        - (void)addLink:(JXLSCell *)cell link:(NSString *)link;
    

    JXLSWorkSheet.m: add implementation body before end statement

    - (void)addLink:(JXLSCell *)cell link:(NSString *)link
      {
        cell_t          *cl;
        unichar         *uniName;
        ustring         uniStr;
        size_t          len;
    
        len = [link length];
    
        uniName = (unichar *)calloc(len+1, sizeof(unichar));
        [link getCharacters:uniName];
        uniStr.assign(uniName);
        free(uniName);
    
        cl = (xlslib_core::cell_t *)cell.cell;
    
        _workSheet->hyperLink(cl, uniStr, uniName);
    

    }

    In my implementation i use the same text as label and the link, add one more parameter to this method, if you want to use some other text as label of the hyperlink in spreadsheet.

    The usage is very simple: you just take the cell you want to contain the url and add link to it. See listing below.

     JXLSCell *cell;
     cell = [workSheet setCellAtRow:rowCount column:1 toString:@"http://stackoverflow.com/"];
     [workSheet addLink:cell link:@"http://stackoverflow.com/"];
    

    I hope it will help you in hyperlink creation in your spreadsheets.