예제 #1
0
        private void LoadWorkBookInfo(ExcelLoadContext context)
        {
            ((IPersistable)this.FileDetails).Load(context);

            if (!context.Package.PartExists(ExcelCommon.Uri_Workbook))
            {
                throw new Exception(string.Format("文档格式错误,未找到{0}", ExcelCommon.Uri_Workbook));
            }

            XElement root = context.Package.GetXElementFromUri(ExcelCommon.Uri_Workbook);

            XElement childNode = root.Element(ExcelCommon.Schema_WorkBook_Main + "bookViews");

            context.Reader.ReadWorkBook_bookViews(childNode);

            childNode = root.Element(ExcelCommon.Schema_WorkBook_Main + "sheets");
            context.Reader.ReadWorkBook_sheets(childNode);

            childNode = root.Element(ExcelCommon.Schema_WorkBook_Main + "definedNames");
            context.Reader.ReadWorkBook_definedNames(childNode, context);

            childNode = root.Element(ExcelCommon.Schema_WorkBook_Main + "fileVersion");
            context.Reader.ReadWorkBook_fileVersion(childNode);

            childNode = root.Element(ExcelCommon.Schema_WorkBook_Main + "workbookPr");
            context.Reader.ReadWorkBook_workbookPr(childNode);

            childNode = root.Element(ExcelCommon.Schema_WorkBook_Main + "workbookProtection");
            context.Reader.ReadWorkBook_workbookProtection(childNode);
        }
예제 #2
0
 void IPersistable.Load(ExcelLoadContext context)
 {
     if (context.Package.PartExists(ExcelCommon.Uri_CalculationChain))
     {
         var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_CalculationChain);
         context.Reader.ReadCalculation(root);
     }
 }
예제 #3
0
		void IPersistable.Load(ExcelLoadContext context)
		{
			if (context.Package.PartExists(ExcelCommon.Uri_Styles))
			{
				var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_Styles);
				context.Reader.ReadStyles(root, this);
			}
		}
예제 #4
0
 private void LoadSharedStrings(ExcelLoadContext context)
 {
     if (context.Package.PartExists(ExcelCommon.Uri_SharedStrings))
     {
         var sharedStringsRoot = context.Package.GetXElementFromUri(ExcelCommon.Uri_SharedStrings);
         context.Reader.ReadSharedStrings(sharedStringsRoot);
     }
 }
예제 #5
0
 void IPersistable.Load(ExcelLoadContext context)
 {
     if (context.Package.PartExists(ExcelCommon.Uri_Styles))
     {
         var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_Styles);
         context.Reader.ReadStyles(root, this);
     }
 }
예제 #6
0
 void IPersistable.Load(ExcelLoadContext context)
 {
     if (context.Package.PartExists(ExcelCommon.Uri_Theme))
     {
         this._Theme = context.Package.GetXDocumentFromUri(ExcelCommon.Uri_Theme);
         //var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_Theme);
         //context.Reader.ReadTheme(root);
     }
 }
예제 #7
0
        void IPersistable.Load(ExcelLoadContext context)
        {
            PackageRelationship drawingsRelation = context.Package.GetPart(this._WorkSheet.SheetUri).GetRelationship(this.RelationshipID);

            this.DrawingUri = PackUriHelper.ResolvePartUri(drawingsRelation.SourceUri, drawingsRelation.TargetUri);
            XElement drawingsElement = context.Package.GetXElementFromUri(this.DrawingUri);

            context.Reader.ReadWrokSheetDrawings(this, drawingsElement, context);
        }
예제 #8
0
        void IPersistable.Load(ExcelLoadContext context)
        {
            PackageRelationship tableRelation = context.Package.GetPart(this._WorkSheet.SheetUri).GetRelationship(this.RelationshipID);

            this._TableUri = PackUriHelper.ResolvePartUri(tableRelation.SourceUri, tableRelation.TargetUri);

            XElement tableElement = context.Package.GetXElementFromUri(PackUriHelper.ResolvePartUri(tableRelation.SourceUri, tableRelation.TargetUri));

            context.Reader.ReadTable(this, tableElement);
        }
예제 #9
0
        void IPersistable.Load(ExcelLoadContext context)
        {
            PackageRelationship sheetRelation = context.Package.GetPart(ExcelCommon.Uri_Workbook).GetRelationship(this.RelationshipID);

            this._SheetUri = PackUriHelper.ResolvePartUri(ExcelCommon.Uri_Workbook, sheetRelation.TargetUri);
            var sheet = context.Package.GetXElementFromUri(this._SheetUri);

            context.Reader.ReadWorkSheet(this, sheet);

            LoadTableValues();
        }
        void IPersistable.Load(ExcelLoadContext context)
        {
            PackagePart currentSheetPart = context.Package.GetPart(this._WorkSheet.SheetUri);

            if (currentSheetPart.RelationshipExists(this._RelationshipID))
            {
                PackageRelationship rel = currentSheetPart.GetRelationship(this._RelationshipID);
                PictureUri = PackUriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);

                XElement vmlDrawingPictureXml = context.Package.GetXElementFromUri(PictureUri);
                if (vmlDrawingPictureXml != null)
                {
                    context.Reader.ReadHeaderFooterVmlDrawingPicture(this, vmlDrawingPictureXml);
                }
            }
        }
예제 #11
0
 private void LoadWorkSheets(ExcelLoadContext context)
 {
     this.Sheets.ForEach(sheet =>
     {
         ((IPersistable)sheet).Load(context);
         sheet.Names.AddRange(context.DefinedNames.Where(nameRange =>
         {
             if (nameRange._WorkSheet != null)
             {
                 return(string.Compare(nameRange._WorkSheet.Name, sheet.Name) == 0);
             }
             else
             {
                 return(false);
             }
         }));
     });
 }
예제 #12
0
        void IPersistable.Load(ExcelLoadContext context)
        {
            #region "LoadCore"
            if (context.Package.PartExists(ExcelCommon.Uri_PropertiesCore))
            {
                var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_PropertiesCore);
                context.Reader.ReadCore(root);
            }
            #endregion

            if (context.Package.PartExists(ExcelCommon.Uri_PropertiesExtended))
            {
                var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_PropertiesExtended);
                context.Reader.ReadApp(root);
            }

            if (context.Package.PartExists(ExcelCommon.Uri_PropertiesCustom))
            {
                this._XmlPropertiesCustom = context.Package.GetXmlFromUri(ExcelCommon.Uri_PropertiesCustom);
            }
        }
예제 #13
0
		void IPersistable.Load(ExcelLoadContext context)
		{
			PackagePart currentSheetPart = context.Package.GetPart(this._WorkSheet.SheetUri);
			if (currentSheetPart.RelationshipExists(this.RelationshipID))
			{
				PackageRelationship vmlDrawingRelation = currentSheetPart.GetRelationship(this.RelationshipID);
				this._VmlDrawingsUri = PackUriHelper.ResolvePartUri(vmlDrawingRelation.SourceUri, vmlDrawingRelation.TargetUri);
				XElement vmlDrawingElement = context.Package.GetXElementFromUri(this._VmlDrawingsUri);
				context.Reader.ReadSheetCommentVmlDrawing(this, vmlDrawingElement);

				PackageRelationshipCollection commentParts = currentSheetPart.GetRelationshipsByType(ExcelCommon.Schema_Comment);
				foreach (PackageRelationship commentPartRelationship in commentParts)
				{
					this._CommentUri = PackUriHelper.ResolvePartUri(commentPartRelationship.SourceUri, commentPartRelationship.TargetUri);
					PackagePart commentPart = context.Package.GetPart(this._CommentUri);
					XDocument commentXml = XDocument.Load(commentPart.GetStream());

					context.Reader.ReadSheetComments(this, commentXml.Root);
				}
			}
		}
예제 #14
0
        void IPersistable.Load(ExcelLoadContext context)
        {
            PackagePart currentSheetPart = context.Package.GetPart(this._WorkSheet.SheetUri);

            if (currentSheetPart.RelationshipExists(this.RelationshipID))
            {
                PackageRelationship vmlDrawingRelation = currentSheetPart.GetRelationship(this.RelationshipID);
                this._VmlDrawingsUri = PackUriHelper.ResolvePartUri(vmlDrawingRelation.SourceUri, vmlDrawingRelation.TargetUri);
                XElement vmlDrawingElement = context.Package.GetXElementFromUri(this._VmlDrawingsUri);
                context.Reader.ReadSheetCommentVmlDrawing(this, vmlDrawingElement);

                PackageRelationshipCollection commentParts = currentSheetPart.GetRelationshipsByType(ExcelCommon.Schema_Comment);
                foreach (PackageRelationship commentPartRelationship in commentParts)
                {
                    this._CommentUri = PackUriHelper.ResolvePartUri(commentPartRelationship.SourceUri, commentPartRelationship.TargetUri);
                    PackagePart commentPart = context.Package.GetPart(this._CommentUri);
                    XDocument   commentXml  = XDocument.Load(commentPart.GetStream());

                    context.Reader.ReadSheetComments(this, commentXml.Root);
                }
            }
        }
예제 #15
0
        private void InnerLoad(Stream input)
        {
            ExceptionHelper.FalseThrow(input.CanRead, "流必须可读与可写!");

            using (Package package = Package.Open(input, FileMode.Open, FileAccess.Read))
            {
                ExcelLoadContext context = new ExcelLoadContext(package);
                context.Reader         = new ExcelReader(this);
                context.Reader.Context = context;

                LoadWorkBookInfo(context);

                LoadSharedStrings(context);

                LoadStyles(context);

                LoadAppTheme(context);

                LoadWorkSheets(context);

                LoadCalculationChains(context);
            }
        }
예제 #16
0
        internal void ReadWrokSheetDrawings(DrawingCollection target, XElement targetElement, ExcelLoadContext context)
        {

            IEnumerable<XElement> childNodes = targetElement.Elements(XName.Get("twoCellAnchor", ExcelCommon.Schema_SheetDrawings));
            ExcelDrawing drTarget = null;
            foreach (XElement xnode in childNodes)
            {
                XElement childNode = xnode.Element(XName.Get("sp", ExcelCommon.Schema_SheetDrawings));
                if (childNode != null)
                {
                    //return new Shape(target);
                }

                childNode = xnode.Element(XName.Get("pic", ExcelCommon.Schema_SheetDrawings));
                if (childNode != null)
                {
                    ExcelPicture drPictureTarget = new ExcelPicture(target._WorkSheet);
                    ReadWrokSheetDrawings_DrawingPic(drPictureTarget, childNode, target.DrawingUri);
                    drTarget = drPictureTarget;
                }

                childNode = xnode.Element(XName.Get("graphicFrame", ExcelCommon.Schema_SheetDrawings));
                if (childNode != null)
                {
                    string rId = xnode.Element(XName.Get("graphicFrame", ExcelCommon.Schema_SheetDrawings)).Element(XName.Get("graphic", ExcelCommon.Schema_Drawings)).Element(XName.Get("graphicData", ExcelCommon.Schema_Drawings)).Element(XName.Get("chart", ExcelCommon.Schema_Chart)).LastAttribute.Value;
                    PackageRelationship drawingsRelation = context.Package.GetPart(target.DrawingUri).GetRelationship(rId);
                    Uri chartUri = PackUriHelper.ResolvePartUri(drawingsRelation.SourceUri, drawingsRelation.TargetUri);
                    XElement drawingsElement = context.Package.GetXElementFromUri(chartUri);

                    string chartType = ((XElement)(drawingsElement.Element(XName.Get("chart", ExcelCommon.Schema_Chart)).Element(XName.Get("plotArea", ExcelCommon.Schema_Chart)).Element(XName.Get("layout", ExcelCommon.Schema_Chart)).NextNode)).Name.LocalName;
                    XElement element = childNode.Element(XName.Get("nvGraphicFramePr", ExcelCommon.Schema_SheetDrawings)).Element(XName.Get("cNvPr", ExcelCommon.Schema_SheetDrawings));
                    if (element != null)
                    {
                        string chartName = element.Attribute(XName.Get("name")).Value;
                        ExcelChartType chartTypeEnum;
                        Enum.TryParse(chartType.Replace("Chart", string.Empty), true, out chartTypeEnum);
                        ExcelChart chart = target.AddChart(chartName, chartTypeEnum);
                        chart.DrawingUri = target.DrawingUri;
                        chart.RelationshipID = rId;
                        ((IPersistable)chart).Load(context);
                        drTarget = chart;
                    }
                }
                if (drTarget != null)
                {
                    ReadWrokSheetDrawings_Attribute(drTarget, xnode);
                    ReadWrokSheetDrawings_clientData(drTarget, xnode);
                    ReadWrokSheetDrawings_Common_Position(drTarget, xnode);
                }

            }

        }
예제 #17
0
 internal void ReadPieCharts(ExcelChart target, XElement targetElement, ExcelLoadContext context)
 {
     XElement childNode = targetElement.Element(XName.Get("chart", ExcelCommon.Schema_Chart)).Element(XName.Get("plotArea", ExcelCommon.Schema_Chart)).Element(XName.Get("pie3DChart", ExcelCommon.Schema_Chart));
     if (childNode != null)
     {
         ReadPieCharts_varyColors(target, childNode);
         ReadPieCharts_dLbls(target, childNode);
         ReadPieCharts_ser(target, childNode);
     }
 }
예제 #18
0
		void IPersistable.Load(ExcelLoadContext context)
		{
			#region "LoadCore"
			if (context.Package.PartExists(ExcelCommon.Uri_PropertiesCore))
			{
				var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_PropertiesCore);
				context.Reader.ReadCore(root);
			}
			#endregion

			if (context.Package.PartExists(ExcelCommon.Uri_PropertiesExtended))
			{
				var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_PropertiesExtended);
				context.Reader.ReadApp(root);
			}

			if (context.Package.PartExists(ExcelCommon.Uri_PropertiesCustom))
			{
				this._XmlPropertiesCustom = context.Package.GetXmlFromUri(ExcelCommon.Uri_PropertiesCustom);
			}
		}
예제 #19
0
        /// <summary>
        /// FileName:workbook.xml 
        /// <para>NodePath:workbook/definedNames</para>
        /// </summary>
        /// <param name="definedNamesRoot"></param>
        internal void ReadWorkBook_definedNames(XElement definedNamesRoot, ExcelLoadContext context)
        {
            if (definedNamesRoot != null)
            {
                foreach (XElement item in definedNamesRoot.Nodes())
                {
                    Match rangeMatch = DefinedName.NameRangeReferenceRegex.Match(item.Value);
                    if (rangeMatch.Success)
                    {
                        if (rangeMatch.Groups["Sheet"].Success)
                        {
                            string sheetName = rangeMatch.Groups["Sheet"].Value;
                            if (sheetName.IsNotEmpty())
                            {
                                WorkSheet currentSheet = this.WorkBook.Sheets[sheetName];

                                DefinedName namedRange = new DefinedName(item.Attribute("name").Value, currentSheet)
                                {
                                    Address = Range.Parse(currentSheet, rangeMatch.Groups["Range"].Value),
                                    NameComment = item.Attribute("comment") == null ? string.Empty : item.Attribute("comment").Value,
                                    IsNameHidden = item.Attribute("hidden") == null ? false : (int.Parse(item.Attribute("hidden").Value) == 1 ? true : false),
                                };
                                if (item.Attribute("localSheetId") != null)
                                {
                                    int localsheetID;
                                    if (int.TryParse(item.Attribute("localSheetId").Value, out localsheetID))
                                        namedRange.LocalSheetId = localsheetID;
                                }

                                context.DefinedNames.Add(namedRange);
                            }
                        }

                        //todo: pivottable 
                        // if (rangeMatch.Groups["Table"].Success)

                    }

                    /*	DefinedName namedRange = new DefinedName(item.Attributes("name"),) 
                        { 
                            Address = item.Value
                        };

                       item.Attributes("name")
                        foreach (XAttribute attr in item.Attributes())
                        {
                            switch (attr.Name.LocalName)
                            {
                                case "name":
                                    namedRange.Name = attr.Value;
                                    break;
                                case "comment":
                                    namedRange.NameComment = attr.Value;
                                    break;
                                case "localSheetId":
                                    namedRange.LocalSheetId = int.Parse(attr.Value);
                                    break;
                                case "hidden":
                                    namedRange.IsNameHidden = int.Parse(attr.Value) == 1 ? true : false;
                                    break;
                            }
                        }
                       this.WorkBook.Names.Add(namedRange);*/
                }
            }
        }
예제 #20
0
 private void LoadCalculationChains(ExcelLoadContext context)
 {
     ((IPersistable)this.CalculationChain).Load(context);
 }
예제 #21
0
		void IPersistable.Load(ExcelLoadContext context)
		{
			if (context.Package.PartExists(ExcelCommon.Uri_Theme))
			{
				this._Theme = context.Package.GetXDocumentFromUri(ExcelCommon.Uri_Theme);
				//var root = context.Package.GetXElementFromUri(ExcelCommon.Uri_Theme);
				//context.Reader.ReadTheme(root);
			}
		}
예제 #22
0
 private void LoadAppTheme(ExcelLoadContext context)
 {
     ((IPersistable)this.Theme).Load(context);
 }
예제 #23
0
 private void LoadStyles(ExcelLoadContext context)
 {
     ((IPersistable)context.GlobalStyles).Load(context);
 }