hyperlinkrecord.java

来自「EXCEL read and write」· Java 代码 · 共 529 行 · 第 1/2 页

JAVA
529
字号
/* ====================================================================   Licensed to the Apache Software Foundation (ASF) under one or more   contributor license agreements.  See the NOTICE file distributed with   this work for additional information regarding copyright ownership.   The ASF licenses this file to You under the Apache License, Version 2.0   (the "License"); you may not use this file except in compliance with   the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.==================================================================== */package org.apache.poi.hssf.record;import java.io.IOException;import java.util.Arrays;import org.apache.poi.util.LittleEndian;import org.apache.poi.util.StringUtil;import org.apache.poi.util.HexDump;/** * The <code>HyperlinkRecord</code> wraps an HLINK-record  *  from the Excel-97 format. * Supports only external links for now (eg http://)  * * @author      Mark Hissink Muller <a href="mailto:mark@hissinkmuller.nl >mark&064;hissinkmuller.nl</a> * @author      Yegor Kozlov (yegor at apache dot org) */public class HyperlinkRecord extends Record {    /**     * Link flags     */    protected static final int  HLINK_URL    = 0x01;  // File link or URL.    protected static final int  HLINK_ABS    = 0x02;  // Absolute path.    protected static final int  HLINK_LABEL  = 0x14;  // Has label.    protected static final int  HLINK_PLACE  = 0x08;  // Place in worksheet.    protected final static byte[] STD_MONIKER = {(byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,                                                 (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B };    protected final static byte[] URL_MONIKER = {(byte)0xE0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11,                                                 (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B };    protected final static byte[] FILE_MONIKER = {0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46};    /**     * Tail of a URL link     */    protected final static byte[] URL_TAIL = {0x79, 0x58, (byte)0x81, (byte)0xF4, 0x3B, 0x1D, 0x7F, 0x48, (byte)0xAF, 0x2C,                                              (byte)0x82, 0x5D, (byte)0xC4, (byte)0x85, 0x27, 0x63, 0x00, 0x00, 0x00,                                               0x00, (byte)0xA5, (byte)0xAB, 0x00, 0x00};    /**     * Tail of a file link     */    protected final static byte[] FILE_TAIL = {(byte)0xFF, (byte)0xFF, (byte)0xAD, (byte)0xDE, 0x00, 0x00, 0x00, 0x00,                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};    public final static short sid = 0x1b8;    /**     * First row of the hyperlink     */    private int rwFirst;    /**     * Last row of the hyperlink     */    private int rwLast;    /**     * First column of the hyperlink     */    private short colFirst;    /**     * Last column of the hyperlink     */    private short colLast;    /**     * 16-byte GUID     */    private byte[] guid;    /**     * Some sort of options. Seems to always equal 2     */    private int label_opts;    /**     * Some sort of options for file links.     */    private short file_opts;    /**     * Link options. Can include any of HLINK_* flags.     */    private int link_opts;    /**     * Test label     */    private String label;    /**     * Moniker. Makes sense only for URL and file links     */    private byte[] moniker;    /**     * Link     */    private String address;    /**     * Remaining bytes     */    private byte[] tail;    /**     * Create a new hyperlink     */    public HyperlinkRecord()    {    }    /**     * Return the column of the first cell that contains the hyperlink     *     * @return the 0-based column of the first cell that contains the hyperlink     */   public short getFirstColumn()    {        return colFirst;    }    /**     * Set the column of the first cell that contains the hyperlink     *     * @param col the 0-based column of the first cell that contains the hyperlink     */    public void setFirstColumn(short col)    {        this.colFirst = col;    }    /**     * Set the column of the last cell that contains the hyperlink     *     * @return the 0-based column of the last cell that contains the hyperlink    */    public short getLastColumn()    {        return colLast;    }    /**     * Set the column of the last cell that contains the hyperlink     *     * @param col the 0-based column of the last cell that contains the hyperlink     */    public void setLastColumn(short col)    {        this.colLast = col;    }    /**     * Return the row of the first cell that contains the hyperlink     *     * @return the 0-based row of the first cell that contains the hyperlink     */    public int getFirstRow()    {        return rwFirst;    }    /**     * Set the row of the first cell that contains the hyperlink     *     * @param row the 0-based row of the first cell that contains the hyperlink     */    public void setFirstRow(int row)    {        this.rwFirst = row;    }    /**     * Return the row of the last cell that contains the hyperlink     *     * @return the 0-based row of the last cell that contains the hyperlink     */    public int getLastRow()    {        return rwLast;    }    /**     * Set the row of the last cell that contains the hyperlink     *     * @param row the 0-based row of the last cell that contains the hyperlink     */    public void setLastRow(int row)    {        this.rwLast = row;    }    /**     * Returns a 16-byte guid identifier. Seems to always equal {@link STD_MONIKER}     *     * @return 16-byte guid identifier     */    public byte[] getGuid()    {        return guid;    }    /**     * Returns a 16-byte moniker.     *     * @return 16-byte moniker     */    public byte[] getMoniker()    {        return moniker;    }    /**     * Return text label for this hyperlink     *     * @return  text to display     */    public String getLabel()    {    	if(label == null) return null;    	        int idx = label.indexOf('\u0000');        return idx == -1 ? label : label.substring(0, idx);    }    /**     * Sets text label for this hyperlink     *     * @param label text label for this hyperlink     */     public void setLabel(String label)    {        this.label = label + '\u0000';    }    /**     * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.     *     * @return  the address of this hyperlink     */    public String getAddress()    {    	if(address == null) return null;    	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?