1 16 17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.IOException ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import org.apache.poi.hssf.usermodel.HSSFCellStyle; 25 import org.apache.poi.hssf.usermodel.HSSFDataFormat; 26 import org.apache.poi.hssf.usermodel.HSSFFont; 27 import org.apache.poi.hssf.usermodel.HSSFSheet; 28 import org.apache.poi.hssf.usermodel.HSSFWorkbook; 29 import org.apache.poi.poifs.filesystem.POIFSFileSystem; 30 31 38 39 class Workbook { 41 private HSSFWorkbook _workbook; 42 private int _sheet_index; 43 private final static int REPEAT_CAPACITY = 91; 44 private Map _repeat; 45 46 49 Workbook() { 50 _workbook = new HSSFWorkbook(); 51 _sheet_index = 0; 52 _repeat = new HashMap (REPEAT_CAPACITY); 53 } 54 58 HSSFDataFormat createDataFormat() { 59 return _workbook.createDataFormat(); 60 } 61 62 67 Object getValidate(String format, short value) { 68 if (_repeat.containsKey(format) == false) { 69 _repeat.put(format, new Short (value)); 70 } 71 return _repeat.get(format); 72 } 73 74 78 String getNextName() { 79 return "Sheet" + _sheet_index++; 80 } 81 82 87 HSSFSheet createSheet(final String name) { 88 return _workbook.createSheet(name); 89 } 90 91 96 int getPhysicalIndex(final String name) { 97 return _workbook.getSheetIndex(name); 98 } 99 100 105 void renameSheet(final int index, final String name) { 106 _workbook.setSheetName(index, name, HSSFWorkbook.ENCODING_UTF_16); 107 } 108 109 114 HSSFCellStyle createStyle() { 115 HSSFCellStyle style = _workbook.createCellStyle(); 116 return style; 117 } 118 119 122 HSSFFont createFont() { 123 HSSFFont font = _workbook.createFont(); 124 return font; 125 } 126 127 HSSFWorkbook getWorkbook() { 128 return _workbook; 129 } 130 131 136 void write(final POIFSFileSystem filesystem) throws IOException { 137 filesystem.createDocument(new ByteArrayInputStream ( 138 _workbook.getBytes()), "Workbook"); 139 } 140 } | Popular Tags |