java - Lexical error in formula that contains ampersand -
i'm trying add formula spreadsheet contains sumif references cell. here's code formula i'm trying add:
addformula("(100 * " + drangecell + " / 256) * (sumif(b" + (dip.start+1) + ":b" + (dip.end+1) + ",\"<\"&" + dbthresholdcell + ")) / " + profile.getimagewidth(), dipareapercentagecol, row, sheet, highlightedformat);
the important part condition in sumif, i'm trying sum if values less value in cell.
when code runs error:
warning: lexical error: (100 * d18 / 256) * (sumif(b1:b2,"<"&d21)) / 332 @ char 36 when parsing formula (100 * d18 / 256) * (sumif(b1:b2,"<"&d21)) / 332 in cell profile!n24
the character it's complaining ampersand. however, when paste exact formula spreadsheet in excel works perfectly.
does jexcel not know how parse ampersand properly? there workaround situation?
if use concatenate(a,b) instead of a&b can desired effect. example above handle single level concatenation &and&and&and if want nested ie (and&and)&and you'll have mess around regex –
if (colelement.attributevalue("type").equals(celltype.string_formula.tostring())) { writablecellformat wcf = new writablecellformat(); pattern pattern = pattern.compile("^([^&]+)&(.*)$"); (matcher m = pattern.matcher(t); m.matches(); m=pattern.matcher(t)) { t = "concatenate(" + m.group(1) + "," + m.group(2) + ")"; } sheet.addcell(new jxl.write.formula(x, y, t)); }
Comments
Post a Comment