https://issues.apache.org/bugzilla/show_bug.cgi?id=55904
Bug ID: 55904
Summary: Cell getHyperlink returns null when the link is drag
copied in excel
Product: POI
Version: 3.9
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
Assignee: [email protected]
Reporter: [email protected]
When a cell containing hyperlink is drag copied the hyperlink cell reference is
stored in range, for example, ref="B3:B10" and so the equals fails in the below
getHyperLink code of XSSFSheet
public XSSFHyperlink getHyperlink(int row, int column) {
String ref = new CellReference(row, column).formatAsString();
for(XSSFHyperlink hyperlink : hyperlinks) {
if(hyperlink.getCellRef().equals(ref)) {
return hyperlink;
}
}
return null;
}
My solution,
public XSSFHyperlink getHyperlink(int row, int column) {
String ref = new CellReference(row, column).formatAsString();
for (XSSFHyperlink hyperlink : hyperlinks) {
if (hyperlink.getCellRef().contains(":")){
if(checkWithInRange(hyperlink.getCellRef(), ref)) {
return hyperlink;
}
} else if (hyperlink.getCellRef().equals(ref)) {
return hyperlink;
}
}
return null;
}
public static final String RANGE_PATTERN = "(.+)(\\d)+:(.+)(\\d)+";
public static final String INPUT_PATTERN = "(.+)(\\d)+";
public static final Pattern P1 = Pattern.compile(RANGE_PATTERN);
public static final Pattern P2 = Pattern.compile(INPUT_PATTERN);
/*
* range - eg, "B3:B8"
* input - B4
*/
public static boolean checkWithInRange(String range, String input) {
Matcher m1 = P1.matcher(range);
Matcher m2 = P2.matcher(input);
if (m1.find() && m2.find()) {
String prefix1 = m1.group(1);
String num1 = m1.group(2);
String prefix2 = m1.group(3);
String num2 = m1.group(4);
String inputPrefix = m2.group(1);
String inputNum = m2.group(2);
if (prefix1 != null && prefix2 != null && inputPrefix != null
&& prefix1.equalsIgnoreCase(prefix2) && prefix2.equalsIgnoreCase(inputPrefix)
&& num1 != null && num2 != null && inputNum != null) {
int n1 = Integer.parseInt(num1);
int n2 = Integer.parseInt(num2);
int n3 = Integer.parseInt(inputNum);
if (n3 >= n1 && n3 <= n2) {
return true;
}
}
}
return false;
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]