Bug 56981 - vertical alignment ignored after first cell in a row in XSSF
Summary: vertical alignment ignored after first cell in a row in XSSF
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on: 58224
Blocks:
  Show dependency tree
 
Reported: 2014-09-14 01:50 UTC by matt.england
Modified: 2015-09-20 12:36 UTC (History)
1 user (show)



Attachments
demo snippet (1021 bytes, text/plain)
2014-09-14 02:01 UTC, matt.england
Details
Result of running the code and opening the file in MS Excel (4.48 KB, image/png)
2015-04-30 14:18 UTC, Dominik Stadler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description matt.england 2014-09-14 01:50:18 UTC
Setting the vertical alignment of the style of the first cell in a row to CellStyle.VERTICAL_TOP, then subsequently attempting to set a later cell to CelLStyle.VERTICAL_BOTTOM results in both cells having TOP alignment (essentially, the second alignment is ignored). I've opened the result of executing the below demo snippet in both LibreOffice and OpenOffice (but not actual MS Excel, not sure if it would behave properly), and the problem appears in both, so I suspect it's a POI problem and not a bug common to both, though that is possible.

public class POITest {
  public static void main(String[] args) {
    //HSSFWorkbook exhibits correct behavior:
    Workbook workbook = new XSSFWorkbook(); 
    CellStyle vertTop = workbook.createCellStyle();
    vertTop.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    CellStyle vertBottom = workbook.createCellStyle();
    vertBottom.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    Sheet sheet = workbook.createSheet("Sheet 1");
    Row row = sheet.createRow(0);
    Cell top = row.createCell(0);
    Cell bottom = row.createCell(1);
    top.setCellValue("Top");
    top.setCellStyle(vertTop); //comment this out to get all bottom-aligned cells
    bottom.setCellValue("Bottom");
    bottom.setCellStyle(vertBottom);
    row.setHeightInPoints(85.75f); //make it obvious
    try {
      FileOutputStream out = new FileOutputStream("test.xlsx");
      workbook.write(out);
      out.flush();
      out.close();
    } catch (IOException e) {
      e.printStackTrace(System.err);
    }
  }
}
Comment 1 matt.england 2014-09-14 02:01:50 UTC
Created attachment 32019 [details]
demo snippet
Comment 2 Dominik Stadler 2015-04-30 14:18:12 UTC
Created attachment 32703 [details]
Result of running the code and opening the file in MS Excel
Comment 3 Dominik Stadler 2015-04-30 14:19:09 UTC
See the attached picture, it seems to work when opening the file with MS Excel, so I think this is rather a problem in LibreOffice/OpenOffice (which both share a common code-base so can easily have the same bug).