package org.apache.poi.hssf.usermodel;
import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.Sheet;
public class HSSFCreationHelper implements CreationHelper {
private HSSFWorkbook workbook;
public HSSFDataFormat createDataFormat() {
return dataFormat;
}
+
+ public HSSFHyperlink createHyperlink(int type, Sheet sheetFor) {
+ return createHyperlink(type);
+ }
+ public HSSFHyperlink createHyperlink(int type) {
+ return new HSSFHyperlink(type);
+ }
}
==================================================================== */\r
package org.apache.poi.hssf.usermodel;\r
\r
-import org.apache.poi.hssf.record.EscherAggregate;\r
-import org.apache.poi.hssf.record.NoteRecord;\r
-import org.apache.poi.hssf.record.TextObjectRecord;\r
import org.apache.poi.hssf.record.HyperlinkRecord;\r
-import org.apache.poi.ddf.*;\r
-\r
-import java.util.Map;\r
-import java.util.List;\r
-import java.util.Iterator;\r
+import org.apache.poi.ss.usermodel.Hyperlink;\r
\r
/**\r
* Represents an Excel hyperlink.\r
*\r
* @author Yegor Kozlov (yegor at apache dot org)\r
*/\r
-public class HSSFHyperlink {\r
+public class HSSFHyperlink implements Hyperlink {\r
\r
/**\r
* Link to a existing file or web page\r
*\r
* @return the type of this hyperlink\r
*/\r
- protected int getType(){\r
+ public int getType(){\r
return link_type;\r
}\r
}\r
--- /dev/null
+/* ====================================================================
+ 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.ss.usermodel;
+
+public interface Hyperlink {
+ /**
+ * Link to a existing file or web page
+ */
+ public static final int LINK_URL = 1;
+
+ /**
+ * Link to a place in this document
+ */
+ public static final int LINK_DOCUMENT = 2;
+
+ /**
+ * Link to an E-mail address
+ */
+ public static final int LINK_EMAIL = 3;
+
+ /**
+ * Link to a file
+ */
+ public static final int LINK_FILE = 4;
+}
* Creates a new DataFormat instance
*/
DataFormat createDataFormat();
+
+ /**
+ * Creates a new Hyperlink, of the given type,
+ * for the given sheet
+ */
+ Hyperlink createHyperlink(int type, Sheet sheetFor);
}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ 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.ss.usermodel;
+
+/**
+ * Represents an Excel hyperlink.
+ */
+public interface Hyperlink {
+ /**
+ * Link to a existing file or web page
+ */
+ public static final int LINK_URL = 1;
+
+ /**
+ * Link to a place in this document
+ */
+ public static final int LINK_DOCUMENT = 2;
+
+ /**
+ * Link to an E-mail address
+ */
+ public static final int LINK_EMAIL = 3;
+
+ /**
+ * Link to a file
+ */
+ public static final int LINK_FILE = 4;
+
+ /**
+ * Return the row of the first cell that contains the hyperlink
+ *
+ * @return the 0-based row of the cell that contains the hyperlink
+ */
+ public int getFirstRow();
+
+ /**
+ * 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);
+
+ /**
+ * 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();
+
+ /**
+ * 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);
+
+ /**
+ * 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();
+
+ /**
+ * 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);
+
+ /**
+ * Return 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();
+
+ /**
+ * 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);
+
+
+
+ /**
+ * 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();
+
+ /**
+ * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
+ *
+ * @param address the address of this hyperlink
+ */
+ public void setAddress(String address);
+
+ /**
+ * Return text label for this hyperlink
+ *
+ * @return text to display
+ */
+ public String getLabel();
+
+ /**
+ * Sets text label for this hyperlink
+ *
+ * @param label text label for this hyperlink
+ */
+ public void setLabel(String label);
+
+ /**
+ * Return the type of this hyperlink
+ *
+ * @return the type of this hyperlink
+ */
+ public int getType();
+}
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.DataFormat;
+import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.usermodel.Sheet;
public class XSSFCreationHelper implements CreationHelper {
private XSSFWorkbook workbook;
public DataFormat createDataFormat() {
return dataFormat;
}
+
+ public Hyperlink createHyperlink(int type, Sheet sheetFor) {
+ return new XSSFHyperlink(type, (XSSFSheet)sheetFor);
+ }
}
--- /dev/null
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import org.apache.poi.ss.usermodel.Hyperlink;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink;
+
+import org.openxml4j.opc.Package;
+import org.openxml4j.opc.PackagePart;
+
+/**
+ * XSSF Implementation of a Hyperlink.
+ * Note - unlike with HSSF, many kinds of hyperlink
+ * are largely stored as relations of the sheet
+ */
+public class XSSFHyperlink implements Hyperlink {
+ private int type;
+ private XSSFSheet sheet;
+ private CTHyperlink ctHyperlink;
+
+ protected XSSFHyperlink(int type, XSSFSheet sheet) {
+ this.type = type;
+ this.sheet = sheet;
+ this.ctHyperlink = CTHyperlink.Factory.newInstance();
+ }
+ protected XSSFHyperlink(CTHyperlink ctHyperlink, XSSFSheet sheet) {
+ this.sheet = sheet;
+ this.ctHyperlink = ctHyperlink;
+
+ // Figure out the Hyperlink type
+ // TODO
+ }
+
+ /**
+ * Returns the underlying hyperlink object
+ */
+ protected CTHyperlink getCTHyperlink() {
+ return ctHyperlink;
+ }
+
+ /**
+ * Do we need to a relation too, to represent
+ * this hyperlink?
+ */
+ public boolean needsRelationToo() {
+ // TODO
+ return false;
+ }
+
+ /**
+ * Generates the relation if required
+ */
+ protected void generateRelationIfNeeded(Package pkg, PackagePart sheetPart) {
+ // TODO
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public String getAddress() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public String getLabel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setLabel(String label) {
+ // TODO Auto-generated method stub
+ }
+ public void setAddress(String address) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public short getFirstColumn() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+ public int getFirstRow() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+ public short getLastColumn() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+ public int getLastRow() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public void setFirstColumn(short col) {
+ // TODO Auto-generated method stub
+ }
+ public void setFirstRow(int row) {
+ // TODO Auto-generated method stub
+ }
+ public void setLastColumn(short col) {
+ // TODO Auto-generated method stub
+ }
+ public void setLastRow(int row) {
+ // TODO Auto-generated method stub
+ }
+}