diff options
Diffstat (limited to 'src/ooxml/java/org')
-rwxr-xr-x | src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java | 65 | ||||
-rwxr-xr-x[-rw-r--r--] | src/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java (renamed from src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorksheet.java) | 35 | ||||
-rwxr-xr-x | src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java | 73 | ||||
-rwxr-xr-x | src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java | 77 | ||||
-rwxr-xr-x | src/ooxml/java/org/apache/poi/xssf/usermodel/ShapeTypes.java | 2 | ||||
-rwxr-xr-x | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java | 2 | ||||
-rwxr-xr-x | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java | 455 | ||||
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java | 6 |
8 files changed, 699 insertions, 16 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java new file mode 100755 index 0000000000..3306d0680c --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java @@ -0,0 +1,65 @@ +/* ==================================================================== + 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.xssf.usermodel; + +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder; + +/** + * Specifies printed page order. + * + * @author Gisella Bronzetti + */ +public enum PageOrder { + + /** + * Order pages vertically first, then move horizontally. + */ + DOWN_THEN_OVER(STPageOrder.DOWN_THEN_OVER), + /** + * Order pages horizontally first, then move vertically + */ + OVER_THEN_DOWN(STPageOrder.OVER_THEN_DOWN); + + + private STPageOrder.Enum order; + + + PageOrder(STPageOrder.Enum order) { + this.order = order; + } + + /** + * Returns value of pages order + * + * @return String value of pages order + */ + public STPageOrder.Enum getValue() { + return order; + } + + + public static PageOrder valueOf(STPageOrder.Enum pageOrder) { + switch (pageOrder.intValue()) { + case STPageOrder.INT_DOWN_THEN_OVER: + return DOWN_THEN_OVER; + case STPageOrder.INT_OVER_THEN_DOWN: + return OVER_THEN_DOWN; + } + throw new RuntimeException("PageOrder value [" + pageOrder + "] not supported"); + } +} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorksheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java index e03ed13e0b..d0a94f00db 100644..100755 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorksheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java @@ -17,15 +17,28 @@ package org.apache.poi.xssf.usermodel; -import org.apache.poi.ss.usermodel.Sheet; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet; -import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; - -public class XSSFWorksheet extends XSSFSheet implements Sheet{ - - public XSSFWorksheet(CTSheet sheet, CTWorksheet worksheet, - XSSFWorkbook workbook) { - super(sheet, worksheet, workbook); - } - +/** + * The enumeration value indicating the possible paper size for a sheet + * + * @author Daniele Montagni + */ +public enum PaperSize { + LETTER_PAPER, + LETTER_SMALL_PAPER, + TABLOID_PAPER, + LEDGER_PAPER, + LEGAL_PAPER, + STATEMENT_PAPER, + EXECUTIVE_PAPER, + A3_PAPER, + A4_PAPER, + A4_SMALL_PAPER, + A5_PAPER, + B4_PAPER, + B5_PAPER, + FOLIO_PAPER, + QUARTO_PAPER, + STANDARD_PAPER_10_14, + STANDARD_PAPER_11_17; + } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java new file mode 100755 index 0000000000..822721085d --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java @@ -0,0 +1,73 @@ +/* ==================================================================== + 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.xssf.usermodel; + +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments; + +/** + * These enumerations specify how cell comments shall be displayed for paper printing purposes. + * + * @author Gisella Bronzetti + */ +public enum PrintCellComments { + + /** + * Do not print cell comments. + */ + NONE(STCellComments.NONE), + /** + * Print cell comments as displayed. + */ + AS_DISPLAYED(STCellComments.AS_DISPLAYED), + /** + * Print cell comments at end of document. + */ + AT_END(STCellComments.AT_END); + + + private STCellComments.Enum comments; + + + PrintCellComments(STCellComments.Enum comments) { + this.comments = comments; + } + + + /** + * Returns comments of cell + * + * @return String comments of cell + */ + public STCellComments.Enum getValue() { + return comments; + } + + + public static PrintCellComments valueOf(STCellComments.Enum cellComment) { + switch (cellComment.intValue()) { + case STCellComments.INT_AS_DISPLAYED: + return AS_DISPLAYED; + case STCellComments.INT_AT_END: + return AT_END; + case STCellComments.INT_NONE: + return NONE; + } + throw new RuntimeException("PrintCellComments: value [" + cellComment + "] not supported"); + } + +} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java new file mode 100755 index 0000000000..3b65f3ed32 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java @@ -0,0 +1,77 @@ +/* ==================================================================== + 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.xssf.usermodel; + +import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation; + +/** + * The enumeration value indicating the print orientation for a sheet. + * + * @author Gisella Bronzetti + */ +public enum PrintOrientation { + + /** + * orientation not specified + */ + DEFAULT(STOrientation.DEFAULT), + /** + * portrait orientation + */ + PORTRAIT(STOrientation.PORTRAIT), + /** + * landscape orientations + */ + LANDSCAPE(STOrientation.LANDSCAPE); + + + private STOrientation.Enum orientation; + + + PrintOrientation(STOrientation.Enum orientation) { + this.orientation = orientation; + } + + + /** + * Returns value of the orientation + * + * @return String value of the orientation + */ + public STOrientation.Enum getValue() { + return orientation; + } + + + public static PrintOrientation valueOf(STOrientation.Enum orient) { + switch (orient.intValue()) { + case STOrientation.INT_DEFAULT: + return DEFAULT; + case STOrientation.INT_LANDSCAPE: + return LANDSCAPE; + case STOrientation.INT_PORTRAIT: + return PORTRAIT; + /* + default: + return DEFAULT; + */ + } + throw new RuntimeException("Orientation value [" + orient + "] not supported"); + } + +} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/ShapeTypes.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/ShapeTypes.java index 4b2cdf8c4d..afe471fb22 100755 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/ShapeTypes.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/ShapeTypes.java @@ -17,7 +17,7 @@ package org.apache.poi.xssf.usermodel;
/**
- * All know type of automatic shapes in DrawingML
+ * All known types of automatic shapes in DrawingML
*
* @author Yegor Kozlov
*/
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java index b451b4ef3d..1172612eb0 100755 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java @@ -45,7 +45,7 @@ public class XSSFDrawing extends POIXMLDocumentPart { /**
* Create a new SpreadsheetML drawing
*
- * @see org.apache.poi.xssf.usermodel.XSSFWorksheet#createDrawingPatriarch()
+ * @see org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch()
*/
public XSSFDrawing() {
super(null, null);
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java new file mode 100755 index 0000000000..cbfe9c0f30 --- /dev/null +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java @@ -0,0 +1,455 @@ +/* ==================================================================== + 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.xssf.usermodel; + +import org.apache.poi.ss.usermodel.PrintSetup; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup; +import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet; + + +/** + * Page setup and page margins settings for the worksheet. + */ +public class XSSFPrintSetup implements PrintSetup { + + private CTWorksheet ctWorksheet; + private CTPageSetup pageSetup; + private CTPageMargins pageMargins; + + + public XSSFPrintSetup(CTWorksheet worksheet) { + if (worksheet == null) throw new NullPointerException(""); + this.ctWorksheet = worksheet; + this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup(); + this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins(); + } + + public XSSFPrintSetup(XSSFSheet sheet) { + this(sheet.getWorksheet()); + } + + public XSSFPrintSetup(CTPageSetup pageSetup, CTPageMargins pageMargins) { + this.pageMargins = pageMargins; + this.pageSetup = pageSetup; + } + + + /** + * Set the paper size. + * + * @param size the paper size. + */ + public void setPaperSize(short size) { + pageSetup.setPaperSize(size); + } + + /** + * Set the paper size as enum value. + * + * @param size value for the paper size. + */ + public void setPaperSize(PaperSize size) { + setPaperSize((short) (size.ordinal() + 1)); + } + + /** + * Set the scale. + * Valid values range from 10 to 400. + * This setting is overridden when fitToWidth and/or fitToHeight are in use + * + * @param scale the scale to use + */ + public void setScale(short scale) { + if (scale < 10 || scale > 400) throw new RuntimeException("Scale value not accepted: you must choose a value between 10 and 400."); + pageSetup.setScale(scale); + } + + /** + * Set the page numbering start. + * Page number for first printed page. If no value is specified, then 'automatic' is assumed. + * + * @param start the page numbering start + */ + public void setPageStart(short start) { + pageSetup.setFirstPageNumber(start); + } + + /** + * Set the number of pages wide to fit the sheet in + * + * @param width the number of pages + */ + public void setFitWidth(short width) { + pageSetup.setFitToWidth(width); + } + + /** + * Set the number of pages high to fit the sheet in + * + * @param height the number of pages + */ + public void setFitHeight(short height) { + pageSetup.setFitToHeight(height); + } + + /** + * Set whether to go left to right or top down in ordering + * + * @param ltor left to right + */ + public void setLeftToRight(boolean ltor) { + if (ltor) + setPageOrder(PageOrder.OVER_THEN_DOWN); + } + + /** + * Set whether to print in landscape + * + * @param ls landscape + */ + public void setLandscape(boolean ls) { + if (ls) + setOrientation(PrintOrientation.LANDSCAPE); + } + + /** + * Use the printer's defaults settings for page setup values and don't use the default values + * specified in the schema. For example, if dpi is not present or specified in the XML, the + * a plication shall not assume 600dpi as specified in the schema as a default and instead + * shall let the printer specify the default dpi. + * + * @param valid Valid + */ + public void setValidSettings(boolean valid) { + pageSetup.setUsePrinterDefaults(valid); + } + + /** + * Set whether it is black and white + * + * @param mono Black and white + */ + public void setNoColor(boolean mono) { + pageSetup.setBlackAndWhite(mono); + } + + /** + * Set whether it is in draft mode + * + * @param d draft + */ + public void setDraft(boolean d) { + pageSetup.setDraft(d); + } + + /** + * Print the include notes + * + * @param printnotes print the notes + */ + public void setNotes(boolean printnotes) { + if (printnotes) + pageSetup.setCellComments(PrintCellComments.AS_DISPLAYED.getValue()); + } + + /** + * Set no orientation. + * + * @param orientation Orientation. + */ + public void setNoOrientation(boolean orientation) { + if (orientation) { + setOrientation(PrintOrientation.DEFAULT); + } + } + + /** + * Set whether to use page start + * + * @param page Use page start + */ + public void setUsePage(boolean page) { + pageSetup.setUseFirstPageNumber(page); + } + + /** + * Sets the horizontal resolution. + * + * @param resolution horizontal resolution + */ + public void setHResolution(short resolution) { + pageSetup.setHorizontalDpi(resolution); + } + + /** + * Sets the vertical resolution. + * + * @param resolution vertical resolution + */ + public void setVResolution(short resolution) { + pageSetup.setVerticalDpi(resolution); + } + + /** + * Sets the header margin. + * + * @param headermargin header margin + */ + public void setHeaderMargin(double headermargin) { + pageMargins.setHeader(headermargin); + } + + /** + * Sets the footer margin. + * + * @param footermargin footer margin + */ + public void setFooterMargin(double footermargin) { + pageMargins.setFooter(footermargin); + } + + /** + * Sets the number of copies. + * + * @param copies number of copies + */ + public void setCopies(short copies) { + pageSetup.setCopies(copies); + } + + /** + * Orientation of the page: landscape - portrait. + * + * @param orientation - Orientation of the page + * @see PrintOrientation + */ + public void setOrientation(PrintOrientation orientation) { + pageSetup.setOrientation(orientation.getValue()); + } + + /** + * Orientation of the page: landscape - portrait. + * + * @return Orientation of the page + * @see PrintOrientation + */ + public PrintOrientation getOrientation() { + return (pageSetup.getOrientation() == null) ? null : PrintOrientation.valueOf(pageSetup.getOrientation()); + } + + + public PrintCellComments getCellComment() { + return (pageSetup.getCellComments() == null) ? null : PrintCellComments.valueOf(pageSetup.getCellComments()); + } + + /** + * Set print page order. + * + * @param pageOrder + */ + public void setPageOrder(PageOrder pageOrder) { + pageSetup.setPageOrder(pageOrder.getValue()); + } + + /** + * get print page order. + * + * @return PageOrder + */ + public PageOrder getPageOrder() { + return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder()); + } + + /** + * Returns the paper size. + * + * @return short - paper size + */ + public short getPaperSize() { + return (short) pageSetup.getPaperSize(); + } + + /** + * Returns the paper size as enum. + * + * @return PaperSize paper size + * @see PaperSize + */ + public PaperSize getPaperSizeEnum() { + return PaperSize.values()[((int) getPaperSize() - 1)]; + } + + /** + * Returns the scale. + * + * @return short - scale + */ + public short getScale() { + return (short) pageSetup.getScale(); + } + + /** + * Set the page numbering start. + * Page number for first printed page. If no value is specified, then 'automatic' is assumed. + * + * @return page number for first printed page + */ + public short getPageStart() { + return (short) pageSetup.getFirstPageNumber(); + } + + /** + * Returns the number of pages wide to fit sheet in. + * + * @return number of pages wide to fit sheet in + */ + public short getFitWidth() { + return (short) pageSetup.getFitToWidth(); + } + + /** + * Returns the number of pages high to fit the sheet in. + * + * @return number of pages high to fit the sheet in + */ + public short getFitHeight() { + return (short) pageSetup.getFitToHeight(); + } + + /** + * Returns the left to right print order. + * + * @return left to right print order + */ + public boolean getLeftToRight() { + return getPageOrder() == PageOrder.OVER_THEN_DOWN; + } + + /** + * Returns the landscape mode. + * + * @return landscape mode + */ + public boolean getLandscape() { + return getOrientation() == PrintOrientation.LANDSCAPE; + } + + /** + * Use the printerŐs defaults settings for page setup values and don't use the default values + * specified in the schema. For example, if dpi is not present or specified in the XML, the + * application shall not assume 600dpi as specified in the schema as a default and instead + * shall let the printer specify the default dpi. + * + * @return valid settings + */ + public boolean getValidSettings() { + return pageSetup.getUsePrinterDefaults(); + } + + /** + * Returns the black and white setting. + * + * @return black and white setting + */ + public boolean getNoColor() { + return pageSetup.getBlackAndWhite(); + } + + /** + * Returns the draft mode. + * + * @return draft mode + */ + public boolean getDraft() { + return pageSetup.getDraft(); + } + + /** + * Returns the print notes. + * + * @return print notes + */ + public boolean getNotes() { + return getCellComment() == PrintCellComments.AS_DISPLAYED; + } + + /** + * Returns the no orientation. + * + * @return no orientation + */ + public boolean getNoOrientation() { + return getOrientation() == PrintOrientation.DEFAULT; + } + + /** + * Returns the use page numbers. + * + * @return use page numbers + */ + public boolean getUsePage() { + return pageSetup.getUseFirstPageNumber(); + } + + /** + * Returns the horizontal resolution. + * + * @return horizontal resolution + */ + public short getHResolution() { + return (short) pageSetup.getHorizontalDpi(); + } + + /** + * Returns the vertical resolution. + * + * @return vertical resolution + */ + public short getVResolution() { + return (short) pageSetup.getVerticalDpi(); + } + + /** + * Returns the header margin. + * + * @return header margin + */ + public double getHeaderMargin() { + return pageMargins.getHeader(); + } + + /** + * Returns the footer margin. + * + * @return footer margin + */ + public double getFooterMargin() { + return pageMargins.getFooter(); + } + + /** + * Returns the number of copies. + * + * @return number of copies + */ + public short getCopies() { + return (short) pageSetup.getCopies(); + } + +} diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 4db48fe2c7..2055894a8c 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import java.util.*; import javax.xml.namespace.QName; +import org.apache.poi.hssf.usermodel.HSSFPrintSetup; import org.apache.poi.hssf.util.PaneInformation; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CommentsSource; @@ -699,9 +700,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { return counter; } - public PrintSetup getPrintSetup() { - // TODO Auto-generated method stub - return null; + public XSSFPrintSetup getPrintSetup() { + return new XSSFPrintSetup(getWorksheet()); } public boolean getProtect() { |