ASF Bugzilla – Attachment 34867 Details for
Bug 60902
.cloneCellStyle as a Workbook method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
version 1, adds a new cloneCellStyle method to the workbook
XSSFWorkbook_cloneCellStyle_v1.patch (text/plain), 4.67 KB, created by
dollinger.florian
on 2017-03-22 14:16:20 UTC
(
hide
)
Description:
version 1, adds a new cloneCellStyle method to the workbook
Filename:
MIME Type:
Creator:
dollinger.florian
Created:
2017-03-22 14:16:20 UTC
Size:
4.67 KB
patch
obsolete
>diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java >index fecad97..237406f 100644 >--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java >+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java >@@ -37,6 +37,7 @@ > import java.util.Locale; > import java.util.Map; > import java.util.NoSuchElementException; >+import java.util.Objects; > import java.util.regex.Pattern; > > import javax.xml.namespace.QName; >@@ -90,6 +91,7 @@ > import org.apache.poi.xssf.model.SharedStringsTable; > import org.apache.poi.xssf.model.StylesTable; > import org.apache.poi.xssf.model.ThemesTable; >+import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide; > import org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils; > import org.apache.xmlbeans.XmlException; > import org.apache.xmlbeans.XmlObject; >@@ -659,6 +661,65 @@ > } > return clonedSheet; > } >+ >+ /** >+ * Searches in the current Workbook for an equivalent CellStyle to the given one (from another Workbook). >+ * If none exists, it will be created. >+ * >+ * @param src The CellStyle that is going to be cloned >+ * @return CellStyle The created or looked up CellStyle in the current Workbook >+ */ >+ public XSSFCellStyle cloneCellStyle(XSSFCellStyle src) { >+ >+ XSSFCellStyle returnStyle = null; >+ >+ // Search for an existing Style that fits the source >+ // Caution: Even if the Style is the same, the underlying borders, fills, ... may differ! >+ >+ for(int i = 0; i < this.getNumCellStyles(); i++){ >+ XSSFCellStyle currCellStyle = this.getCellStyleAt(i); >+ >+ if(Objects.equals(currCellStyle.getHidden(), src.getHidden()) >+ && Objects.equals(currCellStyle.getAlignmentEnum(), src.getAlignmentEnum()) >+ && Objects.equals(currCellStyle.getBorderBottomEnum(), src.getBorderBottomEnum()) >+ && Objects.equals(currCellStyle.getRotation(), src.getRotation()) >+ && Objects.equals(currCellStyle.getFillPatternEnum(), src.getFillPatternEnum()) >+ && Objects.equals(currCellStyle.getFillBackgroundXSSFColor(), src.getFillBackgroundXSSFColor()) >+ && Objects.equals(currCellStyle.getFillForegroundXSSFColor(), src.getFillForegroundXSSFColor()) >+ && Objects.equals(currCellStyle.getFont(), src.getFont()) >+ && Objects.equals(currCellStyle.getBorderTopEnum(), src.getBorderTopEnum()) >+ && Objects.equals(currCellStyle.getTopBorderXSSFColor(), src.getTopBorderXSSFColor()) >+ && Objects.equals(currCellStyle.getBorderRightEnum(), src.getBorderRightEnum()) >+ && Objects.equals(currCellStyle.getRightBorderXSSFColor(), src.getRightBorderXSSFColor()) >+ && Objects.equals(currCellStyle.getBorderBottomEnum(), src.getBorderBottomEnum()) >+ && Objects.equals(currCellStyle.getBottomBorderXSSFColor(), src.getBottomBorderXSSFColor()) >+ && Objects.equals(currCellStyle.getBorderLeftEnum(), src.getBorderLeftEnum()) >+ && Objects.equals(currCellStyle.getLeftBorderXSSFColor(), src.getLeftBorderXSSFColor()) >+ && Objects.equals(currCellStyle.getDataFormat(), src.getDataFormat()) >+ && Objects.equals(currCellStyle.getIndention(), src.getIndention()) >+ && Objects.equals(currCellStyle.getLocked(), src.getLocked()) >+ && Objects.equals(currCellStyle.getQuotePrefixed(), src.getQuotePrefixed()) >+ && Objects.equals(currCellStyle.getShrinkToFit(), src.getShrinkToFit()) >+ && Objects.equals(currCellStyle.getVerticalAlignmentEnum(), src.getVerticalAlignmentEnum()) >+ && Objects.equals(currCellStyle.getWrapText(), src.getWrapText()) >+ && Objects.equals(currCellStyle.getFont(), src.getFont()) >+ // TODO: Not a good method to compare... Any Ideas? >+ // Idea: Let the CellStyle decide itself it it equals another one (don't use .equals(), maybe .deepEquals()) >+ ){ >+ returnStyle = currCellStyle; >+ } >+ >+ } >+ >+ if(returnStyle == null){ >+ // If none exists: Create one (use XSSFCellStyles cloneStyle) >+ returnStyle = this.createCellStyle(); >+ returnStyle.cloneStyleFrom(src); >+ } >+ >+ return returnStyle; >+ } >+ > > /** > * @since 3.14-Beta1 >@@ -2470,4 +2531,6 @@ > > return oleId; > } >+ >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 60902
:
34867
|
34869