Must admit that I had to think about this one a bit - not something I enjoy 
doing late on a Monday afternoon.

Having done so, and I must emphasise that I am not be at all critical but am 
interested, I must ask why you would want a copy constructor? Typically, a Java 
class will over-ride the clone() method to provide this sort of functionality. 
Many will argue against implementing this method I know, but it is the usual 
way to to provide for a deep copy of an object.

"A. Rick Anderson" <[EMAIL PROTECTED]> wrote: Since there doesn't appear to be 
a HSSFCell copy constructor, I am 
attempting to create one, as shown below.

It seems to be working reasonably well, except that it is not copying 
the old CellStyle or Cell Format.  Consequently, when I try to print out 
the new cell, I am getting an exception because it says there is no 
format defined for the new cell.

BTW: Is there a particular reason that there isn't a public copy 
constructor for cells, sheets etc.

public void copyCell(HSSFCell newCell, HSSFCell oldCell) {
         newCell.setCellNum(oldCell.getCellNum());
         newCell.setCellStyle(oldCell.getCellStyle());
         newCell.setCellType(oldCell.getCellType());
         switch (oldCell.getCellType()) {
         case HSSFCell.CELL_TYPE_BLANK:
             break;
         case HSSFCell.CELL_TYPE_BOOLEAN:
             newCell.setCellValue(oldCell.getBooleanCellValue());
             break;
         case HSSFCell.CELL_TYPE_ERROR:
             newCell.setCellErrorValue(oldCell.getErrorCellValue());
             break;
         case HSSFCell.CELL_TYPE_FORMULA:
             newCell.setCellFormula(oldCell.getCellFormula());
             break;
         case HSSFCell.CELL_TYPE_NUMERIC:
             if (HSSFDateUtil.isCellDateFormatted(oldCell)) {
                 newCell.setCellValue(oldCell.getDateCellValue());
             } else {
                 newCell.setCellValue(oldCell.getNumericCellValue());
             }
             break;
         case HSSFCell.CELL_TYPE_STRING:
             newCell.setCellValue(oldCell.getRichStringCellValue());
             break;
         default:
             System.err.println("Unknown Cell Type: " +
                                 oldCell.getCellType());
         } // switch
     } // method copyCell

-- 
A. Rick Anderson


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/



 
---------------------------------
Everyone is raving about the all-new Yahoo! Mail beta.

Reply via email to