Results 1 to 3 of 3
  1. #1
    laredotornado is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default How to copy cell styles in an XSSFWorkbook?

    Hi,

    I'm using

    Java Code:
    <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.5-beta5</version>
    </dependency>
    and trying to copy information from in a worksheet from one XLSX workbook to a new worksheet in a different workbook. I am trying this ...

    Java Code:
    						final Cell newCell = newRow.createCell(colNum);
    						newCell.setCellValue(oldCellValue);
    						final CellStyle newCellStyle = newWorkbook.createCellStyle();
    						newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
    						newCell.setCellStyle(newCellStyle);
    However, the code is dying with

    Java Code:
    java.lang.StackOverflowError
    	at org.apache.poi.xssf.usermodel.XSSFCellStyle.cloneStyleFrom(XSSFCellStyle.java:113)
    	at org.apache.poi.xssf.usermodel.XSSFCellStyle.cloneStyleFrom(XSSFCellStyle.java:114)
    	...
    What is the correct way to copy a cell style from a cell in one workbook to a different cell in a new workbook? Thanks, - Dave

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: How to copy cell styles in an XSSFWorkbook?

    It's a bug, which is not unheard of in a Beta.
    This is the code for that method:
    Java Code:
        public void cloneStyleFrom(CellStyle source) {
            if(source instanceof XSSFCellStyle) {
                this.cloneStyleFrom(source);
            }
            throw new IllegalArgumentException("Can only clone from one XSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
        }
    Go up to Beta6 which has this working properly.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    laredotornado is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to copy cell styles in an XSSFWorkbook?

    Thanks, upgrading solved it.

Similar Threads

  1. Dynamic Content and Styles problem...
    By ThisIsPathetic in forum New To Java
    Replies: 1
    Last Post: 03-20-2011, 07:24 PM
  2. JTextPane Styles Example
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:48 PM
  3. Java2D Line Styles
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:05 PM
  4. JOptionPane - message styles
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 09:20 AM
  5. Replies: 0
    Last Post: 08-02-2007, 12:31 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •