本文整理汇总了Java中org.apache.poi.ss.usermodel.Hyperlink类的典型用法代码示例。如果您正苦于以下问题:Java Hyperlink类的具体用法?Java Hyperlink怎么用?Java Hyperlink使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Hyperlink类属于org.apache.poi.ss.usermodel包,在下文中一共展示了Hyperlink类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CellSettings
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
public CellSettings(
CellType cellType,
HSSFCellStyle cellStyle,
Object cellValue,
String formula,
Hyperlink link
)
{
this.cellType = cellType;
this.cellStyle = cellStyle;
this.cellValue = cellValue;
this.formula = formula;
this.link = link;
}
示例2: importValues
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
public void importValues(
CellType cellType,
HSSFCellStyle cellStyle,
Object cellValue,
String formula,
Hyperlink link
)
{
this.cellType = cellType;
this.cellStyle = cellStyle;
this.cellValue = cellValue;
this.formula = formula;
this.link = link;
}
示例3: setLink
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的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);
}
示例4: main
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的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..");
}
示例5: setHyperlink
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的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);
}
示例6: removeHyperlink
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
/**
* セルに設定されているハイパーリンクを削除する。
* <p>POIのバージョンによって、{@link Cell#removeHyperlink()}のネイティブのメソッドを呼び出す。
* @since 0.4
* @param cell
* @return true: ハイパーリンクが設定されており削除できた場合。false:ハイパーリンクが設定されていない場合。
* @throws IllegalArgumentException cell == null.
*/
public static boolean removeHyperlink(final Cell cell) {
ArgUtils.notNull(cell, "cell");
final Hyperlink link = cell.getHyperlink();
if(link == null) {
return false;
}
if(AVAILABLE_METHOD_CELL_REMOVE_HYPERLINK) {
cell.removeHyperlink();
return true;
} else {
// 既存のハイパーリンクのURLをクリアし、再設定する。
link.setAddress("");
cell.setHyperlink(link);
return true;
}
}
示例7: getFormula2
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的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);
}
示例8: validateAttributes
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
/**
* Validates the attributes for this <code>Tag</code>. This tag must be
* bodiless. The type must be valid.
*/
@SuppressWarnings("unchecked")
public void validateAttributes() throws TagParseException
{
super.validateAttributes();
if (!isBodiless())
throw new TagParseException("Hyperlink tags must not have a body.");
TagContext context = getContext();
Map<String, Object> beans = context.getBeans();
Map<String, RichTextString> attributes = getAttributes();
String type = AttributeUtil.evaluateStringSpecificValues(attributes.get(ATTR_TYPE), beans, ATTR_TYPE,
Arrays.asList(TYPE_URL, TYPE_EMAIL, TYPE_FILE, TYPE_DOC), TYPE_URL);
if (TYPE_URL.equals(type))
myLinkType = Hyperlink.LINK_URL;
else if (TYPE_EMAIL.equals(type))
myLinkType = Hyperlink.LINK_EMAIL;
else if (TYPE_FILE.equals(type))
myLinkType = Hyperlink.LINK_FILE;
else if (TYPE_DOC.equals(type))
myLinkType = Hyperlink.LINK_DOCUMENT;
myAddress = AttributeUtil.evaluateStringNotNull(attributes.get(ATTR_ADDRESS), beans, ATTR_ADDRESS, null);
myValue = attributes.get(ATTR_VALUE);
}
示例9: process
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的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;
}
示例10: addFooter
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
/**
* Adds the footer.
*/
private void addFooter() {
nextRow();
nextRow();
cell.setCellValue("Produced by gedantic");
Hyperlink link = wb.getCreationHelper().createHyperlink(org.apache.poi.common.usermodel.Hyperlink.LINK_URL);
link.setAddress("http://gedantic.org");
cell.setHyperlink(link);
cell.setCellStyle(styleHyperlink);
}
示例11: writeWorkbook
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
private void writeWorkbook() throws java.io.IOException {
Workbook wb = new XSSFWorkbook();
try {
Sheet sheet = wb.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("cell-1");
cell = row.createCell(1);
cell.setCellValue("cell-2");
cell = row.createCell(2);
cell.setCellValue("cell-3");
XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle();
style.setFillBackgroundColor(new XSSFColor(new org.apache.poi.java.awt.Color(1, 2, 3)));
Hyperlink link = wb.getCreationHelper().createHyperlink(HyperlinkType.URL);
link.setAddress("http://www.google.at");
link.setLabel("Google");
cell.setHyperlink(link);
cell.setCellStyle(style);
sheet.setPrintGridlines(true);
OutputStream stream = openFileOutput("test.xlsx", Context.MODE_PRIVATE);
try {
wb.write(stream);
} finally {
stream.close();
}
} finally {
wb.close();
}
}
示例12: populateRow
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
private void populateRow(Row row, User user) {
UserBinding binding = new UserBinding(user);
int columnIndex = 0;
addTextCell(row, columnIndex++, binding.userName().getSafely());
addTextCell(row, columnIndex++, binding.lastName().getSafely());
addTextCell(row, columnIndex++, binding.firstName().getSafely());
XSSFCreationHelper helper= (XSSFCreationHelper) workbook.getCreationHelper();
XSSFHyperlink emailLink = helper.createHyperlink(Hyperlink.LINK_EMAIL);
String emailAddress = binding.email().getSafely();
emailLink.setAddress("mailto:" + emailAddress);
addLinkToCell(addTextCell(row, columnIndex++, emailAddress), emailLink);
if (binding.active().getSafely()) {
addTextCell(row, columnIndex++, "Oui");
}
else {
addTextCell(row, columnIndex++, "Non");
}
if (binding.creationDate().getSafely() != null) {
addDateCell(row, columnIndex++, binding.creationDate().getSafely());
} else {
addTextCell(row, columnIndex++, "");
}
if (binding.lastUpdateDate().getSafely() != null) {
addDateCell(row, columnIndex++, binding.lastUpdateDate().getSafely());
} else {
addTextCell(row, columnIndex++, "");
}
if (binding.lastLoginDate().getSafely() != null) {
addDateCell(row, columnIndex++, binding.lastLoginDate().getSafely());
} else {
addTextCell(row, columnIndex++, "");
}
}
示例13: setAttachmentURLLinks
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
private Hyperlink setAttachmentURLLinks(SignupAttachment attach) {
Hyperlink hsHyperlink = wb.getCreationHelper().createHyperlink(HyperlinkType.URL);
String link = this.sakaiFacade.getServerConfigurationService().getServerUrl()
+ attach.getLocation();
hsHyperlink.setAddress(link);
hsHyperlink.setLabel(attach.getFilename());
return hsHyperlink;
}
示例14: addBooleanCell
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
public static int addBooleanCell(Sheet sheet, int col, int row, int width, int height,
CellStyle cellStyle, Boolean value, Hyperlink link) {
if (value == null) {
return addBlankCell(sheet, col, row, width, height, cellStyle, link);
}
Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_BOOLEAN, link);
cell.setCellValue(value.booleanValue());
return width;
}
示例15: addLabelCell
import org.apache.poi.ss.usermodel.Hyperlink; //导入依赖的package包/类
public static int addLabelCell(Sheet sheet, int col, int row, int width, int height,
CellStyle cellStyle, String value, Hyperlink link) {
if (value == null) {
return addBlankCell(sheet, col, row, width, height, cellStyle, link);
}
Cell cell = createCell(sheet, col, row, width, height, cellStyle, CELL_TYPE_STRING, link);
cell.setCellValue(value);
return width;
}