package xin.glue.ui.common.blob; import java.util.List; import java.util.Map; import jxl.Cell; import jxl.CellType; import jxl.Sheet; import jxl.Workbook; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; import jxl.write.biff.RowsExceededException; public class PosExcelCommon extends PosExcelEngine { private int cols; protected void setData(Workbook rwb, WritableWorkbook wb) throws RowsExceededException, WriteException { Sheet rs = rwb.getSheet(0); cols = rs.getColumns(); setData(wb, rs); } private void setData(WritableWorkbook wb, Sheet rs) throws WriteException, RowsExceededException { this.addRows = 0; if (pageCount > 0) wb.importSheet("sheet" + (pageCount + 1), pageCount, rs); WritableSheet sheet = wb.getSheet(pageCount++); sheet.removeRow(dataRow); int curRow = dataRow; if (dataList.size() > 0) { List list = (List)dataList.get(0); Cell cell; Label label; String fieldName; int count = 1; for (int i = 0; i < list.size(); ) { if (count > pageSize) break; curRow = insertRow(sheet, curRow, rs, dataRow); Map row = (Map)list.get(i); for (int curCol = 0; curCol < cols; curCol++) { cell = rs.getCell(curCol, curRow); if (cell.getType() == CellType.EMPTY) continue; fieldName = cell.getContents().trim(); if (fieldName.equals("[_NO_]")) { setValue(sheet, curRow, 0, String.valueOf(count)); // NO. } else if (fieldName.startsWith("[") && fieldName.endsWith("]")) { fieldName = fieldName.substring(1, fieldName.length() - 1); label = (Label)sheet.getWritableCell(curCol, curRow); if (row.get(fieldName) != null) { label.setString(row.get(fieldName).toString()); } else { label.setString(fieldName); } } } list.remove(i); count++; } if (list.size() > 0) setData(wb, rs); } } }