1 16 17 package org.apache.poi.hssf.usermodel; 18 19 import org.apache.poi.hssf.record.HeaderRecord; 20 21 34 public class HSSFHeader 35 { 36 37 HeaderRecord headerRecord; 38 String left; 39 String center; 40 String right; 41 42 47 protected HSSFHeader( HeaderRecord headerRecord ) 48 { 49 this.headerRecord = headerRecord; 50 String head = headerRecord.getHeader(); 51 while ( head != null && head.length() > 1 ) 52 { 53 int pos = head.length(); 54 switch ( head.substring( 1, 2 ).charAt( 0 ) ) 55 { 56 case 'L': 57 if ( head.indexOf( "&C" ) >= 0 ) 58 { 59 pos = Math.min( pos, head.indexOf( "&C" ) ); 60 } 61 if ( head.indexOf( "&R" ) >= 0 ) 62 { 63 pos = Math.min( pos, head.indexOf( "&R" ) ); 64 } 65 left = head.substring( 2, pos ); 66 head = head.substring( pos ); 67 break; 68 case 'C': 69 if ( head.indexOf( "&L" ) >= 0 ) 70 { 71 pos = Math.min( pos, head.indexOf( "&L" ) ); 72 } 73 if ( head.indexOf( "&R" ) >= 0 ) 74 { 75 pos = Math.min( pos, head.indexOf( "&R" ) ); 76 } 77 center = head.substring( 2, pos ); 78 head = head.substring( pos ); 79 break; 80 case 'R': 81 if ( head.indexOf( "&C" ) >= 0 ) 82 { 83 pos = Math.min( pos, head.indexOf( "&C" ) ); 84 } 85 if ( head.indexOf( "&L" ) >= 0 ) 86 { 87 pos = Math.min( pos, head.indexOf( "&L" ) ); 88 } 89 right = head.substring( 2, pos ); 90 head = head.substring( pos ); 91 break; 92 default : 93 head = null; 94 } 95 } 96 } 97 98 103 public String getLeft() 104 { 105 return left; 106 } 107 108 113 public void setLeft( String newLeft ) 114 { 115 left = newLeft; 116 createHeaderString(); 117 } 118 119 124 public String getCenter() 125 { 126 return center; 127 } 128 129 134 public void setCenter( String newCenter ) 135 { 136 center = newCenter; 137 createHeaderString(); 138 } 139 140 145 public String getRight() 146 { 147 return right; 148 } 149 150 155 public void setRight( String newRight ) 156 { 157 right = newRight; 158 createHeaderString(); 159 } 160 161 165 private void createHeaderString() 166 { 167 headerRecord.setHeader( "&C" + ( center == null ? "" : center ) + 168 "&L" + ( left == null ? "" : left ) + 169 "&R" + ( right == null ? "" : right ) ); 170 headerRecord.setHeaderLength( (byte) headerRecord.getHeader().length() ); 171 } 172 173 179 public static String fontSize( short size ) 180 { 181 return "&" + size; 182 } 183 184 191 public static String font( String font, String style ) 192 { 193 return "&\"" + font + "," + style + "\""; 194 } 195 196 201 public static String page() 202 { 203 return "&P"; 204 } 205 206 211 public static String numPages() 212 { 213 return "&N"; 214 } 215 216 221 public static String date() 222 { 223 return "&D"; 224 } 225 226 231 public static String time() 232 { 233 return "&T"; 234 } 235 236 241 public static String file() 242 { 243 return "&F"; 244 } 245 246 251 public static String tab() 252 { 253 return "&A"; 254 } 255 } 256 257 | Popular Tags |