001package com.hfg.xml.msoffice2003.spreadsheetml;
002
003import com.hfg.xml.XMLTag;
004
005
006//------------------------------------------------------------------------------
007/**
008 Cell tag for use with Microsoft's Office 2003 SpreadsheetML.
009
010 @author J. Alex Taylor, hairyfatguy.com
011 */
012//------------------------------------------------------------------------------
013// com.hfg Library
014//
015// This library is free software; you can redistribute it and/or
016// modify it under the terms of the GNU Lesser General Public
017// License as published by the Free Software Foundation; either
018// version 2.1 of the License, or (at your option) any later version.
019//
020// This library is distributed in the hope that it will be useful,
021// but WITHOUT ANY WARRANTY; without even the implied warranty of
022// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
023// Lesser General Public License for more details.
024//
025// You should have received a copy of the GNU Lesser General Public
026// License along with this library; if not, write to the Free Software
027// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
028//
029// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
030// jataylor@hairyfatguy.com
031//------------------------------------------------------------------------------
032
033public class ExcelCell extends XMLTag
034{
035   private ExcelData mStringDataTag;  // To allow easier addData() functionality
036
037   //---------------------------------------------------------------------------
038   public ExcelCell()
039   {
040      super(SpreadsheetML.CELL);
041   }
042
043   //---------------------------------------------------------------------------
044   public void setComment(String inValue)
045   {
046      addSubtag(new ExcelComment(inValue));
047   }
048
049   //---------------------------------------------------------------------------
050   public void setData(String inValue)
051   {
052      removeSubtagsByName(SpreadsheetML.DATA);
053      mStringDataTag = new ExcelData(inValue);
054      addSubtag(mStringDataTag);
055   }
056
057   //---------------------------------------------------------------------------
058   public void addData(String inValue)
059   {
060      if (null == mStringDataTag)
061      {
062         setData(inValue);
063      }
064      else
065      {
066         mStringDataTag.addContent(inValue);
067      }
068   }
069
070   //---------------------------------------------------------------------------
071   public void setData(int inValue)
072   {
073      removeSubtagsByName(SpreadsheetML.DATA);
074      addSubtag(new ExcelData(inValue));
075   }
076
077   //---------------------------------------------------------------------------
078   public void setData(float inValue)
079   {
080      removeSubtagsByName(SpreadsheetML.DATA);
081      addSubtag(new ExcelData(inValue));
082   }
083
084   //---------------------------------------------------------------------------
085   public void setData(double inValue)
086   {
087      removeSubtagsByName(SpreadsheetML.DATA);
088      addSubtag(new ExcelData(inValue));
089   }
090
091   //---------------------------------------------------------------------------
092   /**
093    Specifies a URL to use to make the Cell a hyperlink.
094    */
095   public ExcelCell setHRef(String inValue)
096   {
097      setAttribute(SpreadsheetML.HREF_ATT, inValue);
098      return this;
099   }
100
101   //---------------------------------------------------------------------------
102   /**
103    The Formula attribute of a Cell element contains the formula associated with
104    the cell. A formula consists of an equals sign (=) followed by calls to Excel
105    functions, operators, values, and references to other cells (in R1C1 format).
106    Ex: '=AVERAGE(R2C2:R10C2)'
107    */
108   public ExcelCell setFormula(String inValue)
109   {
110      setAttribute(SpreadsheetML.FORMULA_ATT, inValue);
111      return this;
112   }
113
114   //---------------------------------------------------------------------------
115   public ExcelCell setIndex(int inValue)
116   {
117      setAttribute(SpreadsheetML.INDEX_ATT, inValue);
118      return this;
119   }
120
121   //---------------------------------------------------------------------------
122   /**
123    Specifies the number of horizontally adjacent cells to merge with this cell.
124    */
125   public ExcelCell setMergeAcross(int inValue)
126   {
127      setAttribute(SpreadsheetML.MERGE_ACROSS_ATT, inValue);
128      return this;
129   }
130
131   //---------------------------------------------------------------------------
132   /**
133    Specifies the number of vertically adjacent cells to merge with this cell.
134    */
135   public ExcelCell setMergeDown(int inValue)
136   {
137      setAttribute(SpreadsheetML.MERGE_DOWN_ATT, inValue);
138      return this;
139   }
140
141   //---------------------------------------------------------------------------
142   public ExcelCell setStyleId(String inValue)
143   {
144      setAttribute(SpreadsheetML.STYLE_ID_ATT, inValue);
145      return this;
146   }
147}