4f7218e9b0c69a58c3807eaa7590d11bb76e8d7a.svn-base 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package xin.glue.ui.common.blob;
  2. import java.util.List;
  3. import java.util.Map;
  4. import jxl.Cell;
  5. import jxl.CellType;
  6. import jxl.Sheet;
  7. import jxl.Workbook;
  8. import jxl.write.Label;
  9. import jxl.write.WritableSheet;
  10. import jxl.write.WritableWorkbook;
  11. import jxl.write.WriteException;
  12. import jxl.write.biff.RowsExceededException;
  13. public class PosExcelCommon extends PosExcelEngine {
  14. private int cols;
  15. protected void setData(Workbook rwb, WritableWorkbook wb) throws RowsExceededException, WriteException {
  16. Sheet rs = rwb.getSheet(0);
  17. cols = rs.getColumns();
  18. setData(wb, rs);
  19. }
  20. private void setData(WritableWorkbook wb, Sheet rs) throws WriteException, RowsExceededException {
  21. this.addRows = 0;
  22. if (pageCount > 0)
  23. wb.importSheet("sheet" + (pageCount + 1), pageCount, rs);
  24. WritableSheet sheet = wb.getSheet(pageCount++);
  25. sheet.removeRow(dataRow);
  26. int curRow = dataRow;
  27. if (dataList.size() > 0) {
  28. List list = (List)dataList.get(0);
  29. Cell cell;
  30. Label label;
  31. String fieldName;
  32. int count = 1;
  33. for (int i = 0; i < list.size(); ) {
  34. if (count > pageSize) break;
  35. curRow = insertRow(sheet, curRow, rs, dataRow);
  36. Map row = (Map)list.get(i);
  37. for (int curCol = 0; curCol < cols; curCol++) {
  38. cell = rs.getCell(curCol, curRow);
  39. if (cell.getType() == CellType.EMPTY) continue;
  40. fieldName = cell.getContents().trim();
  41. if (fieldName.equals("[_NO_]")) {
  42. setValue(sheet, curRow, 0, String.valueOf(count)); // NO.
  43. } else if (fieldName.startsWith("[") && fieldName.endsWith("]")) {
  44. fieldName = fieldName.substring(1, fieldName.length() - 1);
  45. label = (Label)sheet.getWritableCell(curCol, curRow);
  46. if (row.get(fieldName) != null) {
  47. label.setString(row.get(fieldName).toString());
  48. } else {
  49. label.setString(fieldName);
  50. }
  51. }
  52. }
  53. list.remove(i);
  54. count++;
  55. }
  56. if (list.size() > 0)
  57. setData(wb, rs);
  58. }
  59. }
  60. }