Author: fanningpj
Date: Thu Jul 26 14:18:13 2018
New Revision: 1836732
URL: http://svn.apache.org/viewvc?rev=1836732&view=rev
Log:
start process of introducing an interface for Styles and Themes Tables
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Styles.java (with
props)
poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Themes.java (with
props)
Modified:
poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java
Modified:
poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java?rev=1836732&r1=1836731&r2=1836732&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
Thu Jul 26 14:18:13 2018
@@ -34,6 +34,7 @@ import org.apache.poi.ooxml.util.SAXHelp
import
org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler.SheetContentsHandler;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.model.SharedStrings;
+import org.apache.poi.xssf.model.Styles;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.xml.sax.ContentHandler;
@@ -180,7 +181,7 @@ public class XLSX2CSV {
* @throws SAXException if parsing the XML data fails.
*/
public void processSheet(
- StylesTable styles,
+ Styles styles,
SharedStrings strings,
SheetContentsHandler sheetHandler,
InputStream sheetInputStream) throws IOException, SAXException {
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java?rev=1836732&r1=1836731&r2=1836732&view=diff
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
(original)
+++
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
Thu Jul 26 14:18:13 2018
@@ -27,10 +27,7 @@ import org.apache.poi.ss.usermodel.RichT
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
-import org.apache.poi.xssf.model.Comments;
-import org.apache.poi.xssf.model.CommentsTable;
-import org.apache.poi.xssf.model.SharedStrings;
-import org.apache.poi.xssf.model.StylesTable;
+import org.apache.poi.xssf.model.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
@@ -63,7 +60,7 @@ public class XSSFSheetXMLHandler extends
/**
* Table with the styles used for formatting
*/
- private StylesTable stylesTable;
+ private Styles stylesTable;
/**
* Table with cell comments
@@ -117,7 +114,7 @@ public class XSSFSheetXMLHandler extends
* @param strings Table of shared strings
*/
public XSSFSheetXMLHandler(
- StylesTable styles,
+ Styles styles,
CommentsTable comments,
SharedStrings strings,
SheetContentsHandler sheetContentsHandler,
@@ -140,7 +137,7 @@ public class XSSFSheetXMLHandler extends
* @param strings Table of shared strings
*/
public XSSFSheetXMLHandler(
- StylesTable styles,
+ Styles styles,
SharedStrings strings,
SheetContentsHandler sheetContentsHandler,
DataFormatter dataFormatter,
@@ -155,7 +152,7 @@ public class XSSFSheetXMLHandler extends
* @param strings Table of shared strings
*/
public XSSFSheetXMLHandler(
- StylesTable styles,
+ Styles styles,
SharedStrings strings,
SheetContentsHandler sheetContentsHandler,
boolean formulasNotResults) {
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java?rev=1836732&r1=1836731&r2=1836732&view=diff
==============================================================================
---
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
(original)
+++
poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFEventBasedExcelExtractor.java
Thu Jul 26 14:18:13 2018
@@ -39,10 +39,7 @@ import org.apache.poi.xssf.eventusermode
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
import
org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler.SheetContentsHandler;
-import org.apache.poi.xssf.model.Comments;
-import org.apache.poi.xssf.model.CommentsTable;
-import org.apache.poi.xssf.model.SharedStrings;
-import org.apache.poi.xssf.model.StylesTable;
+import org.apache.poi.xssf.model.*;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSimpleShape;
@@ -232,7 +229,7 @@ public class XSSFEventBasedExcelExtracto
*/
public void processSheet(
SheetContentsHandler sheetContentsExtractor,
- StylesTable styles,
+ Styles styles,
CommentsTable comments,
SharedStrings strings,
InputStream sheetInputStream)
Added: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Styles.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Styles.java?rev=1836732&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Styles.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Styles.java Thu Jul 26
14:18:13 2018
@@ -0,0 +1,114 @@
+package org.apache.poi.xssf.model;
+
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
+import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
+
+public interface Styles {
+
+ /**
+ * Get number format string given its id
+ *
+ * @param fmtId number format id
+ * @return number format code
+ */
+ String getNumberFormatAt(short fmtId);
+
+ /**
+ * Puts <code>fmt</code> in the numberFormats map if the format is not
+ * already in the the number format style table.
+ * Does nothing if <code>fmt</code> is already in number format style
table.
+ *
+ * @param fmt the number format to add to number format style table
+ * @return the index of <code>fmt</code> in the number format style table
+ * @throws IllegalStateException if adding the number format to the styles
table
+ * would exceed the max allowed.
+ */
+ int putNumberFormat(String fmt);
+
+ /**
+ * Add a number format with a specific ID into the numberFormats map.
+ * If a format with the same ID already exists, overwrite the format code
+ * with <code>fmt</code>
+ * This may be used to override built-in number formats.
+ *
+ * @param index the number format ID
+ * @param fmt the number format code
+ */
+ void putNumberFormat(short index, String fmt);
+
+ /**
+ * Remove a number format from the style table if it exists.
+ * All cell styles with this number format will be modified to use the
default number format.
+ *
+ * @param index the number format id to remove
+ * @return true if the number format was removed
+ */
+ boolean removeNumberFormat(short index);
+
+ /**
+ * Remove a number format from the style table if it exists
+ * All cell styles with this number format will be modified to use the
default number format
+ *
+ * @param fmt the number format to remove
+ * @return true if the number format was removed
+ */
+ boolean removeNumberFormat(String fmt);
+
+ XSSFFont getFontAt(int idx);
+
+ /**
+ * Records the given font in the font table.
+ * Will re-use an existing font index if this
+ * font matches another, EXCEPT if forced
+ * registration is requested.
+ * This allows people to create several fonts
+ * then customise them later.
+ * Note - End Users probably want to call
+ * {@link XSSFFont#registerTo(StylesTable)}
+ */
+ int putFont(XSSFFont font, boolean forceRegistration);
+
+ /**
+ * Records the given font in the font table.
+ * Will re-use an existing font index if this
+ * font matches another.
+ */
+ int putFont(XSSFFont font);
+
+ /**
+ *
+ * @param idx style index
+ * @return XSSFCellStyle or null if idx is out of bounds for xfs array
+ */
+ XSSFCellStyle getStyleAt(int idx);
+
+ int putStyle(XSSFCellStyle style);
+
+ XSSFCellBorder getBorderAt(int idx);
+
+ /**
+ * Adds a border to the border style table if it isn't already in the
style table
+ * Does nothing if border is already in borders style table
+ *
+ * @param border border to add
+ * @return the index of the added border
+ */
+ int putBorder(XSSFCellBorder border);
+
+ XSSFCellFill getFillAt(int idx);
+
+ /**
+ * Adds a fill to the fill style table if it isn't already in the style
table
+ * Does nothing if fill is already in fill style table
+ *
+ * @param fill fill to add
+ * @return the index of the added fill
+ */
+ int putFill(XSSFCellFill fill);
+
+ int getNumCellStyles();
+
+ int getNumDataFormats();
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Styles.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=1836732&r1=1836731&r2=1836732&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Thu Jul
26 14:18:13 2018
@@ -56,7 +56,7 @@ import org.openxmlformats.schemas.spread
/**
* Table of styles shared across all sheets in a workbook.
*/
-public class StylesTable extends POIXMLDocumentPart {
+public class StylesTable extends POIXMLDocumentPart implements Styles {
private final SortedMap<Short, String> numberFormats = new TreeMap<>();
private final List<XSSFFont> fonts = new ArrayList<>();
private final List<XSSFCellFill> fills = new ArrayList<>();
@@ -261,6 +261,7 @@ public class StylesTable extends POIXMLD
* @param fmtId number format id
* @return number format code
*/
+ @Override
public String getNumberFormatAt(short fmtId) {
return numberFormats.get(fmtId);
}
@@ -285,6 +286,7 @@ public class StylesTable extends POIXMLD
* @throws IllegalStateException if adding the number format to the styles
table
* would exceed the {@link #MAXIMUM_NUMBER_OF_DATA_FORMATS} allowed.
*/
+ @Override
public int putNumberFormat(String fmt) {
// Check if number format already exists
if (numberFormats.containsValue(fmt)) {
@@ -334,6 +336,7 @@ public class StylesTable extends POIXMLD
* @param index the number format ID
* @param fmt the number format code
*/
+ @Override
public void putNumberFormat(short index, String fmt) {
numberFormats.put(index, fmt);
}
@@ -345,6 +348,7 @@ public class StylesTable extends POIXMLD
* @param index the number format id to remove
* @return true if the number format was removed
*/
+ @Override
public boolean removeNumberFormat(short index) {
String fmt = numberFormats.remove(index);
boolean removed = (fmt != null);
@@ -366,11 +370,13 @@ public class StylesTable extends POIXMLD
* @param fmt the number format to remove
* @return true if the number format was removed
*/
+ @Override
public boolean removeNumberFormat(String fmt) {
short id = getNumberFormatId(fmt);
return removeNumberFormat(id);
}
+ @Override
public XSSFFont getFontAt(int idx) {
return fonts.get(idx);
}
@@ -385,6 +391,7 @@ public class StylesTable extends POIXMLD
* Note - End Users probably want to call
* {@link XSSFFont#registerTo(StylesTable)}
*/
+ @Override
public int putFont(XSSFFont font, boolean forceRegistration) {
int idx = -1;
if(!forceRegistration) {
@@ -399,6 +406,8 @@ public class StylesTable extends POIXMLD
fonts.add(font);
return idx;
}
+
+ @Override
public int putFont(XSSFFont font) {
return putFont(font, false);
}
@@ -408,6 +417,7 @@ public class StylesTable extends POIXMLD
* @param idx style index
* @return XSSFCellStyle or null if idx is out of bounds for xfs array
*/
+ @Override
public XSSFCellStyle getStyleAt(int idx) {
int styleXfId = 0;
@@ -422,6 +432,8 @@ public class StylesTable extends POIXMLD
return new XSSFCellStyle(idx, styleXfId, this, theme);
}
+
+ @Override
public int putStyle(XSSFCellStyle style) {
CTXf mainXF = style.getCoreXf();
@@ -431,6 +443,7 @@ public class StylesTable extends POIXMLD
return xfs.indexOf(mainXF);
}
+ @Override
public XSSFCellBorder getBorderAt(int idx) {
return borders.get(idx);
}
@@ -442,6 +455,7 @@ public class StylesTable extends POIXMLD
* @param border border to add
* @return the index of the added border
*/
+ @Override
public int putBorder(XSSFCellBorder border) {
int idx = borders.indexOf(border);
if (idx != -1) {
@@ -452,6 +466,7 @@ public class StylesTable extends POIXMLD
return borders.size() - 1;
}
+ @Override
public XSSFCellFill getFillAt(int idx) {
return fills.get(idx);
}
@@ -479,6 +494,7 @@ public class StylesTable extends POIXMLD
* @param fill fill to add
* @return the index of the added fill
*/
+ @Override
public int putFill(XSSFCellFill fill) {
int idx = fills.indexOf(fill);
if (idx != -1) {
@@ -543,7 +559,8 @@ public class StylesTable extends POIXMLD
/**
* get the size of cell styles
*/
- public int getNumCellStyles(){
+ @Override
+ public int getNumCellStyles() {
// Each cell style has a unique xfs entry
// Several might share the same styleXfs entry
return xfs.size();
@@ -552,6 +569,7 @@ public class StylesTable extends POIXMLD
/**
* @return number of data formats in the styles table
*/
+ @Override
public int getNumDataFormats() {
return numberFormats.size();
}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Themes.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Themes.java?rev=1836732&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Themes.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Themes.java Thu Jul 26
14:18:13 2018
@@ -0,0 +1,19 @@
+package org.apache.poi.xssf.model;
+
+import org.apache.poi.xssf.usermodel.XSSFColor;
+
+public interface Themes {
+ /**
+ * Convert a theme "index" (as used by fonts etc) into a color.
+ * @param idx A theme "index"
+ * @return The mapped XSSFColor, or null if not mapped.
+ */
+ XSSFColor getThemeColor(int idx);
+
+ /**
+ * If the colour is based on a theme, then inherit
+ * information (currently just colours) from it as
+ * required.
+ */
+ void inheritFromThemeAsRequired(XSSFColor color);
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/Themes.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java?rev=1836732&r1=1836731&r2=1836732&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/ThemesTable.java Thu Jul
26 14:18:13 2018
@@ -34,7 +34,7 @@ import org.openxmlformats.schemas.drawin
* Class that represents theme of XLSX document. The theme includes specific
* colors and fonts.
*/
-public class ThemesTable extends POIXMLDocumentPart {
+public class ThemesTable extends POIXMLDocumentPart implements Themes {
public enum ThemeElement {
LT1(0, "Lt1"),
DK1(1,"Dk1"),
@@ -110,6 +110,7 @@ public class ThemesTable extends POIXMLD
* @param idx A theme "index"
* @return The mapped XSSFColor, or null if not mapped.
*/
+ @Override
public XSSFColor getThemeColor(int idx) {
// Theme color references are NOT positional indices into the color
scheme,
// i.e. these keys are NOT the same as the order in which theme colors
appear
@@ -150,6 +151,7 @@ public class ThemesTable extends POIXMLD
* information (currently just colours) from it as
* required.
*/
+ @Override
public void inheritFromThemeAsRequired(XSSFColor color) {
if(color == null) {
// Nothing for us to do
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]