1 2 17 18 19 package org.apache.poi.hssf.usermodel.contrib; 20 21 import org.apache.poi.hssf.usermodel.HSSFCell; 22 import org.apache.poi.hssf.usermodel.HSSFRow; 23 import org.apache.poi.hssf.usermodel.HSSFSheet; 24 import org.apache.poi.hssf.usermodel.HSSFWorkbook; 25 26 import org.apache.poi.hssf.util.Region; 27 28 import org.apache.commons.lang.exception.NestableException; 29 30 36 37 public class HSSFRegionUtil 38 { 39 40 41 private HSSFRegionUtil() { } 42 43 53 public static void setBorderLeft( short border, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 54 throws NestableException { 55 int rowStart = region.getRowFrom(); 56 int rowEnd = region.getRowTo(); 57 int column = region.getColumnFrom(); 58 59 for ( int i = rowStart; i <= rowEnd; i++ ) { 60 HSSFRow row = HSSFCellUtil.getRow( i, sheet ); 61 HSSFCell cell = HSSFCellUtil.getCell( row, column ); 62 HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderLeft", new Short ( border ) ); 63 } 64 } 65 66 76 public static void setLeftBorderColor( short color, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 77 throws NestableException { 78 int rowStart = region.getRowFrom(); 79 int rowEnd = region.getRowTo(); 80 int column = region.getColumnFrom(); 81 82 for ( int i = rowStart; i <= rowEnd; i++ ) { 83 HSSFRow row = HSSFCellUtil.getRow( i, sheet ); 84 HSSFCell cell = HSSFCellUtil.getCell( row, column ); 85 HSSFCellUtil.setCellStyleProperty( cell, workbook, "leftBorderColor", new Short ( color ) ); 86 } 87 } 88 89 98 public static void setBorderRight( short border, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 99 throws NestableException { 100 int rowStart = region.getRowFrom(); 101 int rowEnd = region.getRowTo(); 102 int column = region.getColumnTo(); 103 104 for ( int i = rowStart; i <= rowEnd; i++ ) { 105 HSSFRow row = HSSFCellUtil.getRow( i, sheet ); 106 HSSFCell cell = HSSFCellUtil.getCell( row, column ); 107 108 HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderRight", new Short ( border ) ); 109 } 110 } 111 112 122 public static void setRightBorderColor( short color, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 123 throws NestableException { 124 int rowStart = region.getRowFrom(); 125 int rowEnd = region.getRowTo(); 126 int column = region.getColumnTo(); 127 128 for ( int i = rowStart; i <= rowEnd; i++ ) { 129 HSSFRow row = HSSFCellUtil.getRow( i, sheet ); 130 HSSFCell cell = HSSFCellUtil.getCell( row, column ); 131 HSSFCellUtil.setCellStyleProperty( cell, workbook, "rightBorderColor", new Short ( color ) ); 132 } 133 } 134 135 144 public static void setBorderBottom( short border, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 145 throws NestableException { 146 int colStart = region.getColumnFrom(); 147 int colEnd = region.getColumnTo(); 148 int rowIndex = region.getRowTo(); 149 HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet ); 150 for ( int i = colStart; i <= colEnd; i++ ) { 151 152 HSSFCell cell = HSSFCellUtil.getCell( row, i ); 153 HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderBottom", new Short ( border ) ); 154 } 155 } 156 157 167 public static void setBottomBorderColor( short color, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 168 throws NestableException { 169 int colStart = region.getColumnFrom(); 170 int colEnd = region.getColumnTo(); 171 int rowIndex = region.getRowTo(); 172 HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet ); 173 for ( int i = colStart; i <= colEnd; i++ ) { 174 HSSFCell cell = HSSFCellUtil.getCell( row, i ); 175 HSSFCellUtil.setCellStyleProperty( cell, workbook, "bottomBorderColor", new Short ( color ) ); 176 } 177 } 178 179 180 189 public static void setBorderTop( short border, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 190 throws NestableException { 191 int colStart = region.getColumnFrom(); 192 int colEnd = region.getColumnTo(); 193 int rowIndex = region.getRowFrom(); 194 HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet ); 195 for ( int i = colStart; i <= colEnd; i++ ) { 196 197 HSSFCell cell = HSSFCellUtil.getCell( row, i ); 198 HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderTop", new Short ( border ) ); 199 } 200 } 201 202 212 public static void setTopBorderColor( short color, Region region, HSSFSheet sheet, HSSFWorkbook workbook ) 213 throws NestableException { 214 int colStart = region.getColumnFrom(); 215 int colEnd = region.getColumnTo(); 216 int rowIndex = region.getRowFrom(); 217 HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet ); 218 for ( int i = colStart; i <= colEnd; i++ ) { 219 HSSFCell cell = HSSFCellUtil.getCell( row, i ); 220 HSSFCellUtil.setCellStyleProperty( cell, workbook, "topBorderColor", new Short ( color ) ); 221 222 } 223 } 224 225 } 226 227 | Popular Tags |