当前位置: 首页>>代码示例>>Java>>正文


Java CreationHelper.createHyperlink方法代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.CreationHelper.createHyperlink方法的典型用法代码示例。如果您正苦于以下问题:Java CreationHelper.createHyperlink方法的具体用法?Java CreationHelper.createHyperlink怎么用?Java CreationHelper.createHyperlink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.ss.usermodel.CreationHelper的用法示例。


在下文中一共展示了CreationHelper.createHyperlink方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setLink

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
/**
 * Set a link to a cell. The link type should one of {@link Hyperlink}
 * 
 * @param wb
 *            the workbook which contains the cell
 * @param cell
 *            the cell where the link is stored
 * @param address
 *            the cell destination address
 * @param linkType
 *            the type selected among {@link Hyperlink}
 */
public static void setLink(Workbook wb, HSSFCell cell, String address, int linkType) {
	CreationHelper helper = wb.getCreationHelper();
	CellStyle style = wb.createCellStyle();
	Font font = wb.createFont();
	font.setUnderline(Font.U_SINGLE);
	font.setColor(IndexedColors.BLUE.getIndex());
	style.setFont(font);

	Hyperlink link = helper.createHyperlink(linkType);
	link.setAddress(address);
	cell.setHyperlink(link);
	cell.setCellStyle(style);
}
 
开发者ID:turnus,项目名称:turnus,代码行数:26,代码来源:PoiUtils.java

示例2: main

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
public static void main(String[] args)throws Exception
{
	String dataPath = "src/featurescomparison/workingwithdata/hyperlink/data/";
	
	Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
    CreationHelper createHelper = wb.getCreationHelper();

    //cell style for hyperlinks
    //by default hyperlinks are blue and underlined
    CellStyle hlink_style = wb.createCellStyle();
    Font hlink_font = wb.createFont();
    hlink_font.setUnderline(Font.U_SINGLE);
    hlink_font.setColor(IndexedColors.BLUE.getIndex());
    hlink_style.setFont(hlink_font);

    Cell cell;
    Sheet sheet = wb.createSheet("Hyperlinks");
    //URL
    cell = sheet.createRow(0).createCell((short)0);
    cell.setCellValue("URL Link");

    Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
    link.setAddress("http://poi.apache.org/");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //link to a file in the current directory
    cell = sheet.createRow(1).createCell((short)0);
    cell.setCellValue("File Link");
    link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
    link.setAddress("link1.xls");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //e-mail link
    cell = sheet.createRow(2).createCell((short)0);
    cell.setCellValue("Email Link");
    link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL);
    //note, if subject contains white spaces, make sure they are url-encoded
    link.setAddress("mailto:[email protected]?subject=Hyperlinks");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);

    //link to a place in this workbook

    //create a target sheet and cell
    Sheet sheet2 = wb.createSheet("Target Sheet");
    sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");

    cell = sheet.createRow(3).createCell((short)0);
    cell.setCellValue("Worksheet Link");
    Hyperlink link2 = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
    link2.setAddress("'Target Sheet'!A1");
    cell.setHyperlink(link2);
    cell.setCellStyle(hlink_style);

    FileOutputStream out = new FileOutputStream(dataPath + "ApacheHyperlinks.xlsx");
    wb.write(out);
    out.close();
    
    System.out.println("Done..");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:63,代码来源:ApacheHyperlinks.java

示例3: setHyperlink

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
/**
 * セルにハイパーリンクを設定する。
 * 
 * @param cell セル
 * @param type リンクタイプ
 * @param address ハイパーリンクアドレス
 * @see org.apache.poi.common.usermodel.Hyperlink
 */
public static void setHyperlink( Cell cell, HyperlinkType hyperlinkType, String address) {

    Workbook wb = cell.getRow().getSheet().getWorkbook();

    CreationHelper createHelper = wb.getCreationHelper();

    Hyperlink link = createHelper.createHyperlink( hyperlinkType);
    if ( link instanceof HSSFHyperlink) {
        (( HSSFHyperlink) link).setTextMark( address);
    } else if ( link instanceof XSSFHyperlink) {
        (( XSSFHyperlink) link).setAddress( address);
    }

    cell.setHyperlink( link);
}
 
开发者ID:excella-core,项目名称:excella-core,代码行数:24,代码来源:PoiUtil.java

示例4: getFormula2

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
public String getFormula2(Point point, Cell cell) {
    
    if(Utils.equals(comment, "空文字")) {
        return null;
        
    }
    
    // ダミーでリンクも設定する
    final CreationHelper helper = cell.getSheet().getWorkbook().getCreationHelper();
    final Hyperlink link = helper.createHyperlink(Hyperlink.LINK_URL);
    link.setAddress(comment);
    cell.setHyperlink(link);
    
    final int rowNumber = point.y + 1;
    return String.format("HYPERLINK(D%s,\"リンク\"&A%s)", rowNumber, rowNumber);
}
 
开发者ID:mygreen,项目名称:xlsmapper,代码行数:17,代码来源:LinkCellConverterTest.java

示例5: process

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
/**
 * <p>Place the Hyperlink in the Cell, which replaces any other value left
 * behind in the Cell.</p>
 * @return Whether the first <code>Cell</code> in the <code>Block</code>
 *    associated with this <code>Tag</code> was processed.
 */
public boolean process()
{
   TagContext context = getContext();
   Sheet sheet = context.getSheet();
   Block block = context.getBlock();
   int left = block.getLeftColNum();
   int top = block.getTopRowNum();
   // It should exist in this Cell; this Tag was found in it.
   Row row = sheet.getRow(top);
   Cell cell = row.getCell(left);
   SheetUtil.setCellValue(cell, myValue);

   CreationHelper helper = sheet.getWorkbook().getCreationHelper();
   Hyperlink hyperlink = helper.createHyperlink(myLinkType);
   hyperlink.setAddress(myAddress);
   cell.setHyperlink(hyperlink);

   BlockTransformer transformer = new BlockTransformer();
   transformer.transform(context, getWorkbookContext());

   return true;
}
 
开发者ID:rmage,项目名称:gnvc-ims,代码行数:29,代码来源:HyperlinkTag.java

示例6: setHyperlink

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
/** 设置超链接属性
 * @param cell
 * @param processor
 * @param returnVal
 * @param current
 */
private static void setHyperlink(Cell cell, LinkProcessor processor, Object returnVal, Object current) {
	int linkType = 0 ;		
	String prefix = "";
	switch (processor.getLinkType()) {
	case Url:
		linkType = Hyperlink.LINK_URL;
		prefix = "http";
		break;
	case Document:
		linkType = Hyperlink.LINK_DOCUMENT;
		break;
	case Email:
		linkType = Hyperlink.LINK_EMAIL;
		prefix = "mailto:";
		break;
	case File:
		linkType = Hyperlink.LINK_FILE;
		break;
	}
	CreationHelper creationHelper = cell.getSheet().getWorkbook().getCreationHelper();
	org.apache.poi.ss.usermodel.Hyperlink hyperlink = creationHelper.createHyperlink(linkType);
	String address = processor.getLinkAddress(returnVal, current);
	if(!address.startsWith(prefix)){
		if(linkType == Hyperlink.LINK_EMAIL){
			address = prefix +  address;				
		}else{
			address = "http://" + address;
		}
	}
	hyperlink.setAddress(address);
	cell.setHyperlink(hyperlink);
}
 
开发者ID:long47964,项目名称:excel-utils,代码行数:39,代码来源:ExcelExportUtil.java

示例7: toCell

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
@Override
public Cell toCell(final FieldAdaptor adaptor, final URI targetValue, final Object targetBean,
        final Sheet sheet, final int column, final int row,
        final XlsMapperConfig config) throws XlsMapperException {
    
    final XlsConverter converterAnno = adaptor.getSavingAnnotation(XlsConverter.class);
    final XlsFormula formulaAnno = adaptor.getSavingAnnotation(XlsFormula.class);
    final boolean primaryFormula = formulaAnno == null ? false : formulaAnno.primary();
    
    final Cell cell = POIUtils.getCell(sheet, column, row);
    
    // セルの書式設定
    if(converterAnno != null) {
        POIUtils.wrapCellText(cell, converterAnno.wrapText());
        POIUtils.shrinkToFit(cell, converterAnno.shrinkToFit());
    }
    
    URI value = targetValue;
    
    // 既存のハイパーリンクを削除
    // 削除しないと、Excelの見た目上はリンクは変わっているが、データ上は2重にリンクが設定されている。
    POIUtils.removeHyperlink(cell);
    
    if(value != null && !primaryFormula) {
        
        final CreationHelper helper = sheet.getWorkbook().getCreationHelper();
        final Hyperlink link = helper.createHyperlink(Hyperlink.LINK_URL);
        link.setAddress(value.toString());
        cell.setHyperlink(link);
        
        cell.setCellValue(value.toString());
        
    } else if(formulaAnno != null) {
        Utils.setupCellFormula(adaptor, formulaAnno, config, cell, targetBean);
        
    } else {
        cell.setCellType(Cell.CELL_TYPE_BLANK);
    }
    
    return cell;
}
 
开发者ID:mygreen,项目名称:xlsmapper,代码行数:42,代码来源:URICellConverter.java

示例8: toCell

import org.apache.poi.ss.usermodel.CreationHelper; //导入方法依赖的package包/类
@Override
public Cell toCell(final FieldAdaptor adaptor, final CellLink targetValue, final Object targetBean,
        final Sheet sheet, final int column, final int row, final XlsMapperConfig config) throws XlsMapperException {
    
    final XlsConverter converterAnno = adaptor.getSavingAnnotation(XlsConverter.class);
    final XlsFormula formulaAnno = adaptor.getSavingAnnotation(XlsFormula.class);
    final boolean primaryFormula = formulaAnno == null ? false : formulaAnno.primary();
    
    final Cell cell = POIUtils.getCell(sheet, column, row);
    
    // セルの書式設定
    if(converterAnno != null) {
        POIUtils.wrapCellText(cell, converterAnno.wrapText());
        POIUtils.shrinkToFit(cell, converterAnno.shrinkToFit());
    }
    
    final CellLink value = targetValue;
    
    // 既存のハイパーリンクを削除
    // 削除しないと、Excelの見た目上はリンクは変わっているが、データ上は2重にリンクが設定されている。
    POIUtils.removeHyperlink(cell);
    
    if(value != null && Utils.isNotEmpty(value.getLink()) && !primaryFormula) {
        final CreationHelper helper = sheet.getWorkbook().getCreationHelper();
        final LinkType type = POIUtils.judgeLinkType(value.getLink());
        final Hyperlink link = helper.createHyperlink(type.poiType());
        
        link.setAddress(value.getLink());
        cell.setHyperlink(link);
        cell.setCellValue(value.getLabel());
        
    } else if(value != null && Utils.isNotEmpty(value.getLabel()) && !primaryFormula) {
        // 見出しのみ設定されている場合
        cell.setCellValue(value.getLabel());
        
    } else if(formulaAnno != null) {
        Utils.setupCellFormula(adaptor, formulaAnno, config, cell, targetBean);
        
    } else {
        cell.setCellType(Cell.CELL_TYPE_BLANK);
    }
    
    return cell;
}
 
开发者ID:mygreen,项目名称:xlsmapper,代码行数:45,代码来源:CellLinkCellConverter.java


注:本文中的org.apache.poi.ss.usermodel.CreationHelper.createHyperlink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。