View | Details | Raw Unified | Return to bug 60902
Collapse All | Expand All

(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (+63 lines)
Lines 37-42 Link Here
37
import java.util.Locale;
37
import java.util.Locale;
38
import java.util.Map;
38
import java.util.Map;
39
import java.util.NoSuchElementException;
39
import java.util.NoSuchElementException;
40
import java.util.Objects;
40
import java.util.regex.Pattern;
41
import java.util.regex.Pattern;
41
42
42
import javax.xml.namespace.QName;
43
import javax.xml.namespace.QName;
Lines 90-95 Link Here
90
import org.apache.poi.xssf.model.SharedStringsTable;
91
import org.apache.poi.xssf.model.SharedStringsTable;
91
import org.apache.poi.xssf.model.StylesTable;
92
import org.apache.poi.xssf.model.StylesTable;
92
import org.apache.poi.xssf.model.ThemesTable;
93
import org.apache.poi.xssf.model.ThemesTable;
94
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
93
import org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils;
95
import org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils;
94
import org.apache.xmlbeans.XmlException;
96
import org.apache.xmlbeans.XmlException;
95
import org.apache.xmlbeans.XmlObject;
97
import org.apache.xmlbeans.XmlObject;
Lines 659-664 Link Here
659
        }
661
        }
660
        return clonedSheet;
662
        return clonedSheet;
661
    }
663
    }
664
    
665
    /**
666
     * Searches in the current Workbook for an equivalent CellStyle to the given one (from another Workbook).
667
     * If none exists, it will be created.
668
     *
669
     * @param src The CellStyle that is going to be cloned
670
     * @return CellStyle The created or looked up CellStyle in the current Workbook
671
     */
672
    public XSSFCellStyle cloneCellStyle(XSSFCellStyle src) {
673
        
674
        XSSFCellStyle returnStyle = null;
675
        
676
        // Search for an existing Style that fits the source
677
        // Caution: Even if the Style is the same, the underlying borders, fills, ... may differ!
678
        
679
        for(int i = 0; i < this.getNumCellStyles(); i++){
680
            XSSFCellStyle currCellStyle = this.getCellStyleAt(i);
681
            
682
            if(Objects.equals(currCellStyle.getHidden(), src.getHidden())
683
                    && Objects.equals(currCellStyle.getAlignmentEnum(), src.getAlignmentEnum())
684
                    && Objects.equals(currCellStyle.getBorderBottomEnum(), src.getBorderBottomEnum())
685
                    && Objects.equals(currCellStyle.getRotation(), src.getRotation())
686
                    && Objects.equals(currCellStyle.getFillPatternEnum(), src.getFillPatternEnum())
687
                    && Objects.equals(currCellStyle.getFillBackgroundXSSFColor(), src.getFillBackgroundXSSFColor())
688
                    && Objects.equals(currCellStyle.getFillForegroundXSSFColor(), src.getFillForegroundXSSFColor())
689
                    && Objects.equals(currCellStyle.getFont(), src.getFont())
690
                    && Objects.equals(currCellStyle.getBorderTopEnum(), src.getBorderTopEnum())
691
                    && Objects.equals(currCellStyle.getTopBorderXSSFColor(), src.getTopBorderXSSFColor())
692
                    && Objects.equals(currCellStyle.getBorderRightEnum(), src.getBorderRightEnum())
693
                    && Objects.equals(currCellStyle.getRightBorderXSSFColor(), src.getRightBorderXSSFColor())
694
                    && Objects.equals(currCellStyle.getBorderBottomEnum(), src.getBorderBottomEnum())
695
                    && Objects.equals(currCellStyle.getBottomBorderXSSFColor(), src.getBottomBorderXSSFColor())
696
                    && Objects.equals(currCellStyle.getBorderLeftEnum(), src.getBorderLeftEnum())
697
                    && Objects.equals(currCellStyle.getLeftBorderXSSFColor(), src.getLeftBorderXSSFColor())
698
                    && Objects.equals(currCellStyle.getDataFormat(), src.getDataFormat())
699
                    && Objects.equals(currCellStyle.getIndention(), src.getIndention())
700
                    && Objects.equals(currCellStyle.getLocked(), src.getLocked())
701
                    && Objects.equals(currCellStyle.getQuotePrefixed(), src.getQuotePrefixed())
702
                    && Objects.equals(currCellStyle.getShrinkToFit(), src.getShrinkToFit())
703
                    && Objects.equals(currCellStyle.getVerticalAlignmentEnum(), src.getVerticalAlignmentEnum())
704
                    && Objects.equals(currCellStyle.getWrapText(), src.getWrapText())
705
                    && Objects.equals(currCellStyle.getFont(), src.getFont())
706
                    // TODO: Not a good method to compare... Any Ideas?
707
                    //       Idea: Let the CellStyle decide itself it it equals another one (don't use .equals(), maybe .deepEquals())
708
                    ){
709
                returnStyle = currCellStyle;
710
            }
711
            
712
        }
713
            
714
        if(returnStyle == null){
715
            // If none exists: Create one (use XSSFCellStyles cloneStyle)
716
            returnStyle = this.createCellStyle();
717
            returnStyle.cloneStyleFrom(src);
718
        }
719
720
        return returnStyle;
721
    }
722
    
662
    
723
    
663
    /**
724
    /**
664
     * @since 3.14-Beta1
725
     * @since 3.14-Beta1
Lines 2470-2473 Link Here
2470
2531
2471
        return oleId;
2532
        return oleId;
2472
    }
2533
    }
2534
2535
2473
}
2536
}

Return to bug 60902