1 19 20 package jxl; 21 22 import java.io.FileInputStream ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 28 import jxl.read.biff.File; 29 import jxl.read.biff.WorkbookParser; 30 import jxl.read.biff.BiffException; 31 import jxl.read.biff.PasswordException; 32 import jxl.write.WritableWorkbook; 33 import jxl.write.biff.WritableWorkbookImpl; 34 35 39 public abstract class Workbook 40 { 41 44 private static final String version = "2.5.6"; 45 46 49 protected Workbook() 50 { 51 } 52 53 59 public abstract Sheet[] getSheets(); 60 61 66 public abstract String [] getSheetNames(); 67 68 81 public abstract Sheet getSheet(int index) 82 throws IndexOutOfBoundsException ; 83 84 95 public abstract Sheet getSheet(String name); 96 97 102 public static String getVersion() 103 { 104 return version; 105 } 106 107 112 public abstract int getNumberOfSheets(); 113 114 127 public abstract Cell findCellByName(String name); 128 129 143 public abstract Range[] findByName(String name); 144 145 150 public abstract String [] getRangeNames(); 151 152 153 158 public abstract boolean isProtected(); 159 160 168 protected abstract void parse() throws BiffException, PasswordException; 169 170 174 public abstract void close(); 175 176 184 public static Workbook getWorkbook(java.io.File file) 185 throws IOException , BiffException 186 { 187 return getWorkbook(file, new WorkbookSettings()); 188 } 189 190 199 public static Workbook getWorkbook(java.io.File file, WorkbookSettings ws) 200 throws IOException , BiffException 201 { 202 FileInputStream fis = new FileInputStream (file); 203 204 File dataFile = null; 207 208 try 209 { 210 dataFile = new File(fis, ws); 211 } 212 catch (IOException e) 213 { 214 fis.close(); 215 throw e; 216 } 217 catch (BiffException e) 218 { 219 fis.close(); 220 throw e; 221 } 222 223 fis.close(); 224 225 Workbook workbook = new WorkbookParser(dataFile, ws); 226 workbook.parse(); 227 228 return workbook; 229 } 230 231 239 public static Workbook getWorkbook(InputStream is) 240 throws IOException , BiffException 241 { 242 return getWorkbook(is, new WorkbookSettings()); 243 } 244 245 254 public static Workbook getWorkbook(InputStream is, WorkbookSettings ws) 255 throws IOException , BiffException 256 { 257 File dataFile = new File(is, ws); 258 259 Workbook workbook = new WorkbookParser(dataFile, ws); 260 workbook.parse(); 261 262 return workbook; 263 } 264 265 271 public static WritableWorkbook createWorkbook(java.io.File file) 272 throws IOException 273 { 274 return createWorkbook(file, new WorkbookSettings()); 275 } 276 277 284 public static WritableWorkbook createWorkbook(java.io.File file, 285 WorkbookSettings ws) 286 throws IOException 287 { 288 FileOutputStream fos = new FileOutputStream (file); 289 WritableWorkbook w = new WritableWorkbookImpl(fos, true, ws); 290 return w; 291 } 292 293 302 public static WritableWorkbook createWorkbook(java.io.File file, 303 Workbook in) 304 throws IOException 305 { 306 return createWorkbook(file, in, new WorkbookSettings()); 307 } 308 309 319 public static WritableWorkbook createWorkbook(java.io.File file, 320 Workbook in, 321 WorkbookSettings ws) 322 throws IOException 323 { 324 FileOutputStream fos = new FileOutputStream (file); 325 WritableWorkbook w = new WritableWorkbookImpl(fos, in, true, ws); 326 return w; 327 } 328 329 338 public static WritableWorkbook createWorkbook(OutputStream os, 339 Workbook in) 340 throws IOException 341 { 342 return createWorkbook(os, in, ((WorkbookParser) in).getSettings()); 343 } 344 345 355 public static WritableWorkbook createWorkbook(OutputStream os, 356 Workbook in, 357 WorkbookSettings ws) 358 throws IOException 359 { 360 WritableWorkbook w = new WritableWorkbookImpl(os, in, false, ws); 361 return w; 362 } 363 364 373 public static WritableWorkbook createWorkbook(OutputStream os) 374 throws IOException 375 { 376 return createWorkbook(os, new WorkbookSettings()); 377 } 378 379 389 public static WritableWorkbook createWorkbook(OutputStream os, 390 WorkbookSettings ws) 391 throws IOException 392 { 393 WritableWorkbook w = new WritableWorkbookImpl(os, false, ws); 394 return w; 395 } 396 } 397 398 399 400 401 402 | Popular Tags |