001package com.hfg.xml.msoffice2003.spreadsheetml;
002
003import com.hfg.util.collection.CollectionUtil;
004import com.hfg.xml.XMLNode;
005import com.hfg.xml.XMLTag;
006
007import java.util.List;
008
009
010
011//------------------------------------------------------------------------------
012/**
013 Excel table.
014
015 @author J. Alex Taylor, hairyfatguy.com
016 */
017//------------------------------------------------------------------------------
018// com.hfg Library
019//
020// This library is free software; you can redistribute it and/or
021// modify it under the terms of the GNU Lesser General Public
022// License as published by the Free Software Foundation; either
023// version 2.1 of the License, or (at your option) any later version.
024//
025// This library is distributed in the hope that it will be useful,
026// but WITHOUT ANY WARRANTY; without even the implied warranty of
027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
028// Lesser General Public License for more details.
029//
030// You should have received a copy of the GNU Lesser General Public
031// License along with this library; if not, write to the Free Software
032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
033//
034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
035// jataylor@hairyfatguy.com
036//------------------------------------------------------------------------------
037
038public class ExcelTable extends XMLTag
039{
040
041   //---------------------------------------------------------------------------
042   public ExcelTable()
043   {
044      super(SpreadsheetML.TABLE);
045   }
046
047   //---------------------------------------------------------------------------
048   /**
049    Adds a new column definition. All Column elements for a spreadsheet must follow
050    the Table element and precede the first Row element.
051    */
052   public ExcelColumn addColumn()
053   {
054      ExcelColumn col = new ExcelColumn();
055
056      int insertIndex = 0;
057      List<XMLNode> columnNodes = getSubtagsByName(SpreadsheetML.COLUMN.getLocalName());
058      if (CollectionUtil.hasValues(columnNodes))
059      {
060         insertIndex = indexOf(columnNodes.get(columnNodes.size() - 1)) + 1;
061      }
062
063      addSubtag(insertIndex, col);
064
065      return col;
066   }
067
068   //---------------------------------------------------------------------------
069   public ExcelRow addRow()
070   {
071      ExcelRow row = new ExcelRow();
072      addSubtag(row);
073
074      return row;
075   }
076
077
078   //---------------------------------------------------------------------------
079   public ExcelTable setExpandedColumnCount(int inValue)
080   {
081      setAttribute(SpreadsheetML.EXPANEDED_COLUMN_COUNT_ATT, inValue);
082      return this;
083   }
084
085}