import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.util.Configurator;
/**
* High level representation of a row of a spreadsheet.
public final class HSSFRow implements Row {
// used for collections
- public final static int INITIAL_CAPACITY = 5;
+ public final static int INITIAL_CAPACITY = Configurator.getIntValue("HSSFRow.ColInitialCapacity", 5);
private int rowNum;
private HSSFCell[] cells;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.SSCellRange;
import org.apache.poi.ss.util.SheetUtil;
+import org.apache.poi.util.Configurator;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
* rows. It is currently set to 20. If you generate larger sheets you may benefit
* by setting this to a higher number and recompiling a custom edition of HSSFSheet.
*/
- public final static int INITIAL_CAPACITY = 20;
+ public final static int INITIAL_CAPACITY = Configurator.getIntValue("HSSFSheet.RowInitialCapacity", 20);
/**
* reference to the low level {@link InternalSheet} object
import java.util.List;
import java.util.regex.Pattern;
+import org.apache.commons.codec.digest.DigestUtils;
import org.apache.poi.POIDocument;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherBitmapBlip;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.WorkbookUtil;
+import org.apache.poi.util.Configurator;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.apache.commons.codec.digest.DigestUtils;
import org.apache.poi.ss.formula.udf.IndexedUDFFinder;
* since you're never allowed to have more or less than three sheets!
*/
- public final static int INITIAL_CAPACITY = 3;
+ public final static int INITIAL_CAPACITY = Configurator.getIntValue("HSSFWorkbook.SheetInitialCapacity",3);
/**
* this is the reference to the low level Workbook object
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.ss.formula.functions;\r
+\r
+import org.apache.poi.ss.formula.eval.*;\r
+\r
+/**\r
+ * Implementation for Excel DELTA() function.<p/>\r
+ * <p/>\r
+ * <b>Syntax</b>:<br/> <b>DEC2HEX </b>(<b>number</b>,<b>places</b> )<br/>\r
+ * <p/>\r
+ * Converts a decimal number to hexadecimal.\r
+ *\r
+ * The decimal integer you want to convert. If number is negative, places is ignored\r
+ * and this function returns a 10-character (40-bit) hexadecimal number in which the\r
+ * most significant bit is the sign bit. The remaining 39 bits are magnitude bits.\r
+ * Negative numbers are represented using two's-complement notation.\r
+ *\r
+ * <ul>\r
+ * <li>If number < -549,755,813,888 or if number > 549,755,813,887, this function returns the #NUM! error value.</li>\r
+ * <li>If number is nonnumeric, this function returns the #VALUE! error value.</li>\r
+ * </ul>\r
+ *\r
+ * <h2>places</h2>\r
+ *\r
+ * The number of characters to use. The places argument is useful for padding the\r
+ * return value with leading 0s (zeros).\r
+ *\r
+ * <ul>\r
+ * <li>If this argument is omitted, this function uses the minimum number of characters necessary.</li>\r
+ * <li>If this function requires more than places characters, it returns the #NUM! error value.</li>\r
+ * <li>If this argument is nonnumeric, this function returns the #VALUE! error value.</li>\r
+ * <li>If this argument is negative, this function returns the #NUM! error value.</li>\r
+ * <li>If this argument contains a decimal value, this function ignores the numbers to the right side of the decimal point.</li>\r
+ * </ul>\r
+ *\r
+ * @author cedric dot walter @ gmail dot com\r
+ */\r
+public final class Dec2Hex extends Var1or2ArgFunction {\r
+\r
+ private final static long MIN_VALUE = new Long("-549755813888").longValue();\r
+ private final static long MAX_VALUE = new Long("549755813887").longValue();\r
+ private final static int DEFAULT_PLACES_VALUE = 10;;\r
+\r
+ @Override\r
+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval number, ValueEval places) {\r
+ ValueEval veText1;\r
+ try {\r
+ veText1 = OperandResolver.getSingleValue(number, srcRowIndex, srcColumnIndex);\r
+ } catch (EvaluationException e) {\r
+ return e.getErrorEval();\r
+ }\r
+ String strText1 = OperandResolver.coerceValueToString(veText1);\r
+ Double number1 = OperandResolver.parseDouble(strText1);\r
+\r
+ //If this number argument is non numeric, this function returns the #VALUE! error value.\r
+ if (number1 == null) {\r
+ return ErrorEval.VALUE_INVALID;\r
+ }\r
+\r
+ //If number < -549,755,813,888 or if number > 549,755,813,887, this function returns the #NUM! error value.\r
+ if (number1.longValue() < MIN_VALUE || number1.longValue() > MAX_VALUE) {\r
+ return ErrorEval.NUM_ERROR;\r
+ }\r
+\r
+ int placesNumber = 0;\r
+ if (number1 < 0) {\r
+ placesNumber = DEFAULT_PLACES_VALUE;\r
+ } else {\r
+ ValueEval placesValueEval;\r
+ try {\r
+ placesValueEval = OperandResolver.getSingleValue(places, srcRowIndex, srcColumnIndex);\r
+ } catch (EvaluationException e) {\r
+ return e.getErrorEval();\r
+ }\r
+ String placesStr = OperandResolver.coerceValueToString(placesValueEval);\r
+ Double placesNumberDouble = OperandResolver.parseDouble(placesStr);\r
+\r
+ //non numeric value\r
+ if (placesNumberDouble == null) {\r
+ return ErrorEval.VALUE_INVALID;\r
+ }\r
+\r
+ //If this argument contains a decimal value, this function ignores the numbers to the right side of the decimal point.\r
+ placesNumber = placesNumberDouble.intValue();\r
+\r
+ if (placesNumber < 0) {\r
+ return ErrorEval.NUM_ERROR;\r
+ }\r
+ }\r
+\r
+ String hex = "";\r
+ if (placesNumber != 0) {\r
+ hex = String.format("%0"+placesNumber+"X", number1.intValue() & 0x0FFFFF);\r
+ }\r
+ else {\r
+ hex = Integer.toHexString(number1.intValue());\r
+ }\r
+\r
+ return new StringEval(hex.toUpperCase());\r
+ }\r
+\r
+ @Override\r
+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {\r
+ return this.evaluate(srcRowIndex, srcColumnIndex, arg0, new StringEval(String.valueOf(DEFAULT_PLACES_VALUE)));\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.apache.poi.util;\r
+\r
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+/**\r
+ *\r
+ * @author Cedric Walter (cedric.walter at innoveo.com)\r
+ */\r
+public class Configurator {\r
+\r
+ private static POILogger logger = POILogFactory.getLogger(Configurator.class);\r
+\r
+ public static int getIntValue(String systemProperty, int defaultValue) {\r
+ int result = defaultValue;\r
+ String property = System.getProperty(systemProperty);\r
+ try {\r
+ result = Integer.valueOf(property);\r
+ } catch (Exception e) {\r
+ logger.log(POILogger.ERROR, "System property -D"+systemProperty +" do not contains a valid integer " + property);\r
+ }\r
+ return result;\r
+ }\r
+\r
+\r
+}\r
HSSFCell expectedValueCell = r.getCell(SS.COLUMN_INDEX_EXPECTED_RESULT);\r
String rowComment = getRowCommentColumnValue(r);\r
\r
- String msgPrefix = formatTestCaseDetails(sheetName, r.getRowNum(), c, currentGroupComment, rowComment);\r
+ String msgPrefix = formatTestCaseDetails(this.getFilename(),sheetName, r.getRowNum(), c, currentGroupComment, rowComment);\r
try {\r
confirmExpectedResult(msgPrefix, expectedValueCell, actualValue);\r
_evaluationSuccessCount ++;\r
}\r
\r
\r
- private static String formatTestCaseDetails(String sheetName, int rowIndex, HSSFCell c, String currentGroupComment,\r
+ private static String formatTestCaseDetails(String filename, String sheetName, int rowIndex, HSSFCell c, String currentGroupComment,\r
String rowComment) {\r
\r
StringBuffer sb = new StringBuffer();\r
+\r
+ sb.append("In ").append(filename).append(" ");\r
+\r
CellReference cr = new CellReference(sheetName, rowIndex, c.getColumnIndex(), false, false);\r
sb.append(cr.formatAsString());\r
sb.append(" {=").append(c.getCellFormula()).append("}");\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.formula.functions;
+
+import junit.framework.TestCase;
+import org.apache.poi.ss.formula.eval.ErrorEval;
+import org.apache.poi.ss.formula.eval.StringEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
+
+/**
+ * Tests for {@link Dec2Hex}
+ *
+ * @author cedric dot walter @ gmail dot com
+ */
+public final class TestDec2Hex extends TestCase {
+
+ private static ValueEval invokeValue(String number1, String number2) {
+ ValueEval[] args = new ValueEval[] { new StringEval(number1), new StringEval(number2), };
+ return new Dec2Hex().evaluate(args, -1, -1);
+ }
+
+ private static ValueEval invokeValue(String number1) {
+ ValueEval[] args = new ValueEval[] { new StringEval(number1), };
+ return new Dec2Hex().evaluate(args, -1, -1);
+ }
+
+ private static void confirmValue(String msg, String number1, String number2, String expected) {
+ ValueEval result = invokeValue(number1, number2);
+ assertEquals(StringEval.class, result.getClass());
+ assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ }
+
+ private static void confirmValue(String msg, String number1, String expected) {
+ ValueEval result = invokeValue(number1);
+ assertEquals(StringEval.class, result.getClass());
+ assertEquals(msg, expected, ((StringEval) result).getStringValue());
+ }
+
+ private static void confirmValueError(String msg, String number1, String number2, ErrorEval numError) {
+ ValueEval result = invokeValue(number1, number2);
+ assertEquals(ErrorEval.class, result.getClass());
+ assertEquals(msg, numError, result);
+ }
+
+ public void testBasic() {
+ confirmValue("Converts decimal 100 to hexadecimal with 0 characters (64)", "100","0", "64");
+ confirmValue("Converts decimal 100 to hexadecimal with 4 characters (0064)", "100","4", "0064");
+ confirmValue("Converts decimal 100 to hexadecimal with 5 characters (0064)", "100","5", "00064");
+ confirmValue("Converts decimal 100 to hexadecimal with 10 (default) characters", "100","10", "0000000064");
+ confirmValue("If argument places contains a decimal value, dec2hex ignores the numbers to the right side of the decimal point.", "100","10.0", "0000000064");
+
+ confirmValue("Converts decimal -54 to hexadecimal, 0 is ignored", "-54", "0", "00000FFFCA");
+ confirmValue("Converts decimal -54 to hexadecimal, 2 is ignored","-54", "2", "00000FFFCA");
+ confirmValue("places is optionnal","-54", "00000FFFCA");
+ }
+
+ public void testErrors() {
+ confirmValueError("Out of range min number","-549755813889","0", ErrorEval.NUM_ERROR);
+ confirmValueError("Out of range max number","549755813888","0", ErrorEval.NUM_ERROR);
+
+ confirmValueError("negative places not allowed","549755813888","-10", ErrorEval.NUM_ERROR);
+ confirmValueError("non number places not allowed","ABCDEF","0", ErrorEval.VALUE_INVALID);
+ }
+}