Beispiel #1
0
        internal CommentsTable(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            XmlDocument xml = ConvertStreamToXml(part.GetInputStream());
            ReadFrom(xml);
        }
Beispiel #2
0
        /**
         * Construct POIXMLDocumentPart representing a "core document" namespace part.
         */
        public POIXMLDocumentPart(OPCPackage pkg)
        {
            PackageRelationship coreRel = pkg.GetRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).GetRelationship(0);

            this.packagePart = pkg.GetPart(coreRel);
            this.packageRel = coreRel;
        }
Beispiel #3
0
        public override POIXMLDocumentPart CreateDocumentPart(POIXMLDocumentPart parent, PackageRelationship rel, PackagePart part)
        {
            POIXMLRelation descriptor = XWPFRelation.GetInstance(rel.RelationshipType);
            if (descriptor == null || descriptor.RelationClass == null)
            {
                logger.Log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.RelationshipType);
                return new POIXMLDocumentPart(part, rel);
            }

            try
            {
                Type cls = descriptor.RelationClass;
                try
                {
                    ConstructorInfo constructor = cls.GetConstructor(new Type[] { typeof(POIXMLDocumentPart), typeof(PackagePart), typeof(PackageRelationship) });
                    return constructor.Invoke(new object[] { parent, part, rel }) as POIXMLDocumentPart;
                }
                catch (Exception)
                {
                    ConstructorInfo constructor = cls.GetConstructor(new Type[] { typeof(PackagePart), typeof(PackageRelationship) });
                    return constructor.Invoke(new object[] { part, rel }) as POIXMLDocumentPart;
                }
            }
            catch (Exception e)
            {
                throw new POIXMLException(e);
            }
        }
Beispiel #4
0
        /**
         * Construct a SpreadsheetML chart from a namespace part.
         *
         * @param part the namespace part holding the chart data,
         * the content type must be <code>application/vnd.Openxmlformats-officedocument.Drawingml.chart+xml</code>
         * @param rel  the namespace relationship holding this chart,
         * the relationship type must be http://schemas.Openxmlformats.org/officeDocument/2006/relationships/chart
         */
        protected XSSFChart(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            XmlDocument doc = ConvertStreamToXml(part.GetInputStream());
            chartSpaceDocument = ChartSpaceDocument.Parse(doc, NamespaceManager);
            chart = chartSpaceDocument.GetChartSpace().chart;
        }
Beispiel #5
0
        /**
         * Construct a SpreadsheetML chart from a namespace part.
         *
         * @param part the namespace part holding the chart data,
         * the content type must be <code>application/vnd.Openxmlformats-officedocument.Drawingml.chart+xml</code>
         * @param rel  the namespace relationship holding this chart,
         * the relationship type must be http://schemas.Openxmlformats.org/officeDocument/2006/relationships/chart
         */
        protected XSSFChart(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {


            chartSpace = ChartSpaceDocument.Parse(part.GetInputStream()).GetChartSpace();
            chart = chartSpace.chart;
        }
Beispiel #6
0
 /**
  * Construct a SpreadsheetML Drawing from a namespace part
  *
  * @param part the namespace part holding the Drawing data,
  * the content type must be <code>application/vnd.openxmlformats-officedocument.Drawing+xml</code>
  * @param rel  the namespace relationship holding this Drawing,
  * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing
  */
 internal XSSFDrawing(PackagePart part, PackageRelationship rel)
     : base(part, rel)
 {
     //XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
     ////Removing root element
     //options.setLoadReplaceDocumentElement(null);
     //drawing = CTDrawing.Factory.parse(part.getInputStream(), options);
     drawing = NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Drawing.Parse(part.GetInputStream());
 }
Beispiel #7
0
 /**
  * Get the PackagePart that is the target of a relationship.
  *
  * @param rel The relationship
  * @param pkg The namespace to fetch from
  * @return The target part
  * @throws InvalidFormatException
  */
 protected static PackagePart GetTargetPart(OPCPackage pkg, PackageRelationship rel)
  {
     PackagePartName relName = PackagingUriHelper.CreatePartName(rel.TargetUri);
     PackagePart part = pkg.GetPart(relName);
     if (part == null) {
         throw new ArgumentException("No part found for relationship " + rel);
     }
     return part;
 }
Beispiel #8
0
        /**
         * Create a XSSFHyperlink amd Initialize it from the supplied CTHyperlink bean and namespace relationship
         *
         * @param ctHyperlink the xml bean Containing xml properties
         * @param hyperlinkRel the relationship in the underlying OPC namespace which stores the actual link's Address
         */
        public XSSFHyperlink(CT_Hyperlink ctHyperlink, PackageRelationship hyperlinkRel)
        {
            _ctHyperlink = ctHyperlink;
            _externalRel = hyperlinkRel;

            // Figure out the Hyperlink type and distination

            // If it has a location, it's internal
            if (ctHyperlink.location != null)
            {
                _type = HyperlinkType.Document;
                _location = ctHyperlink.location;
            }
            else
            {
                // Otherwise it's somehow external, check
                //  the relation to see how
                if (_externalRel == null)
                {
                    if (ctHyperlink.id != null)
                    {
                        throw new InvalidOperationException("The hyperlink for cell " +
                            ctHyperlink.@ref + " references relation " + ctHyperlink.id + ", but that didn't exist!");
                    }
                    // hyperlink is internal and is not related to other parts
                    _type = HyperlinkType.Document;
                }
                else
                {
                    Uri target = _externalRel.TargetUri;
                    try
                    {
                        _location = target.ToString();
                    }
                    catch (UriFormatException)
                    {
                        _location = target.OriginalString;
                    }

                    // Try to figure out the type
                    if (_location.StartsWith("http://") || _location.StartsWith("https://")
                            || _location.StartsWith("ftp://"))
                    {
                        _type = HyperlinkType.Url;
                    }
                    else if (_location.StartsWith("mailto:"))
                    {
                        _type = HyperlinkType.Email;
                    }
                    else
                    {
                        _type = HyperlinkType.File;
                    }
                }
            }
        }
        public XWPFHeaderFooter(POIXMLDocumentPart parent, PackagePart part, PackageRelationship rel) :
            base(parent, part, rel)
        {
            ;
            this.document = (XWPFDocument)GetParent();

            if (this.document == null)
            {
                throw new NullReferenceException();
            }
        }
Beispiel #10
0
        internal ThemesTable(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            //theme = ThemeDocument.Parse(part.GetInputStream());
            try
            {
                theme = ThemeDocument.Parse(part.GetInputStream());
            }
            catch (XmlException e)
            {
                throw new IOException(e.Message);
            }
        }
Beispiel #11
0
        /**
         * Construct a ThemesTable.
         * @param part A PackagePart.
         * @param rel A PackageRelationship.
         */
        internal ThemesTable(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            XmlDocument xmldoc = ConvertStreamToXml(part.GetInputStream());
                
            try
            {
                theme = ThemeDocument.Parse(xmldoc, NamespaceManager);
            }
            catch (XmlException e)
            {
                throw new IOException(e.Message);
            }
        }
Beispiel #12
0
        /**
         * Create a XSSFHyperlink amd Initialize it from the supplied CTHyperlink bean and namespace relationship
         *
         * @param ctHyperlink the xml bean Containing xml properties
         * @param hyperlinkRel the relationship in the underlying OPC namespace which stores the actual link's Address
         */
        public XSSFHyperlink(CT_Hyperlink ctHyperlink, PackageRelationship hyperlinkRel)
        {
            _ctHyperlink = ctHyperlink;
            _externalRel = hyperlinkRel;

            // Figure out the Hyperlink type and distination

            // If it has a location, it's internal
            if (ctHyperlink.location != null)
            {
                _type = HyperlinkType.DOCUMENT;
                _location = ctHyperlink.location;
            }
            else
            {
                // Otherwise it's somehow external, check
                //  the relation to see how
                if (_externalRel == null)
                {
                    if (ctHyperlink.id != null)
                    {
                        throw new InvalidOperationException("The hyperlink for cell " + 
                            ctHyperlink.@ref + " references relation " + ctHyperlink.id + ", but that didn't exist!");
                    }
                    throw new InvalidOperationException("A sheet hyperlink must either have a location, or a relationship. Found:\n" + ctHyperlink);
                }

                Uri target = _externalRel.TargetUri;
                _location = target.ToString();

                // Try to figure out the type
                if (_location.StartsWith("http://") || _location.StartsWith("https://")
                        || _location.StartsWith("ftp://"))
                {
                    _type = HyperlinkType.URL;
                }
                else if (_location.StartsWith("mailto:"))
                {
                    _type = HyperlinkType.EMAIL;
                }
                else
                {
                    _type = HyperlinkType.FILE;
                }
            }
        }
Beispiel #13
0
 /**
  * Link this shape with the picture data
  *
  * @param rel relationship referring the picture data
  */
 internal void SetPictureReference(PackageRelationship rel)
 {
     ctPicture.blipFill.blip.embed = rel.Id;
 }
Beispiel #14
0
 /**
  * Checks if the specified relationship is part of this package part.
  * 
  * @param rel
  *            The relationship to check.
  * @return <b>true</b> if the specified relationship exists in this part,
  *         else returns <b>false</b>
  * @see org.apache.poi.OpenXml4Net.opc.RelationshipSource#isRelationshipExists(org.apache.poi.OpenXml4Net.opc.PackageRelationship)
  */
 public bool IsRelationshipExists(PackageRelationship rel)
 {
     try
     {
         foreach (PackageRelationship r in this.Relationships)
         {
             if (r == rel)
                 return true;
         }
     }
     catch (InvalidFormatException)
     { 
     
     }
     return false;
 }
Beispiel #15
0
 /**
  * Construct XWPFPictureData from a package part
  *
  * @param part the package part holding the Drawing data,
  * @param rel  the package relationship holding this Drawing,
  * the relationship type must be http://schemas.Openxmlformats.org/officeDocument/2006/relationships/image
  */
 public XWPFPictureData(PackagePart part, PackageRelationship rel)
     : base(part, rel)
 {
 }
Beispiel #16
0
        internal SharedStringsTable(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            var xml = ConvertStreamToXml(part.GetInputStream());
            ReadFrom(xml);
        }
Beispiel #17
0
 /**
  * Construct a SpreadsheetML Drawing from a namespace part
  *
  * @param part the namespace part holding the Drawing data,
  * the content type must be <code>application/vnd.openxmlformats-officedocument.Drawing+xml</code>
  * @param rel  the namespace relationship holding this Drawing,
  * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing
  */
 internal XSSFDrawing(PackagePart part, PackageRelationship rel)
     : base(part, rel)
 {
     XmlDocument xmldoc = ConvertStreamToXml(part.GetInputStream());
     drawing = NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Drawing.Parse(xmldoc, NamespaceManager);
 }
Beispiel #18
0
 /**
  * Get the PackagePart that is the target of a relationship.
  *
  * @param rel The relationship
  * @return The target part
  * @throws InvalidFormatException
  */
 protected PackagePart GetTargetPart(PackageRelationship rel)
 {
     return GetPackagePart().GetRelatedPart(rel);
 }
Beispiel #19
0
        /**
         * Construct XWPFStyles from a package part
         *
         * @param part the package part holding the data of the styles,
         * @param rel  the package relationship of type "http://schemas.Openxmlformats.org/officeDocument/2006/relationships/styles"
         */

        public XWPFStyles(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {
        }
Beispiel #20
0
        public XWPFSettings(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

        }
 /**
  * Construct a SpreadsheetML Drawing from a namespace part
  *
  * @param part the namespace part holding the Drawing data,
  * the content type must be <code>application/vnd.Openxmlformats-officedocument.Drawing+xml</code>
  * @param rel  the namespace relationship holding this Drawing,
  * the relationship type must be http://schemas.Openxmlformats.org/officeDocument/2006/relationships/drawing
  */
 protected XSSFVMLDrawing(PackagePart part, PackageRelationship rel)
     : base(part, rel)
 {
     Read(GetPackagePart().GetInputStream());
 }
Beispiel #22
0
        /**
         * Creates an XSSFSheet representing the given namespace part and relationship.
         * Should only be called by XSSFWorkbook when Reading in an exisiting file.
         *
         * @param part - The namespace part that holds xml data represenring this sheet.
         * @param rel - the relationship of the given namespace part in the underlying OPC namespace
         */
        internal XSSFSheet(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            dataValidationHelper = new XSSFDataValidationHelper(this);
        }
Beispiel #23
0
        /**
        * Get the PackagePart that is the target of a relationship.
        *
        * @param rel A relationship from this part to another one 
        * @return The target part of the relationship
        */
        public PackagePart GetRelatedPart(PackageRelationship rel)
        {
            // Ensure this is one of ours
            if (!IsRelationshipExists(rel))
            {
                throw new ArgumentException("Relationship " + rel + " doesn't start with this part " + partName);
            }

            // Get the target URI, excluding any relative fragments
            Uri target = rel.TargetUri;
            if (target.Fragment != null)
            {
                String t = target.ToString();
                try
                {
                    target = new Uri(t.Substring(0, t.IndexOf('#')));
                }
                catch (UriFormatException e)
                {
                    throw new InvalidFormatException("Invalid target URI: " + target);
                }
            }

            // Turn that into a name, and fetch
            PackagePartName relName = PackagingUriHelper.CreatePartName(target);
            PackagePart part = container.GetPart(relName);
            if (part == null)
            {
                throw new ArgumentException("No part found for relationship " + rel);
            }
            return part;
        }
Beispiel #24
0
 /**
  * Creates an POIXMLDocumentPart representing the given namespace part, relationship and parent
  * Called by {@link #read(POIXMLFactory, java.util.Map)} when Reading in an exisiting file.
  *
  * @param parent - Parent part
  * @param part - The namespace part that holds xml data represenring this sheet.
  * @param rel - the relationship of the given namespace part
  * @see #read(POIXMLFactory, java.util.Map)
  */
 public POIXMLDocumentPart(POIXMLDocumentPart parent, PackagePart part, PackageRelationship rel)
 {
     this.packagePart = part;
     this.packageRel = rel;
     this.parent = parent;
 }
Beispiel #25
0
 /**
  * When you open something like a theme, call this to
  *  re-base the XML Document onto the core child of the
  *  current core document 
  */
 protected void Rebase(OPCPackage pkg)
 {
     PackageRelationshipCollection cores =
         packagePart.GetRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
     if (cores.Size != 1)
     {
         throw new InvalidOperationException(
             "Tried to rebase using " + PackageRelationshipTypes.CORE_DOCUMENT +
             " but found " + cores.Size + " parts of the right type"
         );
     }
     packageRel = cores.GetRelationship(0);
     packagePart = packagePart.GetRelatedPart(packageRel);
 }
Beispiel #26
0
        /**
         * Construct XSSFPictureData from a namespace part
         *
         * @param part the namespace part holding the Drawing data,
         * @param rel  the namespace relationship holding this Drawing,
         * the relationship type must be http://schemas.Openxmlformats.org/officeDocument/2006/relationships/image
         */
        internal XSSFPictureData(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

        }
Beispiel #27
0
        internal SharedStringsTable(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            ReadFrom(part.GetInputStream());
        }
Beispiel #28
0
        internal MapInfo(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            ReadFrom(part.GetInputStream());
        }
Beispiel #29
0
        /**
        * Creates an XSSFPivotTable representing the given package part and relationship.
        * Should only be called when Reading in an existing file.
        *
        * @param part - The package part that holds xml data representing this pivot table.
        * @param rel - the relationship of the given package part in the underlying OPC package
        */

        protected XSSFPivotTable(PackagePart part, PackageRelationship rel)
            : base(part, rel)
        {

            ReadFrom(part.GetInputStream());
        }
Beispiel #30
0
 public XWPFHeader(POIXMLDocumentPart parent, PackagePart part, PackageRelationship rel)
     : base(parent, part, rel)
 {
     ;
 }