mirror of https://github.com/apache/poi.git
Work on bug 64038 and other bugs and add test for 62865
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1874983 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7c2dfd9930
commit
199895bfc4
|
@ -766,7 +766,6 @@ public class CellNumberFormatter extends CellFormatter {
|
|||
}
|
||||
|
||||
ListIterator<Special> it = numSpecials.listIterator(numSpecials.size());
|
||||
boolean followWithGroupingSeparator = false;
|
||||
Special lastOutputIntegerDigit = null;
|
||||
int digit = 0;
|
||||
while (it.hasPrevious()) {
|
||||
|
@ -778,7 +777,7 @@ public class CellNumberFormatter extends CellFormatter {
|
|||
resultCh = '0';
|
||||
}
|
||||
Special s = it.previous();
|
||||
followWithGroupingSeparator = showGroupingSeparator && digit > 0 && digit % 3 == 0;
|
||||
boolean followWithGroupingSeparator = showGroupingSeparator && digit > 0 && digit % 3 == 0;
|
||||
boolean zeroStrip = false;
|
||||
if (resultCh != '0' || s.ch == '0' || s.ch == '?' || pos >= strip) {
|
||||
zeroStrip = s.ch == '?' && pos < strip;
|
||||
|
@ -787,7 +786,6 @@ public class CellNumberFormatter extends CellFormatter {
|
|||
}
|
||||
if (followWithGroupingSeparator) {
|
||||
mods.add(insertMod(s, zeroStrip ? " " : groupingSeparator, CellNumberStringMod.AFTER));
|
||||
followWithGroupingSeparator = false;
|
||||
}
|
||||
digit++;
|
||||
--pos;
|
||||
|
|
|
@ -420,7 +420,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates whether this paragraph should be kept on the same page as the next one.
|
||||
*
|
||||
|
@ -432,9 +432,9 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets this paragraph to be kept on the same page as the next one or not.
|
||||
* Sets this paragraph to be kept on the same page as the next one or not.
|
||||
*
|
||||
* @since POI 4.1.1
|
||||
*/
|
||||
|
@ -1092,7 +1092,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
return val[0].doubleValue() + (val[1].doubleValue() / 240L);
|
||||
}
|
||||
BigInteger[] val = spacing.getLine().divideAndRemainder(BigInteger.valueOf(20L));
|
||||
return val[0].doubleValue() + (val[1].doubleValue() / 20L);
|
||||
return val[0].doubleValue() + (val[1].doubleValue() / 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1105,8 +1105,8 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
* font size. If AT_LEAST, then spacing value is in inches, and is the
|
||||
* minimum size of the line. If the line height is taller, then the
|
||||
* line expands to match. If EXACT, then spacing is the exact line
|
||||
* height. If the text is taller than the line height, then it is
|
||||
* clipped at the top.
|
||||
* height. If the text is taller than the line height, then it is
|
||||
* clipped at the top.
|
||||
*/
|
||||
public void setSpacingBetween(double spacing, LineSpacingRule rule) {
|
||||
CTSpacing ctSp = getCTSpacing(true);
|
||||
|
@ -1117,7 +1117,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
}
|
||||
ctSp.setLineRule(STLineSpacingRule.Enum.forInt(rule.getValue()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the spacing between lines in a paragraph
|
||||
*
|
||||
|
@ -1126,7 +1126,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
public void setSpacingBetween(double spacing) {
|
||||
setSpacingBetween(spacing, LineSpacingRule.AUTO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the indentation which shall be placed between the left text
|
||||
* margin for this paragraph and the left edge of that paragraph's content
|
||||
|
@ -1460,17 +1460,17 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
* @since POI 4.1.1
|
||||
*/
|
||||
public XWPFHyperlinkRun createHyperlinkRun(String uri) {
|
||||
// Create a relationship ID for this link.
|
||||
// Create a relationship ID for this link.
|
||||
String rId = getPart().getPackagePart().addExternalRelationship(
|
||||
uri, XWPFRelation.HYPERLINK.getRelation()
|
||||
).getId();
|
||||
|
||||
// Create the run.
|
||||
|
||||
// Create the run.
|
||||
CTHyperlink ctHyperLink = getCTP().addNewHyperlink();
|
||||
ctHyperLink.setId(rId);
|
||||
ctHyperLink.addNewR();
|
||||
|
||||
// Append this run to the paragraph.
|
||||
|
||||
// Append this run to the paragraph.
|
||||
XWPFHyperlinkRun link = new XWPFHyperlinkRun(ctHyperLink, ctHyperLink.getRArray(0), this);
|
||||
runs.add(link);
|
||||
iruns.add(link);
|
||||
|
@ -1481,7 +1481,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
* insert a new Run in RunArray
|
||||
*
|
||||
* @param pos The position at which the new run should be added.
|
||||
*
|
||||
*
|
||||
* @return the inserted run or null if the given pos is out of bounds.
|
||||
*/
|
||||
public XWPFRun insertNewRun(int pos) {
|
||||
|
@ -1537,7 +1537,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
startChar = startPos.getChar();
|
||||
int beginRunPos = 0, candCharPos = 0;
|
||||
boolean newList = false;
|
||||
|
||||
|
||||
CTR[] rArray = paragraph.getRArray();
|
||||
for (int runPos = startRun; runPos < rArray.length; runPos++) {
|
||||
int beginTextPos = 0, beginCharPos = 0, textPos = 0, charPos;
|
||||
|
@ -1555,7 +1555,7 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
|
|||
} else {
|
||||
charPos = 0;
|
||||
}
|
||||
|
||||
|
||||
for (; charPos < candidate.length(); charPos++) {
|
||||
if ((candidate.charAt(charPos) == searched.charAt(0)) && (candCharPos == 0)) {
|
||||
beginTextPos = textPos;
|
||||
|
|
|
@ -198,6 +198,8 @@ public final class TestXWPFDocument {
|
|||
XWPFHyperlinkRun h = p.createHyperlinkRun("https://poi.apache.org/");
|
||||
h.setText("Apache POI");
|
||||
|
||||
assertEquals("rId7", h.getHyperlinkId());
|
||||
|
||||
assertEquals("https://poi.apache.org/", h.getHyperlink(doc).getURL());
|
||||
assertEquals(p.getRuns().size(), 1);
|
||||
assertEquals(p.getRuns().get(0), h);
|
||||
|
|
|
@ -109,7 +109,13 @@ public final class TestUnfixedBugs {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDataFormattingWithQuestionMark() {
|
||||
public void testBug62242() {
|
||||
CellFormat cfUK = CellFormat.getInstance("_ * #,##0.00_ ;_ * \\-#,##0.00_ ;_ * \"-\"??_ ;_ @_");
|
||||
assertEquals(" - ", cfUK.apply((double) 0).text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataFormattingWithQuestionMarkBug62242() {
|
||||
// The question mark in the format should be replaced by blanks, but
|
||||
// this is currently not handled when producing the Java formatting and
|
||||
// so we end up with a trailing zero here
|
||||
|
@ -118,13 +124,16 @@ public final class TestUnfixedBugs {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDataFormattingWithQuestionMarkAndPound() {
|
||||
public void testDataFormattingWithQuestionMarkAndPoundBug62242() {
|
||||
char pound = '\u00A3';
|
||||
|
||||
// The question mark in the format should be replaced by blanks, but
|
||||
// this is currently not handled when producing the Java formatting and
|
||||
// so we end up with a trailing zero here
|
||||
CellFormat cfUK = CellFormat.getInstance("_-[$£-809]* \"-\"??_-");
|
||||
assertEquals(" "+pound+" - ", cfUK.apply((double) 0).text);
|
||||
assertEquals(" "+pound+" - ", cfUK.apply((double) 0).text);
|
||||
|
||||
cfUK = CellFormat.getInstance("_-[$£-809]* \"-\"??_-a");
|
||||
assertEquals(" "+pound+" - a", cfUK.apply((double) 0).text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1007,4 +1007,10 @@ public class TestCellFormat {
|
|||
assertNotNull(instance);
|
||||
assertEquals("01/01/1970", instance.apply(new Date(12345)).text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug62865() {
|
||||
CellFormat cf = CellFormat.getInstance("\"ca. \"0");
|
||||
assertEquals("ca. 5", cf.apply((double) 5).text);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue