org.apache.poi.ss.usermodel.Cell.setHyperlink()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(342)

本文整理了Java中org.apache.poi.ss.usermodel.Cell.setHyperlink()方法的一些代码示例,展示了Cell.setHyperlink()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cell.setHyperlink()方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Cell
类名称:Cell
方法名:setHyperlink

Cell.setHyperlink介绍

[英]Assign a hyperlink to this cell
[中]为此单元格指定超链接

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

cell.setHyperlink( hyperLink );

代码示例来源:origin: apache/tika

@Override
  public void applyStyleAndValue(int dbColNum, ResultSet resultSet, Cell cell) throws SQLException {
    if (links < MAX_HYPERLINKS) {
      Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(linkType);
      String path = resultSet.getString(dbColNum);
      String address = urlBase+path;
      hyperlink.setAddress(address);
      cell.setHyperlink(hyperlink);
      cell.setCellStyle(style);
      String fName = Paths.get(path).getFileName().toString();
      cell.setCellValue(fName);
      links++;
    } else {
      //silently stop adding hyperlinks
    }
  }
}

代码示例来源:origin: stackoverflow.com

Cell cell = sheet.createRow(0).createCell(0);
cell.setCellValue("Worksheet Link");
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
link.setTextMark("'Target Sheet'!A1");
cell.setHyperlink(link);

代码示例来源:origin: tobyweston/simple-excel

private static void copyCellHyperlink(Cell oldCell, Cell newCell) {
  if (oldCell.getHyperlink() != null)
    newCell.setHyperlink(oldCell.getHyperlink());
}

代码示例来源:origin: tobyweston/simple-excel

@Override
public void update(org.apache.poi.ss.usermodel.Cell cell, Workbook workbook) {
  this.getStyle().applyTo(cell, workbook);
  cell.setCellValue(text);
  cell.setHyperlink(createHyperlink(workbook));
}

代码示例来源:origin: stackoverflow.com

InputStream inp = new FileInputStream("C:/LISA/kundan.xlsx");
Workbook wb = WorkbookFactory.create(inp);

XSSFHyperlink link;
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(5); 
if (cell == null)
  cell = row.createCell(5);
cell.setCellValue("File");
link = (XSSFHyperlink)createHelper.createHyperlink(Hyperlink.LINK_FILE);
String url="C:/LISA/sampletesdt.txt";
link.setAddress(url);
cell.setHyperlink(link);

// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("C:/LISA/kundan.xlsx");
wb.write(fileOut);
fileOut.close();       
  System.out.println("kundan.xlsx written successfully");

代码示例来源:origin: stackoverflow.com

fileLink.setAddress(filePDF.toURI().toString());
cell.setCellValue("link to absolute file URI");
cell.setHyperlink(fileLink);
fileLink.setAddress(relativeURI);
cell.setCellValue("link to relative file URI");
cell.setHyperlink(fileLink);

代码示例来源:origin: stackoverflow.com

Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("AHyperLink");
Cell cell = sheet.createRow(0).createCell(0);
cell.setCellValue("Google");
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress("http://www.google.com/");
cell.setHyperlink(link);

代码示例来源:origin: stackoverflow.com

CellStyle hlink_style = workbook.createCellStyle();
Font hlink_font = workbook.createFont();
hlink_font.setUnderline(Font.U_SINGLE);
hlink_font.setColor(Font.COLOR_RED);
hlink_style.setFont(hlink_font);
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
Cell cell = null;     
cell=row.createCell((short) 1);
cell.setCellValue("Go to Result");
path_f="D://Result.xls";
link.setAddress(path_f);        
cell.setHyperlink(link);    
cell.setCellStyle(hlink_style);

代码示例来源:origin: stackoverflow.com

//creating the cell
   Row row = my_sheet.createRow(0);                
   Cell cell = row.createCell(0);
   //creating helper class
   XSSFWorkbook workbook = new XSSFWorkbook();
   XSSFCreationHelper helper= workbook.getCreationHelper();
   //creating the hyperlink
   link = helper.createHyperlink(HSSFHyperlink.LINK_DOCUMENT);
   link.setAddress("'target_worksheet_name'!A1");
   //optional hyperlink style
   XSSFCellStyle hlinkstyle = workbook.createCellStyle();
   XSSFFont hlinkfont = workbook.createFont();
   hlinkfont.setUnderline(XSSFFont.U_SINGLE);
   hlinkfont.setColor(HSSFColor.BLUE.index);
   hlinkstyle.setFont(hlinkfont);
   //applying the hyperlink to the cell
   cell.setHyperlink(link);

代码示例来源:origin: net.paissad.tools.reqcoco/reqcoco-core

private void configureHyperlinkCell(final Cell cell, final Font cellFont, final CreationHelper creationHelper, String cellContent) {
  cellFont.setUnderline(Font.U_SINGLE);
  cellFont.setColor(IndexedColors.BLUE.getIndex());
  final Hyperlink link = creationHelper.createHyperlink(HyperlinkType.URL);
  link.setAddress(cellContent);
  cell.setHyperlink(link);
}

代码示例来源:origin: org.jxls/jxls-poi

public Object writeToCell(Cell cell, Context context) {
  Workbook workbook = cell.getSheet().getWorkbook();
  CreationHelper createHelper = workbook.getCreationHelper();
  Hyperlink hyperlink = createHelper.createHyperlink(linkType);
  hyperlink.setAddress(address);
  cell.setHyperlink(hyperlink);
  cell.setCellValue(title);
  if( linkStyle == null ){
    linkStyle = cell.getCellStyle();
  }
  cell.setCellStyle(linkStyle);
  return cell;
}

代码示例来源:origin: com.b2international.snowowl/com.b2international.snowowl.datastore.server

/**
 * Creates the index sheet based on the given sheet names.
 * 
 * @param sheetNames
 */
protected void createIndexSheet(final Collection<T> components) {
  final Sheet indexSheet = workbook.createSheet("INDEX");
  final List<T> filteredComponents = Lists.newArrayList(Iterables.filter(components, new Predicate<T>() {
    @Override
    public boolean apply(T input) {
      return isToExport(getComponentId(input));
    }
  }));
  final List<String> sheetNames = extractSheetNamesFromTerminologyComponents(filteredComponents);
  final Row firstRow = indexSheet.createRow(0);
  createCell(firstRow, getIndexSheetHeaderName(), BOLD_STYLE, 0);
  for (int i = 0; i < sheetNames.size(); i++) {
    final String sheetName = getFinalSheetName(i + 1, sheetNames.get(i));
    final Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(XSSFHyperlink.LINK_DOCUMENT);
    hyperlink.setLabel(sheetName);
    hyperlink.setAddress(String.format("'%s'!A1", sheetName));
    final Row row = indexSheet.createRow(i + 1);
    final Cell cell = row.createCell(0);
    cell.setCellValue(sheetName);
    cell.setCellStyle(hyperlinkStyle);
    cell.setHyperlink(hyperlink);
  }
  indexSheet.autoSizeColumn(0);
}

代码示例来源:origin: org.jxls/jxls-poi

private void updateCellGeneralInfo(Cell cell) {
  cell.setCellType( getPoiCellType(targetCellType) );
  if( hyperlink != null ){
    cell.setHyperlink( hyperlink );
  }
  if(comment != null && !PoiUtil.isJxComment(getCellComment())){
    PoiUtil.setCellComment(cell, getCellComment(), commentAuthor, null);
  }
}

代码示例来源:origin: Appendium/objectlabkit

public ExcelCell link(String url, String label) {
  final CreationHelper creationHelper = row().sheet().workbook().poiWorkbook().getCreationHelper();
  final Hyperlink hl = creationHelper.createHyperlink(HyperlinkType.URL);
  hl.setAddress(url);
  hl.setLabel(label);
  currentCell.setCellValue(label);
  currentCell.setHyperlink(hl);
  style(LINK);
  return this;
}

代码示例来源:origin: com.sap.cloud.servicesdk.prov/odata2.core

private void createCellHyperLink(Cell cell, EntityInfo eInfo, Object val, XSSFWorkbook workbook) {
  CellStyle style = workbook.createCellStyle();
  Font font = workbook.createFont();
  font.setUnderline(Font.U_SINGLE);
  font.setColor(HSSFColor.BLUE.index);
  style.setFont(font);
  
  XSSFHyperlink hLink = null;
  if(EMAIL.equals(eInfo.getSemantics())){
    hLink = workbook.getCreationHelper().createHyperlink(HyperlinkType.EMAIL);
    hLink.setAddress("mailto:"+String.valueOf(val));
  }else if(URL.equals(eInfo.getSemantics())){
    hLink = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL);
    hLink.setAddress(String.valueOf(val));
  }
  if(hLink != null){
    cell.setHyperlink(hLink);
    cell.setCellStyle(style);
  }
}

代码示例来源:origin: cn.afterturn/easypoi-base

if (entity.isHyperlink()) {
  row.getCell(cellNum - 1)
      .setHyperlink(dataHandler.getHyperlink(
          row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(),
          value));
if (entity.isHyperlink()) {
  row.getCell(cellNum - 1)
      .setHyperlink(dataHandler.getHyperlink(
          row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(),
          value));

代码示例来源:origin: stackoverflow.com

newCell.setHyperlink(oldCell.getHyperlink());

代码示例来源:origin: com.phloc/phloc-poi

aTarget.setHyperlink (aSource.getHyperlink ());

代码示例来源:origin: com.blackducksoftware.tools/common-framework

private void populateHyperlinkCell(Record record, FieldDef fieldDef,
  Cell cell) throws Exception {
String cellValue = record.getHyperlinkFieldValue(fieldDef.getName())
  .getDisplayText();
cell.setCellValue(cellValue);
// cell style for hyperlinks
// by default hyperlinks are blue and underlined
CellStyle hlink_style = workbook.createCellStyle();
Font hlink_font = workbook.createFont();
hlink_font.setUnderline(Font.U_SINGLE);
hlink_font.setColor(IndexedColors.BLUE.getIndex());
hlink_style.setFont(hlink_font);
// Make it a hyperlink
CreationHelper createHelper = workbook.getCreationHelper();
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress(record.getHyperlinkFieldValue(fieldDef.getName())
  .getHyperlinkText());
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
}

相关文章