1 12 13 package org.displaytag.sample.decorators; 14 15 import org.apache.poi.hssf.usermodel.HSSFCell; 16 import org.apache.poi.hssf.usermodel.HSSFRow; 17 import org.apache.poi.hssf.usermodel.HSSFSheet; 18 import org.displaytag.decorator.hssf.DecoratesHssf; 19 20 21 27 public class HssfTotalWrapper extends TotalWrapperTemplate implements DecoratesHssf 28 { 29 30 private HSSFSheet sheet; 31 32 private HSSFCell currentCell; 33 34 private HSSFRow currentRow; 35 36 private int colNum; 37 38 protected void writeCityTotal(String city, double total) 39 { 40 this.writeTotal(city, total); 41 } 42 43 private void writeTotal(String value, double total) 44 { 45 if (this.assertRequiredState()) 46 { 47 int rowNum = this.sheet.getLastRowNum(); 48 this.currentRow = this.sheet.createRow(++rowNum); 49 this.colNum = 0; 50 prepareCell(); 51 prepareCell(); 52 prepareCell(); 53 this.currentCell.setCellValue("------------"); 54 55 this.currentRow = this.sheet.createRow(++rowNum); 56 this.colNum = 0; 57 prepareCell(); 58 prepareCell(); 59 this.currentCell.setCellValue(value + " Total:"); 60 prepareCell(); 61 this.currentCell.setCellValue(total); 62 } 63 } 64 65 private void prepareCell() 66 { 67 this.currentCell = this.currentRow.createCell((short) this.colNum++); 68 this.currentCell.setEncoding(HSSFCell.ENCODING_UTF_16); 69 } 70 71 protected void writeGrandTotal(double total) 72 { 73 this.writeTotal("Grand", total); 74 } 75 76 public void setSheet(HSSFSheet sheet) 77 { 78 this.sheet = sheet; 79 } 80 81 85 private boolean assertRequiredState() 86 { 87 return this.sheet != null; 88 } 89 } 90 | Popular Tags |