| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package xin.glue.ui.common.blob;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.List;
- import com.posdata.glue.dao.vo.PosRowSet;
- import jxl.Cell;
- 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 abstract class PosExcelEngine implements PosExcelInterface {
- protected List dataList = new ArrayList();
- protected int dataRow = 0;
- protected int addRows = 0;
- protected int pageSize = 25;
- protected int pageCount = 0;
- protected boolean autoBlank = true;
- public void setData(List dataList, InputStream is, OutputStream os, int dataRow, int pageSize) {
- for (int i = 0; i < dataList.size(); i++) {
- ArrayList list = new ArrayList();
- PosRowSet rowSet = (PosRowSet)dataList.get(i);
- while (rowSet.hasNext())
- list.add(rowSet.next().getAttributes());
- this.dataList.add(list);
- }
- this.dataRow = dataRow;
- this.pageSize = pageSize;
- try {
- Workbook rwb = Workbook.getWorkbook(is);
- WritableWorkbook wb = Workbook.createWorkbook(os, rwb);
- setData(rwb, wb);
- wb.write();
- wb.close();
- rwb.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- protected abstract void setData(Workbook rwb, WritableWorkbook wb) throws RowsExceededException, WriteException;
- protected int insertRow(WritableSheet sheet, int curRow, Sheet rs, int refRow) throws WriteException {
- sheet.insertRow(++curRow); // Ìí¼ÓÐÐ
- sheet.setRowView(curRow, rs.getRowView(refRow).getSize());
- Cell cell;
- Label label;
- Cell[] cells = rs.getRow(refRow);
- for (int curCol = 0, count = cells.length; curCol < count; curCol++) {
- cell = cells[curCol];
- label = new Label(curCol, curRow, "", cell.getCellFormat());
- sheet.addCell(label);
- }
- this.addRows++;
- return curRow;
- }
-
- protected void setValue(WritableSheet sheet, int curRow, int curCol, Object value) {
- if (value != null && !value.equals("")) {
- Label label;
- label = (Label)sheet.getWritableCell(curCol, curRow);
- String val = label.getContents();
- if (val.equals("")) val = value.toString();
- else val += '\n' + value.toString(); // '\012' Ç¿ÖÆ»»ÐÐ
- label.setString(val);
- }
- }
- protected void addBlankRow(WritableSheet sheet, int curRow, Sheet rs, int refRow, int rows) throws WriteException {
- if (autoBlank) {
- while (rows < pageSize) {
- curRow = insertRow(sheet, curRow, rs, refRow);
- }
- }
- }
- }
|