Bug 54894 - Cell gets corrupted after calling cloneStyleFrom and setBorderBottom
Summary: Cell gets corrupted after calling cloneStyleFrom and setBorderBottom
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 normal with 4 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-26 07:00 UTC by Asha K S
Modified: 2015-02-10 16:13 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Asha K S 2013-04-26 07:00:32 UTC
In the code below the cell gets corrupted when we call setCellStyle on it after calling cloneStyleFrom and setBorderBottom.In the generated file right click on the cell to which the style was applied to notice that the "Format cells " dialog doesnot come up.

  import org.apache.poi.hssf.usermodel.*;
  import org.apache.poi.ss.usermodel.*;

   import java.io.FileOutputStream;
   import java.io.IOException;

  /**
    * Demonstrates how to create borders around cells.
    *
   * @author Glen Stampoultzis (glens at apache.org)
    */
   public class Borders
  	  {
      public static void main(String[] args)
          throws IOException
  	      {
          HSSFWorkbook wb = new HSSFWorkbook();
          HSSFSheet sheet = wb.createSheet("new sheet");

          // Create a row and put some cells in it. Rows are 0 based.
          HSSFRow row = sheet.createRow((short) 1);

          // Create a cell and put a value in it.
          HSSFCell cell = row.createCell((short) 1);
          cell.setCellValue(4);

          CellStyle def = cell.getCellStyle();
          // Style the cell with borders all around.
          HSSFCellStyle style = wb.createCellStyle();
          style.cloneStyleFrom(def);
          style.setBorderBottom(HSSFCellStyle.BORDER_THIN);

          cell.setCellStyle(style);

          // Write the output to a file
          FileOutputStream fileOut = new FileOutputStream("workbook.xls");
          wb.write(fileOut);
          fileOut.close();
      }
  }
Comment 1 Dominik Stadler 2013-08-26 11:51:07 UTC
Still happens in current version of Excel, does not happen in OpenOffice, BiffViewer shows the following diff:

--- 
+++ 
@@ -1246,28 +1246,28 @@
     .alignmentoptions= 20
           .alignment = 0
           .wraptext  = false
           .valignment= 2
           .justlast  = 0
           .rotation  = 0
-    .indentionoptions= 0
+    .indentionoptions= 2000
           .indent    = 0
           .shrinktoft= false
           .mergecells= false
           .readngordr= 0
           .formatflag= false
           .fontflag  = false
           .prntalgnmt= false
-          .borderflag= false
+          .borderflag= true
           .paternflag= false
           .celloption= false
-    .borderoptns     = 0
+    .borderoptns     = 1000
           .lftln     = 0
           .rgtln     = 0
           .topln     = 0
-          .btmln     = 0
+          .btmln     = 1
     .paleteoptns     = 0
           .leftborder= 0
           .rghtborder= 0
           .diag      = 0
     .paleteoptn2     = 0
           .topborder = 0
@@ -1542,13 +1542,13 @@
 [/ROW]
 
 Offset=0x00000651(1617) recno=92 sid=0x0203 size=0x000E(14)
 [NUMBER]
     .row    = 0x0001
     .col    = 0x0001
-    .xfindex= 0x000F
+    .xfindex= 0x0015
   .value= 4
 [/NUMBER]
 
 Offset=0x00000663(1635) recno=93 sid=0x00D7 size=0x0006(6)
 [DBCELL]
     .rowoffset = 0x00000026
Comment 2 Dominik Stadler 2015-02-10 16:13:31 UTC
I could not reproduce this with latest POI-trunk and Excel in Office 365, so I assume it is either fixed in POI now or it was a bug in Excel itself which is fixed there in later versions of Excel.