001: package com.xoetrope.export.xl;
002:
003: import com.xoetrope.export.Block;
004: import com.xoetrope.export.RowBlock;
005: import com.xoetrope.export.TableBlock;
006: import java.util.Hashtable;
007: import jxl.write.Label;
008: import jxl.write.WritableSheet;
009: import jxl.write.WriteException;
010:
011: /**
012: *
013: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
014: * the GNU Public License (GPL), please see license.txt for more details. If
015: * you make commercial use of this software you must purchase a commercial
016: * license from Xoetrope.</p>
017: * <p> $Revision: 1.2 $</p>
018: */
019: public class XLTableBlock extends TableBlock {
020:
021: WritableSheet sheet;
022: Hashtable spanCells;
023: XLExporter xlExporter;
024:
025: public XLTableBlock(XLExporter exporter) {
026: xlExporter = exporter;
027: }
028:
029: public RowBlock addRow() {
030: XLRowBlockItem rowItem = new XLRowBlockItem(xlExporter);
031: xlExporter.addRow();
032: blocks.add(rowItem);
033: xlExporter.setColumn(-1);
034: return rowItem;
035: }
036:
037: public void setWorksheet(WritableSheet worksheet) {
038: sheet = worksheet;
039: spanCells = new Hashtable();
040: }
041:
042: /*public Block startTableRow()
043: {
044: return null;
045: }
046:
047: public Block endTableRow()
048: {
049: xlExporter.addRow();
050: xlExporter.setColumn( 0 );
051: return null;
052: }
053:
054: public Block writeTableCell( String cellContents )
055: {
056: skipSpanCells();
057: setCell( cellContents );
058: xlExporter.addColumn();
059: return null;
060: }
061:
062: public Block writeTableCell( String cellContents, int colSpan, int rowSpan )
063: {
064: skipSpanCells();
065: setCell( cellContents );
066: if ( rowSpan > 1 ) {
067: for ( int i = 1; i < rowSpan; i++ ) {
068: String key = xlExporter.getColumn() + "A:" + ( i + xlExporter.getRow() ) + "A";
069: spanCells.put( key, sheet.getCell( xlExporter.getColumn(), i + xlExporter.getRow() ) );
070: }
071: }
072: xlExporter.addColumn( colSpan );
073: return null;
074: }
075: **/
076:
077: /*
078: private void skipSpanCells()
079: {
080: boolean span = true;
081: while ( span ) {
082: String key = xlExporter.getColumn() + "A:" + xlExporter.getRow() + "A";
083: if ( spanCells.get( key ) != null )
084: xlExporter.addColumn();
085: else
086: span = false;
087: }
088: }
089:
090: private void setCell( String contents )
091: {
092: Label lbl = new Label( xlExporter.getColumn(), xlExporter.getRow(), contents );
093: try {
094: sheet.addCell( lbl );
095: } catch ( WriteException ex ) {
096: ex.printStackTrace();
097: }
098: }
099: */
100:
101: }
|