本文整理汇总了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);
}
示例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..");
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}