You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by be...@apache.org on 2012/08/05 15:05:49 UTC
svn commit: r1369572 [2/4] - in /poi/branches/gsoc2012: ./
src/documentation/ src/documentation/content/xdocs/
src/documentation/content/xdocs/spreadsheet/
src/java/org/apache/poi/hssf/model/
src/java/org/apache/poi/hssf/record/aggregates/ src/java/org...
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFPictureData.java Sun Aug 5 13:05:44 2012
@@ -22,6 +22,7 @@ import org.apache.poi.ddf.EscherBitmapBl
import org.apache.poi.ddf.EscherBlipRecord;
import org.apache.poi.ddf.EscherMetafileBlip;
import org.apache.poi.ss.usermodel.PictureData;
+import org.apache.poi.util.PngUtils;
/**
* Represents binary data stored in the file. Eg. A GIF, JPEG etc...
@@ -60,7 +61,18 @@ public class HSSFPictureData implements
*/
public byte[] getData()
{
- return blip.getPicturedata();
+ byte[] pictureData = blip.getPicturedata();
+
+ //PNG created on MAC may have a 16-byte prefix which prevents successful reading.
+ //Just cut it off!.
+ if (PngUtils.matchesPngHeader(pictureData, 16))
+ {
+ byte[] png = new byte[pictureData.length-16];
+ System.arraycopy(pictureData, 16, png, 0, png.length);
+ pictureData = png;
+ }
+
+ return pictureData;
}
/**
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Sun Aug 5 13:05:44 2012
@@ -33,8 +33,10 @@ import org.apache.poi.hssf.record.aggreg
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
import org.apache.poi.ss.formula.FormulaShifter;
+import org.apache.poi.ss.formula.ptg.MemFuncPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
+import org.apache.poi.ss.formula.ptg.UnionPtg;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaType;
@@ -371,6 +373,7 @@ public final class HSSFSheet implements
/**
* Creates a data validation object
+ *
* @param dataValidation The Data validation object settings
*/
public void addValidationData(DataValidation dataValidation) {
@@ -522,6 +525,7 @@ public final class HSSFSheet implements
/**
* get the default row height for the sheet (if the rows do not define their own height) in
* twips (1/20 of a point)
+ *
* @return default row height
*/
public short getDefaultRowHeight() {
@@ -531,6 +535,7 @@ public final class HSSFSheet implements
/**
* get the default row height for the sheet (if the rows do not define their own height) in
* points.
+ *
* @return default row height in points
*/
@@ -813,6 +818,7 @@ public final class HSSFSheet implements
/**
* used internally in the API to get the low level Sheet record represented by this
* Object.
+ *
* @return Sheet - low level representation of this HSSFSheet.
*/
InternalSheet getSheet() {
@@ -821,6 +827,7 @@ public final class HSSFSheet implements
/**
* whether alternate expression evaluation is on
+ *
* @param b alternative expression evaluation or not
*/
public void setAlternativeExpression(boolean b) {
@@ -832,6 +839,7 @@ public final class HSSFSheet implements
/**
* whether alternative formula entry is on
+ *
* @param b alternative formulas or not
*/
public void setAlternativeFormula(boolean b) {
@@ -843,6 +851,7 @@ public final class HSSFSheet implements
/**
* show automatic page breaks or not
+ *
* @param b whether to show auto page breaks
*/
public void setAutobreaks(boolean b) {
@@ -854,6 +863,7 @@ public final class HSSFSheet implements
/**
* set whether sheet is a dialog sheet or not
+ *
* @param b isDialog or not
*/
public void setDialog(boolean b) {
@@ -877,6 +887,7 @@ public final class HSSFSheet implements
/**
* fit to page option is on
+ *
* @param b fit or not
*/
public void setFitToPage(boolean b) {
@@ -888,6 +899,7 @@ public final class HSSFSheet implements
/**
* set if row summaries appear below detail in the outline
+ *
* @param b below or not
*/
public void setRowSumsBelow(boolean b) {
@@ -901,6 +913,7 @@ public final class HSSFSheet implements
/**
* set if col summaries appear right of the detail in the outline
+ *
* @param b right or not
*/
public void setRowSumsRight(boolean b) {
@@ -912,6 +925,7 @@ public final class HSSFSheet implements
/**
* whether alternate expression evaluation is on
+ *
* @return alternative expression evaluation or not
*/
public boolean getAlternateExpression() {
@@ -921,6 +935,7 @@ public final class HSSFSheet implements
/**
* whether alternative formula entry is on
+ *
* @return alternative formulas or not
*/
public boolean getAlternateFormula() {
@@ -930,6 +945,7 @@ public final class HSSFSheet implements
/**
* show automatic page breaks or not
+ *
* @return whether to show auto page breaks
*/
public boolean getAutobreaks() {
@@ -939,6 +955,7 @@ public final class HSSFSheet implements
/**
* get whether sheet is a dialog sheet or not
+ *
* @return isDialog or not
*/
public boolean getDialog() {
@@ -963,6 +980,7 @@ public final class HSSFSheet implements
* <p>
* In Excel 2003 this option can be changed in the Options dialog on the View tab.
* </p>
+ *
* @return whether all zero values on the worksheet are displayed
*/
public boolean isDisplayZeros() {
@@ -975,6 +993,7 @@ public final class HSSFSheet implements
* <p>
* In Excel 2003 this option can be set in the Options dialog on the View tab.
* </p>
+ *
* @param value whether to display or hide all zero values on the worksheet
*/
public void setDisplayZeros(boolean value) {
@@ -983,6 +1002,7 @@ public final class HSSFSheet implements
/**
* fit to page option is on
+ *
* @return fit or not
*/
public boolean getFitToPage() {
@@ -992,6 +1012,7 @@ public final class HSSFSheet implements
/**
* get if row summaries appear below detail in the outline
+ *
* @return below or not
*/
public boolean getRowSumsBelow() {
@@ -1001,6 +1022,7 @@ public final class HSSFSheet implements
/**
* get if col summaries appear right of the detail in the outline
+ *
* @return right or not
*/
public boolean getRowSumsRight() {
@@ -1010,6 +1032,7 @@ public final class HSSFSheet implements
/**
* Returns whether gridlines are printed.
+ *
* @return Gridlines are printed
*/
public boolean isPrintGridlines() {
@@ -1018,8 +1041,9 @@ public final class HSSFSheet implements
/**
* Turns on or off the printing of gridlines.
+ *
* @param newPrintGridlines boolean to turn on or off the printing of
- * gridlines
+ * gridlines
*/
public void setPrintGridlines(boolean newPrintGridlines) {
getSheet().getPrintGridlines().setPrintGridlines(newPrintGridlines);
@@ -1027,6 +1051,7 @@ public final class HSSFSheet implements
/**
* Gets the print setup object.
+ *
* @return The user model for the print setup object.
*/
public HSSFPrintSetup getPrintSetup() {
@@ -1799,10 +1824,9 @@ public final class HSSFSheet implements
return new HSSFPatriarch(this, agg);
}
- /**
- * @deprecated (Sep 2008) use {@link #setColumnGroupCollapsed(int, boolean)}
- */
-
+ /**
+ * @deprecated (Sep 2008) use {@link #setColumnGroupCollapsed(int, boolean)}
+ */
public void setColumnGroupCollapsed(short columnNumber, boolean collapsed) {
setColumnGroupCollapsed(columnNumber & 0xFFFF, collapsed);
}
@@ -2070,4 +2094,160 @@ public final class HSSFSheet implements
}
return null;
}
+
+
+ public CellRangeAddress getRepeatingRows() {
+ return getRepeatingRowsOrColums(true);
+ }
+
+
+ public CellRangeAddress getRepeatingColumns() {
+ return getRepeatingRowsOrColums(false);
+ }
+
+
+ public void setRepeatingRows(CellRangeAddress rowRangeRef) {
+ CellRangeAddress columnRangeRef = getRepeatingColumns();
+ setRepeatingRowsAndColumns(rowRangeRef, columnRangeRef);
+ }
+
+
+ public void setRepeatingColumns(CellRangeAddress columnRangeRef) {
+ CellRangeAddress rowRangeRef = getRepeatingRows();
+ setRepeatingRowsAndColumns(rowRangeRef, columnRangeRef);
+ }
+
+
+ private void setRepeatingRowsAndColumns(
+ CellRangeAddress rowDef, CellRangeAddress colDef) {
+ int sheetIndex = _workbook.getSheetIndex(this);
+ int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
+ int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
+
+ int col1 = -1;
+ int col2 = -1;
+ int row1 = -1;
+ int row2 = -1;
+
+ if (rowDef != null) {
+ row1 = rowDef.getFirstRow();
+ row2 = rowDef.getLastRow();
+ if ((row1 == -1 && row2 != -1) || (row1 > row2)
+ || (row1 < 0 || row1 > maxRowIndex)
+ || (row2 < 0 || row2 > maxRowIndex)) {
+ throw new IllegalArgumentException("Invalid row range specification");
+ }
+ }
+ if (colDef != null) {
+ col1 = colDef.getFirstColumn();
+ col2 = colDef.getLastColumn();
+ if ((col1 == -1 && col2 != -1) || (col1 > col2)
+ || (col1 < 0 || col1 > maxColIndex)
+ || (col2 < 0 || col2 > maxColIndex)) {
+ throw new IllegalArgumentException("Invalid column range specification");
+ }
+ }
+
+ short externSheetIndex =
+ _workbook.getWorkbook().checkExternSheet(sheetIndex);
+
+ boolean setBoth = rowDef != null && colDef != null;
+ boolean removeAll = rowDef == null && colDef == null;
+
+ HSSFName name = _workbook.getBuiltInName(
+ NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
+ if (removeAll) {
+ if (name != null) {
+ _workbook.removeName(name);
+ }
+ return;
+ }
+ if (name == null) {
+ name = _workbook.createBuiltInName(
+ NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
+ }
+
+ List<Ptg> ptgList = new ArrayList<Ptg>();
+ if (setBoth) {
+ final int exprsSize = 2 * 11 + 1; // 2 * Area3DPtg.SIZE + UnionPtg.SIZE
+ ptgList.add(new MemFuncPtg(exprsSize));
+ }
+ if (colDef != null) {
+ Area3DPtg colArea = new Area3DPtg(0, maxRowIndex, col1, col2,
+ false, false, false, false, externSheetIndex);
+ ptgList.add(colArea);
+ }
+ if (rowDef != null) {
+ Area3DPtg rowArea = new Area3DPtg(row1, row2, 0, maxColIndex,
+ false, false, false, false, externSheetIndex);
+ ptgList.add(rowArea);
+ }
+ if (setBoth) {
+ ptgList.add(UnionPtg.instance);
+ }
+
+ Ptg[] ptgs = new Ptg[ptgList.size()];
+ ptgList.toArray(ptgs);
+ name.setNameDefinition(ptgs);
+
+ HSSFPrintSetup printSetup = getPrintSetup();
+ printSetup.setValidSettings(false);
+ setActive(true);
+ }
+
+
+ private CellRangeAddress getRepeatingRowsOrColums(boolean rows) {
+ NameRecord rec = getBuiltinNameRecord(NameRecord.BUILTIN_PRINT_TITLE);
+ if (rec == null) {
+ return null;
+ }
+
+ Ptg[] nameDefinition = rec.getNameDefinition();
+ if (nameDefinition == null) {
+ return null;
+ }
+
+ int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
+ int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
+
+ for (Ptg ptg : nameDefinition) {
+
+ if (ptg instanceof Area3DPtg) {
+ Area3DPtg areaPtg = (Area3DPtg) ptg;
+
+ if (areaPtg.getFirstColumn() == 0
+ && areaPtg.getLastColumn() == maxColIndex) {
+ if (rows) {
+ CellRangeAddress rowRange = new CellRangeAddress(
+ areaPtg.getFirstRow(), areaPtg.getLastRow(), -1, -1);
+ return rowRange;
+ }
+ } else if (areaPtg.getFirstRow() == 0
+ && areaPtg.getLastRow() == maxRowIndex) {
+ if (!rows) {
+ CellRangeAddress columnRange = new CellRangeAddress(-1, -1,
+ areaPtg.getFirstColumn(), areaPtg.getLastColumn());
+ return columnRange;
+ }
+ }
+
+ }
+
+ }
+
+ return null;
+ }
+
+
+ private NameRecord getBuiltinNameRecord(byte builtinCode) {
+ int sheetIndex = _workbook.getSheetIndex(this);
+ int recIndex =
+ _workbook.findExistingBuiltinNameRecordIdx(sheetIndex, builtinCode);
+ if (recIndex == -1) {
+ return null;
+ }
+ return _workbook.getNameRecord(recIndex);
+ }
+
+
}
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Sun Aug 5 13:05:44 2012
@@ -49,13 +49,10 @@ import org.apache.poi.poifs.filesystem.P
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.SheetNameFormatter;
-import org.apache.poi.ss.formula.ptg.Area3DPtg;
-import org.apache.poi.ss.formula.ptg.MemFuncPtg;
-import org.apache.poi.ss.formula.ptg.Ptg;
-import org.apache.poi.ss.formula.ptg.UnionPtg;
import org.apache.poi.ss.formula.udf.AggregatingUDFFinder;
import org.apache.poi.ss.formula.udf.UDFFinder;
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.POILogFactory;
import org.apache.poi.util.POILogger;
@@ -75,8 +72,6 @@ import org.apache.commons.codec.digest.D
*/
public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.usermodel.Workbook {
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
- private static final int MAX_ROW = 0xFFFF;
- private static final short MAX_COLUMN = (short)0x00FF;
/**
* The maximum number of cell styles in a .xls workbook.
@@ -957,84 +952,31 @@ public final class HSSFWorkbook extends
* @param endColumn 0 based end of repeating columns.
* @param startRow 0 based start of repeating rows.
* @param endRow 0 based end of repeating rows.
+ *
+ * @deprecated use {@link HSSFSheet#setRepeatingRows(CellRangeAddress)}
+ * or {@link HSSFSheet#setRepeatingColumns(CellRangeAddress)}
*/
public void setRepeatingRowsAndColumns(int sheetIndex,
int startColumn, int endColumn,
- int startRow, int endRow)
- {
- // Check arguments
- if (startColumn == -1 && endColumn != -1) throw new IllegalArgumentException("Invalid column range specification");
- if (startRow == -1 && endRow != -1) throw new IllegalArgumentException("Invalid row range specification");
- if (startColumn < -1 || startColumn >= MAX_COLUMN) throw new IllegalArgumentException("Invalid column range specification");
- if (endColumn < -1 || endColumn >= MAX_COLUMN) throw new IllegalArgumentException("Invalid column range specification");
- if (startRow < -1 || startRow > MAX_ROW) throw new IllegalArgumentException("Invalid row range specification");
- if (endRow < -1 || endRow > MAX_ROW) throw new IllegalArgumentException("Invalid row range specification");
- if (startColumn > endColumn) throw new IllegalArgumentException("Invalid column range specification");
- if (startRow > endRow) throw new IllegalArgumentException("Invalid row range specification");
-
- HSSFSheet sheet = getSheetAt(sheetIndex);
- short externSheetIndex = getWorkbook().checkExternSheet(sheetIndex);
-
- boolean settingRowAndColumn =
- startColumn != -1 && endColumn != -1 && startRow != -1 && endRow != -1;
- boolean removingRange =
- startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1;
-
- int rowColHeaderNameIndex = findExistingBuiltinNameRecordIdx(sheetIndex, NameRecord.BUILTIN_PRINT_TITLE);
- if (removingRange) {
- if (rowColHeaderNameIndex >= 0) {
- workbook.removeName(rowColHeaderNameIndex);
- }
- return;
- }
- boolean isNewRecord;
- NameRecord nameRecord;
- if (rowColHeaderNameIndex < 0) {
- //does a lot of the house keeping for builtin records, like setting lengths to zero etc
- nameRecord = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex+1);
- isNewRecord = true;
- } else {
- nameRecord = workbook.getNameRecord(rowColHeaderNameIndex);
- isNewRecord = false;
- }
+ int startRow, int endRow) {
+ HSSFSheet sheet = getSheetAt(sheetIndex);
- List temp = new ArrayList();
+ CellRangeAddress rows = null;
+ CellRangeAddress cols = null;
- if (settingRowAndColumn) {
- final int exprsSize = 2 * 11 + 1; // 2 * Area3DPtg.SIZE + UnionPtg.SIZE
- temp.add(new MemFuncPtg(exprsSize));
- }
- if (startColumn >= 0) {
- Area3DPtg colArea = new Area3DPtg(0, MAX_ROW, startColumn, endColumn,
- false, false, false, false, externSheetIndex);
- temp.add(colArea);
- }
- if (startRow >= 0) {
- Area3DPtg rowArea = new Area3DPtg(startRow, endRow, 0, MAX_COLUMN,
- false, false, false, false, externSheetIndex);
- temp.add(rowArea);
- }
- if (settingRowAndColumn) {
- temp.add(UnionPtg.instance);
- }
- Ptg[] ptgs = new Ptg[temp.size()];
- temp.toArray(ptgs);
- nameRecord.setNameDefinition(ptgs);
-
- if (isNewRecord)
- {
- HSSFName newName = new HSSFName(this, nameRecord, nameRecord.isBuiltInName() ? null : workbook.getNameCommentRecord(nameRecord));
- names.add(newName);
- }
-
- HSSFPrintSetup printSetup = sheet.getPrintSetup();
- printSetup.setValidSettings(false);
+ if (startRow != -1) {
+ rows = new CellRangeAddress(startRow, endRow, -1, -1);
+ }
+ if (startColumn != -1) {
+ cols = new CellRangeAddress(-1, -1, startColumn, endColumn);
+ }
- sheet.setActive(true);
+ sheet.setRepeatingRows(rows);
+ sheet.setRepeatingColumns(cols);
}
- private int findExistingBuiltinNameRecordIdx(int sheetIndex, byte builtinCode) {
+ int findExistingBuiltinNameRecordIdx(int sheetIndex, byte builtinCode) {
for(int defNameIndex =0; defNameIndex<names.size(); defNameIndex++) {
NameRecord r = workbook.getNameRecord(defNameIndex);
if (r == null) {
@@ -1050,6 +992,26 @@ public final class HSSFWorkbook extends
return -1;
}
+
+ HSSFName createBuiltInName(byte builtinCode, int sheetIndex) {
+ NameRecord nameRecord =
+ workbook.createBuiltInName(builtinCode, sheetIndex + 1);
+ HSSFName newName = new HSSFName(this, nameRecord, null);
+ names.add(newName);
+ return newName;
+ }
+
+
+ HSSFName getBuiltInName(byte builtinCode, int sheetIndex) {
+ int index = findExistingBuiltinNameRecordIdx(sheetIndex, builtinCode);
+ if (index < 0) {
+ return null;
+ } else {
+ return names.get(index);
+ }
+ }
+
+
/**
* create a new Font and add it to the workbook's font table
* @return new font object
@@ -1477,6 +1439,25 @@ public final class HSSFWorkbook extends
}
+ /**
+ * As {@link #getNameIndex(String)} is not necessarily unique
+ * (name + sheet index is unique), this method is more accurate.
+ *
+ * @param name the name whose index in the list of names of this workbook
+ * should be looked up.
+ * @return an index value >= 0 if the name was found; -1, if the name was
+ * not found
+ */
+ int getNameIndex(HSSFName name) {
+ for (int k = 0; k < names.size(); k++) {
+ if (name == names.get(k)) {
+ return k;
+ }
+ }
+ return -1;
+ }
+
+
public void removeName(int index){
names.remove(index);
workbook.removeName(index);
@@ -1497,10 +1478,21 @@ public final class HSSFWorkbook extends
public void removeName(String name) {
int index = getNameIndex(name);
-
removeName(index);
}
+
+ /**
+ * As {@link #removeName(String)} is not necessarily unique
+ * (name + sheet index is unique), this method is more accurate.
+ *
+ * @param name the name to remove.
+ */
+ void removeName(HSSFName name) {
+ int index = getNameIndex(name);
+ removeName(index);
+ }
+
public HSSFPalette getCustomPalette()
{
return new HSSFPalette(workbook.getCustomPalette());
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/format/CellDateFormatter.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/format/CellDateFormatter.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/format/CellDateFormatter.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/format/CellDateFormatter.java Sun Aug 5 13:05:44 2012
@@ -150,7 +150,10 @@ public class CellDateFormatter extends C
StringBuffer descBuf = CellFormatPart.parseFormat(format,
CellFormatType.DATE, partHandler);
partHandler.finish(descBuf);
- dateFmt = new SimpleDateFormat(descBuf.toString());
+ // tweak the format pattern to pass tests on JDK 1.7,
+ // See https://issues.apache.org/bugzilla/show_bug.cgi?id=53369
+ String ptrn = descBuf.toString().replaceAll("((y)(?!y))(?<!yy)", "yy");
+ dateFmt = new SimpleDateFormat(ptrn, LOCALE);
}
/** {@inheritDoc} */
@@ -214,4 +217,4 @@ public class CellDateFormatter extends C
public void simpleValue(StringBuffer toAppendTo, Object value) {
SIMPLE_DATE.formatValue(toAppendTo, value);
}
-}
\ No newline at end of file
+}
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java Sun Aug 5 13:05:44 2012
@@ -637,10 +637,10 @@ public final class WorkbookEvaluator {
* YK: Used by OperationEvaluationContext to resolve indirect names.
*/
/*package*/ ValueEval evaluateNameFormula(Ptg[] ptgs, OperationEvaluationContext ec) {
- if (ptgs.length > 1) {
- throw new RuntimeException("Complex name formulas not supported yet");
- }
- return getEvalForPtg(ptgs[0], ec);
+ if (ptgs.length == 1) {
+ return getEvalForPtg(ptgs[0], ec);
+ }
+ return evaluateFormula(ec, ptgs);
}
/**
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/DataFormatter.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Sun Aug 5 13:05:44 2012
@@ -111,8 +111,11 @@ public class DataFormatter {
/** Pattern to find "AM/PM" marker */
private static final Pattern amPmPattern = Pattern.compile("((A|P)[M/P]*)", Pattern.CASE_INSENSITIVE);
- /** A regex to find patterns like [$$-1009] and [$?-452]. */
- private static final Pattern specialPatternGroup = Pattern.compile("(\\[\\$[^-\\]]*-[0-9A-Z]+\\])");
+ /**
+ * A regex to find locale patterns like [$$-1009] and [$?-452].
+ * Note that we don't currently process these into locales
+ */
+ private static final Pattern localePatternGroup = Pattern.compile("(\\[\\$[^-\\]]*-[0-9A-Z]+\\])");
/**
* A regex to match the colour formattings rules.
@@ -278,12 +281,16 @@ public class DataFormatter {
if (format != null) {
return format;
}
+
+ // Is it one of the special built in types, General or @?
if ("General".equalsIgnoreCase(formatStr) || "@".equals(formatStr)) {
if (isWholeNumber(cellValue)) {
return generalWholeNumFormat;
}
return generalDecimalNumFormat;
}
+
+ // Build a formatter, and cache it
format = createFormat(cellValue, formatIndex, formatStr);
formats.put(formatStr, format);
return format;
@@ -323,8 +330,8 @@ public class DataFormatter {
colourM = colorPattern.matcher(formatStr);
}
- // try to extract special characters like currency
- Matcher m = specialPatternGroup.matcher(formatStr);
+ // Strip off the locale information, we use an instance-wide locale for everything
+ Matcher m = localePatternGroup.matcher(formatStr);
while(m.find()) {
String match = m.group();
String symbol = match.substring(match.indexOf('$') + 1, match.indexOf('-'));
@@ -336,12 +343,20 @@ public class DataFormatter {
symbol = sb.toString();
}
formatStr = m.replaceAll(symbol);
- m = specialPatternGroup.matcher(formatStr);
+ m = localePatternGroup.matcher(formatStr);
}
+ // Check for special cases
if(formatStr == null || formatStr.trim().length() == 0) {
return getDefaultFormat(cellValue);
}
+
+ if ("General".equalsIgnoreCase(formatStr) || "@".equals(formatStr)) {
+ if (isWholeNumber(cellValue)) {
+ return generalWholeNumFormat;
+ }
+ return generalDecimalNumFormat;
+ }
if(DateUtil.isADateFormat(formatIndex,formatStr) &&
DateUtil.isValidExcelDate(cellValue)) {
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Sheet.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Sheet.java Sun Aug 5 13:05:44 2012
@@ -927,4 +927,95 @@ public interface Sheet extends Iterable<
*/
SheetConditionalFormatting getSheetConditionalFormatting();
+
+ /**
+ * Gets the repeating rows used when printing the sheet, as found in
+ * File->PageSetup->Sheet.
+ * <p/>
+ * Repeating rows cover a range of contiguous rows, e.g.:
+ * <pre>
+ * Sheet1!$1:$1
+ * Sheet2!$5:$8
+ * </pre>
+ * The {@link CellRangeAddress} returned contains a column part which spans
+ * all columns, and a row part which specifies the contiguous range of
+ * repeating rows.
+ * <p/>
+ * If the Sheet does not have any repeating rows defined, null is returned.
+ *
+ * @return an {@link CellRangeAddress} containing the repeating rows for the
+ * Sheet, or null.
+ */
+ CellRangeAddress getRepeatingRows();
+
+
+ /**
+ * Gets the repeating columns used when printing the sheet, as found in
+ * File->PageSetup->Sheet.
+ * <p/>
+ * Repeating columns cover a range of contiguous columns, e.g.:
+ * <pre>
+ * Sheet1!$A:$A
+ * Sheet2!$C:$F
+ * </pre>
+ * The {@link CellRangeAddress} returned contains a row part which spans all
+ * rows, and a column part which specifies the contiguous range of
+ * repeating columns.
+ * <p/>
+ * If the Sheet does not have any repeating columns defined, null is
+ * returned.
+ *
+ * @return an {@link CellRangeAddress} containing the repeating columns for
+ * the Sheet, or null.
+ */
+ CellRangeAddress getRepeatingColumns();
+
+
+ /**
+ * Sets the repeating rows used when printing the sheet, as found in
+ * File->PageSetup->Sheet.
+ * <p/>
+ * Repeating rows cover a range of contiguous rows, e.g.:
+ * <pre>
+ * Sheet1!$1:$1
+ * Sheet2!$5:$8</pre>
+ * The parameter {@link CellRangeAddress} should specify a column part
+ * which spans all columns, and a row part which specifies the contiguous
+ * range of repeating rows, e.g.:
+ * <pre>
+ * sheet.setRepeatingRows(CellRangeAddress.valueOf("2:3"));</pre>
+ * A null parameter value indicates that repeating rows should be removed
+ * from the Sheet:
+ * <pre>
+ * sheet.setRepeatingRows(null);</pre>
+ *
+ * @param rowRangeRef a {@link CellRangeAddress} containing the repeating
+ * rows for the Sheet, or null.
+ */
+ void setRepeatingRows(CellRangeAddress rowRangeRef);
+
+
+ /**
+ * Sets the repeating columns used when printing the sheet, as found in
+ * File->PageSetup->Sheet.
+ * <p/>
+ * Repeating columns cover a range of contiguous columns, e.g.:
+ * <pre>
+ * Sheet1!$A:$A
+ * Sheet2!$C:$F</pre>
+ * The parameter {@link CellRangeAddress} should specify a row part
+ * which spans all rows, and a column part which specifies the contiguous
+ * range of repeating columns, e.g.:
+ * <pre>
+ * sheet.setRepeatingColumns(CellRangeAddress.valueOf("B:C"));</pre>
+ * A null parameter value indicates that repeating columns should be removed
+ * from the Sheet:
+ * <pre>
+ * sheet.setRepeatingColumns(null);</pre>
+ *
+ * @param columnRangeRef a {@link CellRangeAddress} containing the repeating
+ * columns for the Sheet, or null.
+ */
+ void setRepeatingColumns(CellRangeAddress columnRangeRef);
+
}
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Workbook.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Workbook.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/usermodel/Workbook.java Sun Aug 5 13:05:44 2012
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
+import org.apache.poi.ss.util.CellRangeAddress;
/**
* High level representation of a Excel workbook. This is the first object most users
@@ -284,6 +285,9 @@ public interface Workbook {
* @param endColumn 0 based end of repeating columns.
* @param startRow 0 based start of repeating rows.
* @param endRow 0 based end of repeating rows.
+ *
+ * @deprecated use {@link Sheet#setRepeatingRows(CellRangeAddress)}
+ * or {@link Sheet#setRepeatingColumns(CellRangeAddress)}
*/
void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow);
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddress.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddress.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddress.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddress.java Sun Aug 5 13:05:44 2012
@@ -100,7 +100,10 @@ public class CellRangeAddress extends Ce
sb.append(cellRefFrom.formatAsString());
//for a single-cell reference return A1 instead of A1:A1
- if(!cellRefFrom.equals(cellRefTo)){
+ //for full-column ranges or full-row ranges return A:A instead of A,
+ //and 1:1 instead of 1
+ if(!cellRefFrom.equals(cellRefTo)
+ || isFullColumnRange() || isFullRowRange()){
sb.append(':');
sb.append(cellRefTo.formatAsString());
}
@@ -108,8 +111,12 @@ public class CellRangeAddress extends Ce
}
/**
- * @param ref usually a standard area ref (e.g. "B1:D8"). May be a single cell
- * ref (e.g. "B5") in which case the result is a 1 x 1 cell range.
+ * Creates a CellRangeAddress from a cell range reference string.
+ *
+ * @param ref usually a standard area ref (e.g. "B1:D8"). May be a single
+ * cell ref (e.g. "B5") in which case the result is a 1 x 1 cell
+ * range. May also be a whole row range (e.g. "3:5"), or a whole
+ * column range (e.g. "C:F")
*/
public static CellRangeAddress valueOf(String ref) {
int sep = ref.indexOf(":");
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellRangeAddressBase.java Sun Aug 5 13:05:44 2012
@@ -76,11 +76,13 @@ public abstract class CellRangeAddressBa
//TODO use the correct SpreadsheetVersion
public final boolean isFullColumnRange() {
- return _firstRow == 0 && _lastRow == SpreadsheetVersion.EXCEL97.getLastRowIndex();
+ return (_firstRow == 0 && _lastRow == SpreadsheetVersion.EXCEL97.getLastRowIndex())
+ || (_firstRow == -1 && _lastRow == -1);
}
//TODO use the correct SpreadsheetVersion
public final boolean isFullRowRange() {
- return _firstCol == 0 && _lastCol == SpreadsheetVersion.EXCEL97.getLastColumnIndex();
+ return (_firstCol == 0 && _lastCol == SpreadsheetVersion.EXCEL97.getLastColumnIndex())
+ || (_firstCol == -1 && _lastCol == -1);
}
/**
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellReference.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellReference.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellReference.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/ss/util/CellReference.java Sun Aug 5 13:05:44 2012
@@ -91,25 +91,28 @@ public class CellReference {
String[] parts = separateRefParts(cellRef);
_sheetName = parts[0];
+
String colRef = parts[1];
- if (colRef.length() < 1) {
- throw new IllegalArgumentException("Invalid Formula cell reference: '"+cellRef+"'");
- }
- _isColAbs = colRef.charAt(0) == '$';
+ _isColAbs = (colRef.length() > 0) && colRef.charAt(0) == '$';
if (_isColAbs) {
- colRef=colRef.substring(1);
+ colRef = colRef.substring(1);
+ }
+ if (colRef.length() == 0) {
+ _colIndex = -1;
+ } else {
+ _colIndex = convertColStringToIndex(colRef);
}
- _colIndex = convertColStringToIndex(colRef);
String rowRef=parts[2];
- if (rowRef.length() < 1) {
- throw new IllegalArgumentException("Invalid Formula cell reference: '"+cellRef+"'");
- }
- _isRowAbs = rowRef.charAt(0) == '$';
+ _isRowAbs = (rowRef.length() > 0) && rowRef.charAt(0) == '$';
if (_isRowAbs) {
- rowRef=rowRef.substring(1);
+ rowRef = rowRef.substring(1);
+ }
+ if (rowRef.length() == 0) {
+ _rowIndex = -1;
+ } else {
+ _rowIndex = Integer.parseInt(rowRef)-1; // -1 to convert 1-based to zero-based
}
- _rowIndex = Integer.parseInt(rowRef)-1; // -1 to convert 1-based to zero-based
}
public CellReference(int pRow, int pCol) {
@@ -482,14 +485,18 @@ public class CellReference {
* Sheet name is not included.
*/
/* package */ void appendCellReference(StringBuffer sb) {
- if(_isColAbs) {
- sb.append(ABSOLUTE_REFERENCE_MARKER);
- }
- sb.append( convertNumToColString(_colIndex));
- if(_isRowAbs) {
- sb.append(ABSOLUTE_REFERENCE_MARKER);
+ if (_colIndex != -1) {
+ if(_isColAbs) {
+ sb.append(ABSOLUTE_REFERENCE_MARKER);
+ }
+ sb.append( convertNumToColString(_colIndex));
+ }
+ if (_rowIndex != -1) {
+ if(_isRowAbs) {
+ sb.append(ABSOLUTE_REFERENCE_MARKER);
+ }
+ sb.append(_rowIndex+1);
}
- sb.append(_rowIndex+1);
}
/**
Modified: poi/branches/gsoc2012/src/java/org/apache/poi/util/LittleEndian.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/java/org/apache/poi/util/LittleEndian.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/java/org/apache/poi/util/LittleEndian.java (original)
+++ poi/branches/gsoc2012/src/java/org/apache/poi/util/LittleEndian.java Sun Aug 5 13:05:44 2012
@@ -724,6 +724,24 @@ public class LittleEndian implements Lit
}
return ( ch4 << 24 ) + ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 << 0 );
}
+
+ /**
+ * get an unsigned int value from an InputStream
+ *
+ * @param stream
+ * the InputStream from which the int is to be read
+ * @return the unsigned int (32-bit) value
+ * @exception IOException
+ * will be propagated back to the caller
+ * @exception BufferUnderrunException
+ * if the stream cannot provide enough bytes
+ */
+ public static long readUInt( InputStream stream ) throws IOException,
+ BufferUnderrunException
+ {
+ long retNum = readInt(stream);
+ return retNum & 0x00FFFFFFFFl;
+ }
/**
* get a long value from an InputStream
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java Sun Aug 5 13:05:44 2012
@@ -186,6 +186,20 @@ public abstract class OPCPackage impleme
return open(path, defaultPackageAccess);
}
+ /**
+ * Open a package with read/write permission.
+ *
+ * @param file
+ * The file to open.
+ * @return A Package object, else <b>null</b>.
+ * @throws InvalidFormatException
+ * If the specified file doesn't exist, and a parsing error
+ * occur.
+ */
+ public static OPCPackage open(File file) throws InvalidFormatException {
+ return open(file, defaultPackageAccess);
+ }
+
/**
* Open a package.
*
@@ -212,6 +226,31 @@ public abstract class OPCPackage impleme
return pack;
}
+ /**
+ * Open a package.
+ *
+ * @param file
+ * The file to open.
+ * @param access
+ * PackageBase access.
+ * @return A PackageBase object, else <b>null</b>.
+ * @throws InvalidFormatException
+ * If the specified file doesn't exist, and a parsing error
+ * occur.
+ */
+ public static OPCPackage open(File file, PackageAccess access)
+ throws InvalidFormatException {
+ if (file == null|| (file.exists() && file.isDirectory()))
+ throw new IllegalArgumentException("file");
+
+ OPCPackage pack = new ZipPackage(file, access);
+ if (pack.partList == null && access != PackageAccess.WRITE) {
+ pack.getParts();
+ }
+ pack.originalPackagePath = file.getAbsolutePath();
+ return pack;
+ }
+
/**
* Open a package.
*
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Sun Aug 5 13:05:44 2012
@@ -85,30 +85,55 @@ public final class ZipPackage extends Pa
);
}
- /**
- * Constructor. Opens a Zip based Open XML document.
- *
- * @param path
- * The path of the file to open or create.
- * @param access
- * The package access mode.
- * @throws InvalidFormatException
- * If the content type part parsing encounters an error.
- */
- ZipPackage(String path, PackageAccess access) {
- super(access);
+ /**
+ * Constructor. Opens a Zip based Open XML document.
+ *
+ * @param path
+ * The path of the file to open or create.
+ * @param access
+ * The package access mode.
+ * @throws InvalidFormatException
+ * If the content type part parsing encounters an error.
+ */
+ ZipPackage(String path, PackageAccess access) {
+ super(access);
+
+ ZipFile zipFile = null;
+
+ try {
+ zipFile = ZipHelper.openZipFile(path);
+ } catch (IOException e) {
+ throw new InvalidOperationException(
+ "Can't open the specified file: '" + path + "'", e);
+ }
+
+ this.zipArchive = new ZipFileZipEntrySource(zipFile);
+ }
+
+ /**
+ * Constructor. Opens a Zip based Open XML document.
+ *
+ * @param file
+ * The file to open or create.
+ * @param access
+ * The package access mode.
+ * @throws InvalidFormatException
+ * If the content type part parsing encounters an error.
+ */
+ ZipPackage(File file, PackageAccess access) {
+ super(access);
+
+ ZipFile zipFile = null;
+
+ try {
+ zipFile = ZipHelper.openZipFile(file);
+ } catch (IOException e) {
+ throw new InvalidOperationException(
+ "Can't open the specified file: '" + file + "'", e);
+ }
- ZipFile zipFile = null;
-
- try {
- zipFile = ZipHelper.openZipFile(path);
- } catch (IOException e) {
- throw new InvalidOperationException(
- "Can't open the specified file: '" + path + "'", e);
- }
-
- this.zipArchive = new ZipFileZipEntrySource(zipFile);
- }
+ this.zipArchive = new ZipFileZipEntrySource(zipFile);
+ }
/**
* Retrieves the parts from this package. We assume that the package has not
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java Sun Aug 5 13:05:44 2012
@@ -72,11 +72,12 @@ public final class ZipHelper {
* Retrieve the Zip entry of the content types part.
*/
public static ZipEntry getContentTypeZipEntry(ZipPackage pkg) {
- Enumeration entries = pkg.getZipArchive().getEntries();
+ Enumeration<? extends ZipEntry> entries = pkg.getZipArchive().getEntries();
+
// Enumerate through the Zip entries until we find the one named
// '[Content_Types].xml'.
while (entries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) entries.nextElement();
+ ZipEntry entry = entries.nextElement();
if (entry.getName().equals(
ContentTypeManager.CONTENT_TYPES_PART_NAME))
return entry;
@@ -141,6 +142,21 @@ public final class ZipHelper {
}
}
+ /**
+ * Opens the specified file as a zip, or returns null if no such file exists
+ *
+ * @param file
+ * The file to open.
+ * @return The zip archive freshly open.
+ */
+ public static ZipFile openZipFile(File file) throws IOException {
+ if (!file.exists()) {
+ return null;
+ }
+
+ return new ZipFile(file);
+ }
+
/**
* Retrieve and open a zip file with the specified path.
*
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java Sun Aug 5 13:05:44 2012
@@ -87,7 +87,7 @@ public class WorkbookFactory {
NPOIFSFileSystem fs = new NPOIFSFileSystem(file);
return new HSSFWorkbook(fs.getRoot(), true);
} catch(OfficeXmlFileException e) {
- OPCPackage pkg = OPCPackage.openOrCreate(file);
+ OPCPackage pkg = OPCPackage.open(file);
return new XSSFWorkbook(pkg);
}
}
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java Sun Aug 5 13:05:44 2012
@@ -299,7 +299,7 @@ public abstract class XSLFSimpleShape ex
public void setLineWidth(double width) {
CTShapeProperties spPr = getSpPr();
if (width == 0.) {
- if (spPr.isSetLn())
+ if (spPr.isSetLn() && spPr.getLn().isSetW())
spPr.getLn().unsetW();
} else {
CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr
@@ -353,7 +353,7 @@ public abstract class XSLFSimpleShape ex
public void setLineDash(LineDash dash) {
CTShapeProperties spPr = getSpPr();
if (dash == null) {
- if (spPr.isSetLn())
+ if (spPr.isSetLn() && spPr.getLn().isSetPrstDash())
spPr.getLn().unsetPrstDash();
} else {
CTPresetLineDashProperties val = CTPresetLineDashProperties.Factory
@@ -406,7 +406,7 @@ public abstract class XSLFSimpleShape ex
public void setLineCap(LineCap cap) {
CTShapeProperties spPr = getSpPr();
if (cap == null) {
- if (spPr.isSetLn())
+ if (spPr.isSetLn() && spPr.getLn().isSetCap())
spPr.getLn().unsetCap();
} else {
CTLineProperties ln = spPr.isSetLn() ? spPr.getLn() : spPr
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java Sun Aug 5 13:05:44 2012
@@ -425,7 +425,13 @@ public class XSLFTextParagraph implement
}
};
fetchParagraphProperty(fetcher);
- return fetcher.getValue() == null ? getDefaultTabSize() : fetcher.getValue();
+ return fetcher.getValue() == null ? 0. : fetcher.getValue();
+ }
+
+ public void addTabStop(double value){
+ CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
+ CTTextTabStopList tabStops = pr.isSetTabLst() ? pr.getTabLst() : pr.addNewTabLst();
+ tabStops.addNewTab().setPos(Units.toEMU(value));
}
/**
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java Sun Aug 5 13:05:44 2012
@@ -353,6 +353,39 @@ public class XSLFTextRun {
}
/**
+ * Set the baseline for both the superscript and subscript fonts.
+ * <p>
+ * The size is specified using a percentage.
+ * Positive values indicate superscript, negative values indicate subscript.
+ * </p>
+ *
+ * @param baselineOffset
+ */
+ public void setBaselineOffset(double baselineOffset){
+ getRPr().setBaseline((int) baselineOffset * 1000);
+ }
+
+ /**
+ * Set whether the text in this run is formatted as superscript.
+ * Default base line offset is 30%
+ *
+ * @see #setBaselineOffset(double)
+ */
+ public void setSuperscript(boolean flag){
+ setBaselineOffset(flag ? 30. : 0.);
+ }
+
+ /**
+ * Set whether the text in this run is formatted as subscript.
+ * Default base line offset is -25%.
+ *
+ * @see #setBaselineOffset(double)
+ */
+ public void setSubscript(boolean flag){
+ setBaselineOffset(flag ? -25.0 : 0.);
+ }
+
+ /**
* @return whether a run of text will be formatted as a superscript text. Default is false.
*/
public boolean isSubscript() {
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java Sun Aug 5 13:05:44 2012
@@ -728,10 +728,6 @@ public class SXSSFCell implements Cell
}
void ensureTypeOrFormulaType(int type)
{
- assert type==CELL_TYPE_NUMERIC||
- type==CELL_TYPE_STRING||
- type==CELL_TYPE_BOOLEAN||
- type==CELL_TYPE_ERROR;
if(_value.getType()==type)
{
if(type==CELL_TYPE_STRING&&((StringValue)_value).isRichText())
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java Sun Aug 5 13:05:44 2012
@@ -212,7 +212,6 @@ public class SXSSFRow implements Row
*/
public Cell getCell(int cellnum, MissingCellPolicy policy)
{
- assert false;
Cell cell = getCell(cellnum);
if(policy == RETURN_NULL_AND_BLANK)
{
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Sun Aug 5 13:05:44 2012
@@ -17,19 +17,32 @@
package org.apache.poi.xssf.streaming;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
-import java.util.TreeMap;
import java.util.Map;
+import java.util.TreeMap;
+import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.ss.SpreadsheetVersion;
-import org.apache.poi.ss.usermodel.*;
-
+import org.apache.poi.ss.usermodel.AutoFilter;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellRange;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.DataValidation;
+import org.apache.poi.ss.usermodel.DataValidationHelper;
+import org.apache.poi.ss.usermodel.Drawing;
+import org.apache.poi.ss.usermodel.Footer;
+import org.apache.poi.ss.usermodel.Header;
+import org.apache.poi.ss.usermodel.PrintSetup;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.SheetUtil;
import org.apache.poi.xssf.usermodel.XSSFSheet;
-
-import org.apache.poi.hssf.util.PaneInformation;
-import org.apache.poi.ss.util.CellRangeAddress;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
@@ -1263,7 +1276,27 @@ public class SXSSFSheet implements Sheet
public SheetConditionalFormatting getSheetConditionalFormatting(){
return _sh.getSheetConditionalFormatting();
}
-
+
+
+ public CellRangeAddress getRepeatingRows() {
+ return _sh.getRepeatingRows();
+ }
+
+
+ public CellRangeAddress getRepeatingColumns() {
+ return _sh.getRepeatingColumns();
+ }
+
+ public void setRepeatingRows(CellRangeAddress rowRangeRef) {
+ _sh.setRepeatingRows(rowRangeRef);
+ }
+
+ public void setRepeatingColumns(CellRangeAddress columnRangeRef) {
+ _sh.setRepeatingColumns(columnRangeRef);
+ }
+
+
+
//end of interface implementation
/**
* Specifies how many rows can be accessed at most via getRow().
@@ -1330,7 +1363,6 @@ public class SXSSFSheet implements Sheet
if(entry.getValue()==row)
return entry.getKey().intValue();
}
- assert false;
return -1;
}
}
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java Sun Aug 5 13:05:44 2012
@@ -42,6 +42,7 @@ import java.util.zip.ZipEntry;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
+import org.apache.poi.ss.util.CellRangeAddress;
/**
* Streaming version of XSSFWorkbook implementing the "BigGridDemo" strategy.
@@ -244,7 +245,6 @@ public class SXSSFWorkbook implements Wo
XSSFSheet getXSSFSheet(SXSSFSheet sheet)
{
XSSFSheet result=_sxFromXHash.get(sheet);
- assert result!=null;
return result;
}
@@ -543,7 +543,6 @@ public class SXSSFWorkbook implements Wo
*/
public int getSheetIndex(Sheet sheet)
{
- assert sheet instanceof SXSSFSheet;
return _wb.getSheetIndex(getXSSFSheet((SXSSFSheet)sheet));
}
@@ -664,6 +663,9 @@ public class SXSSFWorkbook implements Wo
* @param endColumn 0 based end of repeating columns.
* @param startRow 0 based start of repeating rows.
* @param endRow 0 based end of repeating rows.
+ *
+ * @deprecated use {@link SXSSFSheet#setRepeatingRows(CellRangeAddress)}
+ * or {@link SXSSFSheet#setRepeatingColumns(CellRangeAddress)}
*/
public void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
{
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java Sun Aug 5 13:05:44 2012
@@ -204,7 +204,6 @@ public class SheetDataWriter {
break;
}
default: {
- assert false;
throw new RuntimeException("Huh?");
}
}
@@ -279,6 +278,9 @@ public class SheetDataWriter {
// the same rule applies to unicode surrogates and "not a character" symbols.
if( c < ' ' || Character.isLowSurrogate(c) || Character.isHighSurrogate(c) ||
('\uFFFE' <= c && c <= '\uFFFF')) {
+ if (counter > last) {
+ _out.write(chars, last, counter - last);
+ }
_out.write('?');
last = counter + 1;
}
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sun Aug 5 13:05:44 2012
@@ -41,6 +41,7 @@ import org.apache.poi.openxml4j.opc.Pack
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaShifter;
+import org.apache.poi.ss.formula.SheetNameFormatter;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
@@ -3185,4 +3186,162 @@ public class XSSFSheet extends POIXMLDoc
color.setIndexed(colorIndex);
pr.setTabColor(color);
}
+
+
+ public CellRangeAddress getRepeatingRows() {
+ return getRepeatingRowsOrColums(true);
+ }
+
+
+ public CellRangeAddress getRepeatingColumns() {
+ return getRepeatingRowsOrColums(false);
+ }
+
+ public void setRepeatingRows(CellRangeAddress rowRangeRef) {
+ CellRangeAddress columnRangeRef = getRepeatingColumns();
+ setRepeatingRowsAndColumns(rowRangeRef, columnRangeRef);
+ }
+
+
+ public void setRepeatingColumns(CellRangeAddress columnRangeRef) {
+ CellRangeAddress rowRangeRef = getRepeatingRows();
+ setRepeatingRowsAndColumns(rowRangeRef, columnRangeRef);
+ }
+
+
+ private void setRepeatingRowsAndColumns(
+ CellRangeAddress rowDef, CellRangeAddress colDef) {
+ int col1 = -1;
+ int col2 = -1;
+ int row1 = -1;
+ int row2 = -1;
+
+ if (rowDef != null) {
+ row1 = rowDef.getFirstRow();
+ row2 = rowDef.getLastRow();
+ if ((row1 == -1 && row2 != -1)
+ || row1 < -1 || row2 < -1 || row1 > row2) {
+ throw new IllegalArgumentException("Invalid row range specification");
+ }
+ }
+ if (colDef != null) {
+ col1 = colDef.getFirstColumn();
+ col2 = colDef.getLastColumn();
+ if ((col1 == -1 && col2 != -1)
+ || col1 < -1 || col2 < -1 || col1 > col2) {
+ throw new IllegalArgumentException(
+ "Invalid column range specification");
+ }
+ }
+
+ int sheetIndex = getWorkbook().getSheetIndex(this);
+
+ boolean removeAll = rowDef == null && colDef == null;
+
+ XSSFName name = getWorkbook().getBuiltInName(
+ XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
+ if (removeAll) {
+ if (name != null) {
+ getWorkbook().removeName(name);
+ }
+ return;
+ }
+ if (name == null) {
+ name = getWorkbook().createBuiltInName(
+ XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
+ }
+
+ String reference = getReferenceBuiltInRecord(
+ name.getSheetName(), col1, col2, row1, row2);
+ name.setRefersToFormula(reference);
+
+ // If the print setup isn't currently defined, then add it
+ // in but without printer defaults
+ // If it's already there, leave it as-is!
+ if (worksheet.isSetPageSetup() && worksheet.isSetPageMargins()) {
+ // Everything we need is already there
+ } else {
+ // Have initial ones put in place
+ getPrintSetup().setValidSettings(false);
+ }
+ }
+
+ private static String getReferenceBuiltInRecord(
+ String sheetName, int startC, int endC, int startR, int endR) {
+ // Excel example for built-in title:
+ // 'second sheet'!$E:$F,'second sheet'!$2:$3
+
+ CellReference colRef =
+ new CellReference(sheetName, 0, startC, true, true);
+ CellReference colRef2 =
+ new CellReference(sheetName, 0, endC, true, true);
+ CellReference rowRef =
+ new CellReference(sheetName, startR, 0, true, true);
+ CellReference rowRef2 =
+ new CellReference(sheetName, endR, 0, true, true);
+
+ String escapedName = SheetNameFormatter.format(sheetName);
+
+ String c = "";
+ String r = "";
+
+ if(startC == -1 && endC == -1) {
+ } else {
+ c = escapedName + "!$" + colRef.getCellRefParts()[2]
+ + ":$" + colRef2.getCellRefParts()[2];
+ }
+
+ if (startR == -1 && endR == -1) {
+
+ } else if (!rowRef.getCellRefParts()[1].equals("0")
+ && !rowRef2.getCellRefParts()[1].equals("0")) {
+ r = escapedName + "!$" + rowRef.getCellRefParts()[1]
+ + ":$" + rowRef2.getCellRefParts()[1];
+ }
+
+ StringBuffer rng = new StringBuffer();
+ rng.append(c);
+ if(rng.length() > 0 && r.length() > 0) {
+ rng.append(',');
+ }
+ rng.append(r);
+ return rng.toString();
+ }
+
+
+ private CellRangeAddress getRepeatingRowsOrColums(boolean rows) {
+ int sheetIndex = getWorkbook().getSheetIndex(this);
+ XSSFName name = getWorkbook().getBuiltInName(
+ XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
+ if (name == null ) {
+ return null;
+ }
+ String refStr = name.getRefersToFormula();
+ if (refStr == null) {
+ return null;
+ }
+ String[] parts = refStr.split(",");
+ int maxRowIndex = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
+ int maxColIndex = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
+ for (String part : parts) {
+ CellRangeAddress range = CellRangeAddress.valueOf(part);
+ if ((range.getFirstColumn() == 0
+ && range.getLastColumn() == maxColIndex)
+ || (range.getFirstColumn() == -1
+ && range.getLastColumn() == -1)) {
+ if (rows) {
+ return range;
+ }
+ } else if (range.getFirstRow() == 0
+ && range.getLastRow() == maxRowIndex
+ || (range.getFirstRow() == -1
+ && range.getLastRow() == -1)) {
+ if (!rows) {
+ return range;
+ }
+ }
+ }
+ return null;
+ }
+
}
Modified: poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/gsoc2012/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sun Aug 5 13:05:44 2012
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -51,6 +52,7 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
+import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.WorkbookUtil;
import org.apache.poi.util.*;
@@ -172,9 +174,15 @@ public class XSSFWorkbook extends POIXML
/**
* Constructs a XSSFWorkbook object given a OpenXML4J <code>Package</code> object,
- * see <a href="http://openxml4j.org/">www.openxml4j.org</a>.
+ * see <a href="http://poi.apache.org/oxml4j/">http://poi.apache.org/oxml4j/</a>.
+ *
+ * Once you have finished working with the Workbook, you should close the package
+ * by calling pkg.close, to avoid leaving file handles open.
+ *
+ * Creating a XSSFWorkbook from a file-backed OPC Package has a lower memory
+ * footprint than an InputStream backed one.
*
- * @param pkg the OpenXML4J <code>Package</code> object.
+ * @param pkg the OpenXML4J <code>OPC Package</code> object.
*/
public XSSFWorkbook(OPCPackage pkg) throws IOException {
super(pkg);
@@ -183,6 +191,20 @@ public class XSSFWorkbook extends POIXML
load(XSSFFactory.getInstance());
}
+ /**
+ * Constructs a XSSFWorkbook object, by buffering the whole stream into memory
+ * and then opening an {@link OPCPackage} object for it.
+ *
+ * Using an {@link InputStream} requires more memory than using a File, so
+ * if a {@link File} is available then you should instead do something like
+ * <pre><code>
+ * OPCPackage pkg = OPCPackage.open(path);
+ * XSSFWorkbook wb = new XSSFWorkbook(pkg);
+ * // work with the wb object
+ * ......
+ * pkg.close(); // gracefully closes the underlying zip file
+ * </code></pre>
+ */
public XSSFWorkbook(InputStream is) throws IOException {
super(PackageHelper.open(is));
@@ -904,6 +926,20 @@ public class XSSFWorkbook extends POIXML
throw new IllegalArgumentException("Named range was not found: " + name);
}
+
+ /**
+ * As {@link #removeName(String)} is not necessarily unique
+ * (name + sheet index is unique), this method is more accurate.
+ *
+ * @param name the name to remove.
+ */
+ void removeName(XSSFName name) {
+ if (!namedRanges.remove(name)) {
+ throw new IllegalArgumentException("Name was not found: " + name);
+ }
+ }
+
+
/**
* Delete the printarea for the sheet specified
*
@@ -1108,71 +1144,27 @@ public class XSSFWorkbook extends POIXML
* @param endColumn 0 based end of repeating columns.
* @param startRow 0 based start of repeating rows.
* @param endRow 0 based end of repeating rows.
+ *
+ * @deprecated use {@link XSSFSheet#setRepeatingRows(CellRangeAddress)}
+ * or {@link XSSFSheet#setRepeatingColumns(CellRangeAddress)}
*/
public void setRepeatingRowsAndColumns(int sheetIndex,
int startColumn, int endColumn,
int startRow, int endRow) {
- // Check arguments
- if ((startColumn == -1 && endColumn != -1) || startColumn < -1 || endColumn < -1 || startColumn > endColumn)
- throw new IllegalArgumentException("Invalid column range specification");
- if ((startRow == -1 && endRow != -1) || startRow < -1 || endRow < -1 || startRow > endRow)
- throw new IllegalArgumentException("Invalid row range specification");
-
- XSSFSheet sheet = getSheetAt(sheetIndex);
- boolean removingRange = startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1;
-
- XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
- if (removingRange) {
- if(name != null)namedRanges.remove(name);
- return;
- }
- if (name == null) {
- name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
- }
-
- String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
- name.setRefersToFormula(reference);
-
- // If the print setup isn't currently defined, then add it
- // in but without printer defaults
- // If it's already there, leave it as-is!
- CTWorksheet ctSheet = sheet.getCTWorksheet();
- if(ctSheet.isSetPageSetup() && ctSheet.isSetPageMargins()) {
- // Everything we need is already there
- } else {
- // Have initial ones put in place
- XSSFPrintSetup printSetup = sheet.getPrintSetup();
- printSetup.setValidSettings(false);
- }
- }
-
- private static String getReferenceBuiltInRecord(String sheetName, int startC, int endC, int startR, int endR) {
- //windows excel example for built-in title: 'second sheet'!$E:$F,'second sheet'!$2:$3
- CellReference colRef = new CellReference(sheetName, 0, startC, true, true);
- CellReference colRef2 = new CellReference(sheetName, 0, endC, true, true);
-
- String escapedName = SheetNameFormatter.format(sheetName);
-
- String c;
- if(startC == -1 && endC == -1) c= "";
- else c = escapedName + "!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
-
- CellReference rowRef = new CellReference(sheetName, startR, 0, true, true);
- CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
-
- String r = "";
- if(startR == -1 && endR == -1) r = "";
- else {
- if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) {
- r = escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
- }
- }
+ XSSFSheet sheet = getSheetAt(sheetIndex);
+
+ CellRangeAddress rows = null;
+ CellRangeAddress cols = null;
+
+ if (startRow != -1) {
+ rows = new CellRangeAddress(startRow, endRow, -1, -1);
+ }
+ if (startColumn != -1) {
+ cols = new CellRangeAddress(-1, -1, startColumn, endColumn);
+ }
- StringBuffer rng = new StringBuffer();
- rng.append(c);
- if(rng.length() > 0 && r.length() > 0) rng.append(',');
- rng.append(r);
- return rng.toString();
+ sheet.setRepeatingRows(rows);
+ sheet.setRepeatingColumns(cols);
}
private static String getReferencePrintArea(String sheetName, int startC, int endC, int startR, int endR) {
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFColor.java Sun Aug 5 13:05:44 2012
@@ -17,11 +17,7 @@
package org.apache.poi.xslf.usermodel;
import junit.framework.TestCase;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.STPresetColorVal;
-import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
import java.awt.Color;
@@ -149,4 +145,19 @@ public class TestXSLFColor extends TestC
assertEquals(XSLFColor.presetColors.get(colorName), color.getColor());
}
}
+
+ public void testSys() {
+ CTColor xml = CTColor.Factory.newInstance();
+ CTSystemColor sys = xml.addNewSysClr();
+ sys.setVal(STSystemColorVal.GRAY_TEXT);
+ XSLFColor color = new XSLFColor(xml, null, null);
+ assertEquals(Color.black, color.getColor());
+
+ xml = CTColor.Factory.newInstance();
+ sys = xml.addNewSysClr();
+ sys.setLastClr(new byte[]{(byte)0xFF, 0, 0});
+ color = new XSLFColor(xml, null, null);
+ assertEquals(Color.red, color.getColor());
+ }
+
}
\ No newline at end of file
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java Sun Aug 5 13:05:44 2012
@@ -19,9 +19,7 @@ package org.apache.poi.xslf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.XSLFTestDataSamples;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;
-import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
import java.awt.Color;
@@ -102,6 +100,20 @@ public class TestXSLFSimpleShape extends
assertEquals(null, shape.getLineColor());
// setting dash width to null unsets the SolidFill element
assertFalse(shape.getSpPr().getLn().isSetSolidFill());
+
+ XSLFSimpleShape ln2 = slide.createAutoShape();
+ ln2.setLineDash(LineDash.DOT);
+ assertEquals(LineDash.DOT, ln2.getLineDash());
+ ln2.setLineWidth(0.);
+ assertEquals(0., ln2.getLineWidth());
+
+ XSLFSimpleShape ln3 = slide.createAutoShape();
+ ln3.setLineWidth(1.);
+ assertEquals(1., ln3.getLineWidth());
+ ln3.setLineDash(null);
+ assertEquals(null, ln3.getLineDash());
+ ln3.setLineCap(null);
+ assertEquals(null, ln3.getLineDash());
}
public void testFill() {
@@ -231,4 +243,14 @@ public class TestXSLFSimpleShape extends
}
+ public void testShadowEffects(){
+ XMLSlideShow ppt = new XMLSlideShow();
+ XSLFSlide slide = ppt.createSlide();
+ CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();
+ CTEffectStyleList lst = styleMatrix.getEffectStyleLst();
+ assertNotNull(lst);
+ for(CTEffectStyleItem ef : lst.getEffectStyleList()){
+ CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();
+ }
+ }
}
\ No newline at end of file
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableStyles.java Sun Aug 5 13:05:44 2012
@@ -17,6 +17,7 @@
package org.apache.poi.xslf.usermodel;
import junit.framework.TestCase;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableStyle;
/**
* @author Yegor Kozlov
@@ -30,4 +31,9 @@ public class TestXSLFTableStyles extends
assertEquals(0, tblStyles.getStyles().size());
}
+
+ public void testStyle(){
+ CTTableStyle obj = CTTableStyle.Factory.newInstance();
+ XSLFTableStyle style = new XSLFTableStyle(obj);
+ }
}
\ No newline at end of file
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java Sun Aug 5 13:05:44 2012
@@ -289,6 +289,17 @@ public class TestXSLFTextParagraph exten
p.setBullet(false);
assertFalse(p.isBullet());
+
+ p.setBulletAutoNumber(ListAutoNumber.ALPHA_LC_PARENT_BOTH, 1);
+
+ double tabStop = p.getTabStop(0);
+ assertEquals(0.0, tabStop);
+
+ p.addTabStop(100.);
+ assertEquals(100., p.getTabStop(0));
+
+ assertEquals(72.0, p.getDefaultTabSize());
+
}
public void testLineBreak(){
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java Sun Aug 5 13:05:44 2012
@@ -56,5 +56,16 @@ public class TestXSLFTextRun extends Tes
r.setFontSize(13.0);
assertEquals(13.0, r.getFontSize());
+ assertEquals(false, r.isSuperscript());
+ r.setSuperscript(true);
+ assertEquals(true, r.isSuperscript());
+ r.setSuperscript(false);
+ assertEquals(false, r.isSuperscript());
+
+ assertEquals(false, r.isSubscript());
+ r.setSubscript(true);
+ assertEquals(true, r.isSubscript());
+ r.setSubscript(false);
+ assertEquals(false, r.isSubscript());
}
}
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java Sun Aug 5 13:05:44 2012
@@ -154,6 +154,14 @@ public final class TestSXSSFWorkbook ext
tmp = wr.getTempFile();
assertTrue(tmp.getName().startsWith("poi-sxssf-sheet-xml"));
assertTrue(tmp.getName().endsWith(".gz"));
+
+ //Test escaping of Unicode control characters
+ wb = new SXSSFWorkbook();
+ wb.createSheet("S1").createRow(0).createCell(0).setCellValue("value\u0019");
+ XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
+ Cell cell = xssfWorkbook.getSheet("S1").getRow(0).getCell(0);
+ assertEquals("value?", cell.getStringCellValue());
+
}
public void testGZipSheetdataWriter(){
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java Sun Aug 5 13:05:44 2012
@@ -20,6 +20,7 @@ package org.apache.poi.xssf.usermodel;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.ss.usermodel.BaseTestNamedRange;
+import org.apache.poi.ss.util.CellRangeAddress;
/**
* @author Yegor Kozlov
@@ -35,13 +36,15 @@ public final class TestXSSFName extends
// First test that setting RR&C for same sheet more than once only creates a
// single Print_Titles built-in record
XSSFWorkbook wb = new XSSFWorkbook();
- wb.createSheet("First Sheet");
+ XSSFSheet sheet1 = wb.createSheet("First Sheet");
- wb.setRepeatingRowsAndColumns(0, -1, -1, -1, -1);
+ sheet1.setRepeatingRows(null);
+ sheet1.setRepeatingColumns(null);
// set repeating rows and columns twice for the first sheet
for (int i = 0; i < 2; i++) {
- wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3);
+ sheet1.setRepeatingRows(CellRangeAddress.valueOf("1:4"));
+ sheet1.setRepeatingColumns(CellRangeAddress.valueOf("A:A"));
//sheet.createFreezePane(0, 3);
}
assertEquals(1, wb.getNumberOfNames());
@@ -51,18 +54,18 @@ public final class TestXSSFName extends
assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula());
//remove the columns part
- wb.setRepeatingRowsAndColumns(0, -1, -1, 0, 3);
+ sheet1.setRepeatingColumns(null);
assertEquals("'First Sheet'!$1:$4", nr1.getRefersToFormula());
//revert
- wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3);
+ sheet1.setRepeatingColumns(CellRangeAddress.valueOf("A:A"));
//remove the rows part
- wb.setRepeatingRowsAndColumns(0, 0, 0, -1, -1);
+ sheet1.setRepeatingRows(null);
assertEquals("'First Sheet'!$A:$A", nr1.getRefersToFormula());
//revert
- wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3);
+ sheet1.setRepeatingRows(CellRangeAddress.valueOf("1:4"));
// Save and re-open
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
@@ -75,8 +78,9 @@ public final class TestXSSFName extends
// check that setting RR&C on a second sheet causes a new Print_Titles built-in
// name to be created
- nwb.createSheet("SecondSheet");
- nwb.setRepeatingRowsAndColumns(1, 1, 2, 0, 0);
+ XSSFSheet sheet2 = nwb.createSheet("SecondSheet");
+ sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:1"));
+ sheet2.setRepeatingColumns(CellRangeAddress.valueOf("B:C"));
assertEquals(2, nwb.getNumberOfNames());
XSSFName nr2 = nwb.getNameAt(1);
@@ -84,6 +88,7 @@ public final class TestXSSFName extends
assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
assertEquals("SecondSheet!$B:$C,SecondSheet!$1:$1", nr2.getRefersToFormula());
- nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
+ sheet2.setRepeatingRows(null);
+ sheet2.setRepeatingColumns(null);
}
}
Modified: poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java?rev=1369572&r1=1369571&r2=1369572&view=diff
==============================================================================
--- poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java (original)
+++ poi/branches/gsoc2012/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java Sun Aug 5 13:05:44 2012
@@ -337,4 +337,10 @@ public final class TestXWPFDocument exte
doc.getPackage().revert();
}
+
+ public void testSettings(){
+ XWPFSettings settings = new XWPFSettings();
+ settings.setZoomPercent(50);
+ assertEquals(50, settings.getZoomPercent());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org