protected ArrayList formats = new ArrayList();
protected ArrayList names = new ArrayList();
+
+ protected ArrayList hyperlinks = new ArrayList();
protected int numxfs = 0; // hold the number of extended format records
protected int numfonts = 0; // hold the number of font records
Workbook retval = new Workbook();
ArrayList records = new ArrayList(recs.size() / 3);
- for (int k = 0; k < recs.size(); k++) {
+ int k;
+ for (k = 0; k < recs.size(); k++) {
Record rec = ( Record ) recs.get(k);
if (rec.getSid() == EOFRecord.sid) {
// retval.records.supbookpos = retval.records.bspos + 1;
// retval.records.namepos = retval.records.supbookpos + 1;
// }
+
+ // Look for other interesting values that
+ // follow the EOFRecord
+ for ( ; k < recs.size(); k++) {
+ Record rec = ( Record ) recs.get(k);
+ switch (rec.getSid()) {
+ case HyperlinkRecord.sid:
+ retval.hyperlinks.add(rec);
+ break;
+ }
+ }
retval.records.setRecords(records);
return null;
}
+ public List getHyperlinks()
+ {
+ return hyperlinks;
+ }
+
public List getRecords()
{
return records.getRecords();
limitations under the License.
==================================================================== */
-/*
- * HyperlinkRecord
- *
- * Created on February 20th, 2005, 16:00 PM
- */
package org.apache.poi.hssf.record;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
-/**The <code>HyperlinkRecord</code> wraps an HLINK-record from the Excel-97 format
+/**
+ * The <code>HyperlinkRecord</code> wraps an HLINK-record
+ * from the Excel-97 format.
+ * Supports only external links for now (eg http://)
*
- * @version 20-feb-2005
* @author Mark Hissink Muller <a href="mailto:mark@hissinkmuller.nl >mark&064;hissinkmuller.nl</a>
- *
- * Version by date changes
- * ------- --- -------- -------
- * 0.1 MHM 20022005 draft version; need to fix serialize and getRecordSize()
- *
- * 1.0 MHM 20022005 (Initial version; only aims to support internet URLs (e.g. http://www.example.com) ) - added 31-08-07: AFAIK, this file is NOT functional/working. Please let me know if you turn it into something that does work.
*/
public class HyperlinkRecord extends Record implements CellValueRecordInterface
{
public final static short sid = 0x1b8;
- private int field_1_row;
- private short field_2_column;
- private short field_3_xf_index;
- private short field_4_unknown;
+ private short field_1_unknown;
+ private int field_2_row;
+ private short field_3_column;
+ private short field_4_xf_index;
private byte[] field_5_unknown;
private int field_6_label_opts;
private int field_7_url_len;
*/
public short getColumn()
{
- return field_2_column;
+ return field_3_column;
}
/* (non-Javadoc)
*/
public int getRow()
{
- return field_1_row;
+ return field_2_row;
}
/* (non-Javadoc)
*/
public short getXFIndex()
{
- return field_3_xf_index;
+ return field_4_xf_index;
}
/* (non-Javadoc)
*/
public void setColumn(short col)
{
- this.field_2_column = col;
+ this.field_3_column = col;
}
*/
public void setRow(int row)
{
- this.field_1_row = row;
+ this.field_2_row = row;
}
*/
public void setXFIndex(short xf)
{
- this.field_3_xf_index = xf;
+ this.field_4_xf_index = xf;
}
// if(1==1)
// throw new IllegalArgumentException("");
- field_1_row = in.readUShort();
- field_2_column = in.readShort();
- field_3_xf_index = in.readShort();
- field_4_unknown = in.readShort();
+ field_1_unknown = in.readShort();
+ field_2_row = in.readUShort();
+ field_3_column = in.readShort();
+ field_4_xf_index = in.readShort();
// Next up is 16 bytes we don't get
field_5_unknown = new byte[16];
LittleEndian.putShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset,
( short )(getRecordSize()-4));
- LittleEndian.putUShort(data, 4 + offset, field_1_row);
- LittleEndian.putShort(data, 6 + offset, field_2_column);
- LittleEndian.putShort(data, 8 + offset, field_3_xf_index);
- LittleEndian.putShort(data, 10 + offset, field_4_unknown);
+ LittleEndian.putShort(data, 4 + offset, field_1_unknown);
+ LittleEndian.putUShort(data, 6 + offset, field_2_row);
+ LittleEndian.putShort(data, 8 + offset, field_3_column);
+ LittleEndian.putShort(data, 10 + offset, field_4_xf_index);
offset += 12;
for(int i=0; i<field_5_unknown.length; i++) {
private byte[] data = new byte[] {
-72, 1, 110, 0,
- // Row, col, xf, ??
+ // ??, Row, col, xf
6, 0, 3, 0, 2, 0, 2, 0,
// ??
private byte[] data2 = new byte[] {
-72, 1, -126, 0,
- // Row, col, xf, ??
+ // ??, Row, col, xf
2, 0, 2, 0, 4, 0, 4, 0,
// ??
HyperlinkRecord r = new HyperlinkRecord(inp);
- assertEquals(6, r.getRow());
- assertEquals(3, r.getColumn());
+ assertEquals(3, r.getRow());
+ assertEquals(2, r.getColumn());
assertEquals(2, r.getXFIndex());
assertEquals("L,A", r.getLabel());
HyperlinkRecord r = new HyperlinkRecord(inp);
assertEquals(2, r.getRow());
- assertEquals(2, r.getColumn());
+ assertEquals(4, r.getColumn());
assertEquals(4, r.getXFIndex());
assertEquals("Stacie@ABC.com", r.getLabel());
package org.apache.poi.hssf.usermodel;
-import junit.framework.TestCase;
-
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.hssf.model.Sheet;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.EOFRecord;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.util.HSSFColor;
-import org.apache.poi.util.TempFile;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-
-import java.util.List;
-import java.util.Iterator;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.model.Sheet;
+import org.apache.poi.hssf.record.HyperlinkRecord;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.TempFile;
/**
* Tests various functionity having to do with HSSFCell. For instance support for
in.close();
}
- public void testWithHyperlinks() throws Exception {
+ public void BROKENtestWithHyperlink() throws Exception {
String dir = System.getProperty("HSSF.testdata.path");
File f = new File(dir, "WithHyperlink.xls");
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(f));
+
+ assertEquals(3, wb.getNumberOfSheets());
+
+ // Find our hyperlink record, and check they're
+ // as we'd expect
+ List records = wb.getWorkbook().getHyperlinks();
+ assertEquals(1, records.size());
+
+ HyperlinkRecord link = (HyperlinkRecord)
+ records.get(0);
+ assertNotNull(link);
+
+ // Is in A5
+ assertEquals("Foo", link.getLabel());
+ assertEquals("http://poi.apache.org/", link.getUrlString());
+ assertEquals(4, link.getRow());
+ assertEquals(0, link.getColumn());
+
+ // Now check at the HSSFCell level
+ assertEquals(3, wb.getNumberOfSheets());
+
+ HSSFSheet s = wb.getSheetAt(1);
+ HSSFRow r = s.getRow(4);
+ assertNotNull(r);
+ HSSFCell c = r.getCell((short)0);
+ }
+
+ public void BROKENtestWithTwoHyperlinks() throws Exception {
+ String dir = System.getProperty("HSSF.testdata.path");
+ File f = new File(dir, "WithTwoHyperLinks.xls");
+ HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(f));
+
+ assertEquals(3, wb.getNumberOfSheets());
+
+ // Find our hyperlink record, and check they're
+ // as we'd expect
+ List records = wb.getWorkbook().getHyperlinks();
+ assertEquals(2, records.size());
+
+ HyperlinkRecord linkA = (HyperlinkRecord)
+ records.get(0);
+ HyperlinkRecord linkB = (HyperlinkRecord)
+ records.get(1);
+ assertNotNull(linkA);
+ assertNotNull(linkB);
+
+ // Is in A5
+ assertEquals("Foo", linkA.getLabel());
+ assertEquals("http://poi.apache.org/", linkA.getUrlString());
+ assertEquals(4, linkA.getRow());
+ assertEquals(0, linkA.getColumn());
+
+ // Is in B9
+ assertEquals("Bar", linkB.getLabel());
+ assertEquals("http://poi.apache.org/", linkB.getUrlString());
+ assertEquals(8, linkB.getRow());
+ assertEquals(1, linkB.getColumn());
+
+ // Now check at the HSSFCell level
+ assertEquals(3, wb.getNumberOfSheets());
+
+ HSSFSheet s = wb.getSheetAt(1);
+ HSSFRow r = s.getRow(4);
+ assertNotNull(r);
+ HSSFCell c = r.getCell((short)0);
}
/*tests the toString() method of HSSFCell*/