001package com.hfg.xml.msofficexml.xlsx.part;
002
003
004import java.io.BufferedInputStream;
005import java.io.File;
006
007import com.hfg.xml.XMLTag;
008import com.hfg.xml.msofficexml.OfficeXML;
009import com.hfg.xml.msofficexml.docx.RelationshipXML;
010import com.hfg.xml.msofficexml.part.OfficeXMLPart;
011import com.hfg.xml.msofficexml.xlsx.Xlsx;
012import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlWorksheet;
013import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXML;
014
015//------------------------------------------------------------------------------
016/**
017 * Worksheet Part of a OfficeOpenXML xlsx Excel document.
018 *
019 * @author J. Alex Taylor, hairyfatguy.com
020 */
021//------------------------------------------------------------------------------
022// com.hfg XML/HTML Coding Library
023//
024// This library is free software; you can redistribute it and/or
025// modify it under the terms of the GNU Lesser General Public
026// License as published by the Free Software Foundation; either
027// version 2.1 of the License, or (at your option) any later version.
028//
029// This library is distributed in the hope that it will be useful,
030// but WITHOUT ANY WARRANTY; without even the implied warranty of
031// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
032// Lesser General Public License for more details.
033//
034// You should have received a copy of the GNU Lesser General Public
035// License along with this library; if not, write to the Free Software
036// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
037//
038// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
039// jataylor@hairyfatguy.com
040//------------------------------------------------------------------------------
041
042public class WorksheetPart extends OfficeXMLPart
043{
044   //###########################################################################
045   // PRIVATE FIELDS
046   //###########################################################################
047
048   private int                       mSheetIndex;
049   private WorksheetRelationshipPart mWorksheetRelationshipPart;
050
051   //###########################################################################
052   // CONSTRUCTORS
053   //###########################################################################
054
055   //---------------------------------------------------------------------------
056   public WorksheetPart(Xlsx inXlsx)
057   {
058      super(inXlsx);
059
060      XMLTag rootNode = new SsmlWorksheet(this);
061      rootNode.addXMLNamespaceDeclaration(OfficeXML.OFFICE_NAMESPACE);
062      rootNode.addXMLNamespaceDeclaration(RelationshipXML.RELATIONSHIP_NAMESPACE);
063/*
064      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006"));
065      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"));
066      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("v", "urn:schemas-microsoft-com:vml"));
067      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("w10", "urn:schemas-microsoft-com:office:word"));
068      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("wne", "http://schemas.microsoft.com/office/word/2006/wordml"));
069*/
070      setRootNode(rootNode);
071   }
072
073   //---------------------------------------------------------------------------
074   public WorksheetPart(Xlsx inXlsx, String inName, XMLTag inSheetTag)
075   {
076      super(inXlsx);
077
078      SsmlWorksheet worksheet = new SsmlWorksheet(this, inName, inSheetTag);
079      setRootNode(worksheet);
080   }
081
082   //###########################################################################
083   // PUBLIC METHODS
084   //###########################################################################
085
086   //---------------------------------------------------------------------------
087   public WorksheetRelationshipPart getWorksheetRelationshipPart()
088   {
089      if (null == mWorksheetRelationshipPart)
090      {
091         mWorksheetRelationshipPart = new WorksheetRelationshipPart(this);
092      }
093
094      return mWorksheetRelationshipPart;
095   }
096
097   //---------------------------------------------------------------------------
098   public WorksheetPart setSheetIndex(int inValue)
099   {
100      mSheetIndex = inValue;
101      return this;
102   }
103
104   //---------------------------------------------------------------------------
105   public Integer getSheetIndex()
106   {
107      return mSheetIndex;
108   }
109
110   //---------------------------------------------------------------------------
111   @Override
112   public File getFile()
113   {
114      return new File(SsmlXML.WORKSHEETS_DIR, "sheet" + mSheetIndex + ".xml");
115   }
116
117   //---------------------------------------------------------------------------
118   @Override
119   public SsmlWorksheet getRootNode()
120   {
121      SsmlWorksheet rootNode = (SsmlWorksheet) super.getRootNode();
122      if (null == rootNode)
123      {
124         rootNode = new SsmlWorksheet(this);
125         setRootNode(rootNode);
126      }
127
128      return rootNode;
129   }
130}