当前位置: 首页>>代码示例>>C#>>正文


C# PackagePart.CreateRelationship方法代码示例

本文整理汇总了C#中System.IO.Packaging.PackagePart.CreateRelationship方法的典型用法代码示例。如果您正苦于以下问题:C# PackagePart.CreateRelationship方法的具体用法?C# PackagePart.CreateRelationship怎么用?C# PackagePart.CreateRelationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Packaging.PackagePart的用法示例。


在下文中一共展示了PackagePart.CreateRelationship方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreatePartRelationship

 private static void CreatePartRelationship(Uri partUri, string partRelationshipType, string partId, PackagePart parentPart)
 {
     Uri relativeUri = PackUriHelper.GetRelativeUri(parentPart.Uri, partUri);
     parentPart.CreateRelationship(relativeUri, TargetMode.Internal, partRelationshipType, partId);
 }
开发者ID:GropenD,项目名称:MadMilkman.Docx,代码行数:5,代码来源:DocxPackageWriter.cs

示例2: WriteWorkSheet_hyperLinks

        private XElement WriteWorkSheet_hyperLinks(WorkSheet sheet, List<Cell> sheetHyperLink, PackagePart worksheetPart)
        {
            XElement sheethyperlinks = new XElement(XName.Get("hyperlinks", ExcelCommon.Schema_WorkBook_Main.NamespaceName));

            Dictionary<string, string> hyps = new Dictionary<string, string>();

            foreach (Cell celllink in sheetHyperLink)
            {
                XElement hyperlinkNode = new XElement(XName.Get("hyperlink", ExcelCommon.Schema_WorkBook_Main.NamespaceName));

                #region "location"
                //if (string.IsNullOrEmpty(celllink._Hyperlink.AbsoluteUri))
                if (celllink._Hyperlink.AbsoluteUri == "xl://internal/")
                {
                    if (celllink._Hyperlink is ExcelHyperLink)
                    {
                        ExcelHyperLink hyperlink = celllink._Hyperlink as ExcelHyperLink;

                        string address = Range.Parse(sheet, celllink.Column.Index, celllink.Row.Index, hyperlink.ColSpann + celllink.Column.Index, celllink.Row.Index + hyperlink.RowSpann).ToAddress();
                        hyperlinkNode.Add(new XAttribute("ref", address));

                        if (hyperlink.ReferenceAddress.IsNotEmpty())
                        {
                            string strlocation = hyperlink.ReferenceAddress;
                            if (strlocation.Contains("!"))
                            {
                                if (strlocation[0] != '\'')
                                {
                                    hyperlinkNode.Add(new XAttribute("location", string.Format("'{0}'!{1}", strlocation.Substring(0, strlocation.IndexOf('!')), strlocation.Substring(strlocation.IndexOf('!') + 1))));
                                }
                                else
                                {
                                    hyperlinkNode.Add(new XAttribute("location", strlocation));
                                }
                            }
                            else
                            {
                                hyperlinkNode.Add(new XAttribute("location", string.Format("'{0}'!{1}", sheet.Name, strlocation)));
                            }
                        }

                        if (hyperlink.Display.IsNotEmpty())
                        {
                            hyperlinkNode.Add(new XAttribute("display", hyperlink.Display));
                        }

                        if (hyperlink.ToolTip.IsNotEmpty())
                        {
                            hyperlinkNode.Add(new XAttribute("tooltip", hyperlink.Display));
                        }
                    }
                }
                else
                {
                    if (hyperlinkNode.Attribute(XName.Get("ref", ExcelCommon.Schema_WorkBook_Main.NamespaceName)) == null)
                    {
                        hyperlinkNode.Add(new XAttribute("ref", celllink.ToString()));
                    }
                    string idRelations = string.Empty;
                    if (hyps.ContainsKey(celllink._Hyperlink.AbsoluteUri))
                    {
                        idRelations = hyps[celllink._Hyperlink.AbsoluteUri];
                    }
                    else
                    {
                        idRelations = worksheetPart.CreateRelationship(celllink._Hyperlink, TargetMode.External, ExcelCommon.Schema_Hyperlink).Id;
                        hyps.Add(celllink._Hyperlink.AbsoluteUri, idRelations);
                    }
                    hyperlinkNode.Add(new XAttribute(XName.Get("id", ExcelCommon.Schema_Relationships), idRelations));
                }
                #endregion
                sheethyperlinks.Add(hyperlinkNode);
            }
            return sheethyperlinks;
        }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:75,代码来源:ExcelWriter.cs

示例3: WriteWorkBook_sheets

        /// <summary>
        /// FileName:workbook.xml 
        /// <para>NodePath:workbook/sheets</para>
        /// </summary>
        private XElement WriteWorkBook_sheets(PackagePart partWorkbook)
        {
            XElement sheets = new XElement(ExcelCommon.Schema_WorkBook_Main + "sheets");

            int sheetID = 1;
            foreach (WorkSheet sheet in this.Workbook.Sheets)
            {
                foreach (var definedName in sheet.Names)
                {
                    this.Context.DefinedNames.Add(definedName);
                }

                XElement sheetElement = new XElement(ExcelCommon.Schema_WorkBook_Main + "sheet");
                sheetElement.Add(new XAttribute("name", sheet.Name));
                sheetElement.Add(new XAttribute("sheetId", sheetID));

                sheet.SheetUri = new Uri("/xl/worksheets/sheet" + sheetID + ".xml", UriKind.Relative);
                sheet.RelationshipID = partWorkbook.CreateRelationship(PackUriHelper.GetRelativeUri(ExcelCommon.Uri_Workbook,
                    sheet.SheetUri), TargetMode.Internal, ExcelCommon.Schema_Relationships + "/worksheet").Id;

                XName name = XName.Get("id", ExcelCommon.Schema_Relationships);
                sheetElement.Add(new XAttribute(name, sheet.RelationshipID));

                #region "Hidden"
                if (sheet.Hidden == ExcelWorksheetHidden.Hidden)
                {
                    sheetElement.Add(new XAttribute("state", "hidden"));
                }
                else if (sheet.Hidden == ExcelWorksheetHidden.VeryHidden)
                {
                    sheetElement.Add(new XAttribute("state", "veryHidden"));
                }
                #endregion

                sheets.Add(sheetElement);
                sheetID++;
            }

            return sheets;
        }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:44,代码来源:ExcelWriter.cs

示例4: WriteWorkSheet_HeaderFooter_Pictures

 private void WriteWorkSheet_HeaderFooter_Pictures(WorkSheet sheet, PackagePart worksheetPart)
 {
     if (sheet._HeaderFooter._Pictures != null)
     {
         if (sheet._HeaderFooter._Pictures.Count > 0)
         {
             sheet._HeaderFooter._Pictures.PictureUri = this.Context.Package.GetNewUri(@"/xl/drawings/vmlDrawing{0}.vml");
             PackageRelationship rel = worksheetPart.CreateRelationship(PackUriHelper.GetRelativeUri(sheet.SheetUri, sheet._HeaderFooter._Pictures.PictureUri), TargetMode.Internal, ExcelCommon.Schema_Relationships + "/vmlDrawing");
             sheet._HeaderFooter._Pictures.RelationshipID = rel.Id;
             ((IPersistable)sheet._HeaderFooter._Pictures).Save(this.Context);
         }
         else
         {
             sheet._HeaderFooter._Pictures.RelationshipID = string.Empty;
         }
     }
 }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:17,代码来源:ExcelWriter.cs

示例5: WriteWrokSheetDrawing_Content_pic

        private XElement WriteWrokSheetDrawing_Content_pic(ExcelPicture pic, DrawingCollection drawingCollection, PackagePart wrokSheetDrawingPart, int index)
        {
            XElement picNode = new XElement(XName.Get("pic", ExcelCommon.Schema_SheetDrawings));

            #region "nvPicPr"
            XElement nvPicPrNode = new XElement(XName.Get("nvPicPr", ExcelCommon.Schema_SheetDrawings));
            XElement cNvPrNode = new XElement(XName.Get("cNvPr", ExcelCommon.Schema_SheetDrawings),
                new XAttribute(XName.Get("id"), (index + 2).ToString()));
            if (string.IsNullOrEmpty(pic.Name))
                cNvPrNode.Add(new XAttribute(XName.Get("name"), string.Format("图片 {0}", index)));
            else
                cNvPrNode.Add(new XAttribute(XName.Get("name"), pic.Name));

            nvPicPrNode.Add(cNvPrNode);

            XElement cNvPicPrNode = new XElement(XName.Get("cNvPicPr", ExcelCommon.Schema_SheetDrawings));
            cNvPicPrNode.Add(new XElement(XName.Get("picLocks", ExcelCommon.Schema_Drawings), new XAttribute("noChangeAspect", 1)));
            nvPicPrNode.Add(cNvPicPrNode);
            picNode.Add(nvPicPrNode);
            #endregion "nvPicPr"

            #region "blipFill"
            XElement blipFillNode = new XElement(XName.Get("blipFill", ExcelCommon.Schema_SheetDrawings));
            XElement blipNode = new XElement(XName.Get("blip", ExcelCommon.Schema_Drawings));
            blipNode.Add(new XAttribute(XName.Get("R", XNamespace.Xmlns.NamespaceName), ExcelCommon.Schema_Relationships));

            ExcelImageInfo currentImage = SavePicture(pic.Name, pic.ImageFormat, pic.Image, pic.ContentType);
            if (this.Context.HashImageRelationships.ContainsKey(currentImage.Hash))
                blipNode.Add(new XAttribute(XName.Get("embed", ExcelCommon.Schema_Relationships), this.Context.HashImageRelationships[currentImage.Hash]));
            else
            {
                PackageRelationship picRelation = wrokSheetDrawingPart.CreateRelationship(PackUriHelper.GetRelativeUri(drawingCollection.DrawingUri, currentImage.Uri), TargetMode.Internal, ExcelCommon.Schema_Relationships + "/image");
                blipNode.Add(new XAttribute(XName.Get("embed", ExcelCommon.Schema_Relationships), picRelation.Id));
                this.Context.HashImageRelationships.Add(currentImage.Hash, picRelation.Id);
            }
            blipNode.Add(new XAttribute(XName.Get("cstate"), "print"));
            blipFillNode.Add(blipNode);

            XElement stretchNode = new XElement(XName.Get("stretch", ExcelCommon.Schema_Drawings),
                   new XElement(XName.Get("fillRect", ExcelCommon.Schema_Drawings)));
            blipFillNode.Add(stretchNode);
            picNode.Add(blipFillNode);
            #endregion

            #region "spPr"
            XElement spPrNode = new XElement(XName.Get("spPr", ExcelCommon.Schema_SheetDrawings),
                new XElement(XName.Get("xfrm", ExcelCommon.Schema_Drawings),
                    new XElement(XName.Get("off", ExcelCommon.Schema_Drawings),
                        new XAttribute("x", 0), new XAttribute("y", 0)),
                    new XElement(XName.Get("ext", ExcelCommon.Schema_Drawings),
                        new XAttribute("cx", 0), new XAttribute("cy", 0))),
                new XElement(XName.Get("prstGeom", ExcelCommon.Schema_Drawings),
                    new XAttribute("prst", "rect"),
                    new XElement(XName.Get("avLst", ExcelCommon.Schema_Drawings))));
            if (pic._Fill != null)
                WriteWrokSheetDrawing_pic_solidFill(pic._Fill, spPrNode);

            if (pic._Border != null)
                WriteWrokSheetDrawing_pic_ln(pic._Border, spPrNode);

            picNode.Add(spPrNode);
            #endregion

            return picNode;
        }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:65,代码来源:ExcelWriter.cs

示例6: CreateChartPackage

        private string CreateChartPackage(ExcelChart excelchart, PackagePart wrokSheetDrawingPart, Uri drawingUri)
        {
            Uri uriChart = this.Context.Package.GetNewUri("/xl/charts/chart{0}.xml");
            PackageRelationship chartRelation = wrokSheetDrawingPart.CreateRelationship(PackUriHelper.GetRelativeUri(drawingUri, uriChart), TargetMode.Internal, ExcelCommon.Schema_Relationships + "/chart");
            PackagePart chartPackagePart = this.Context.Package.CreatePart(uriChart, ExcelCommon.ContentType_sheetChart, CompressionOption.NotCompressed);

            XDocument chartDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
            WriteWrokSheetChart(excelchart, chartDoc);
            using (Stream chartStream = chartPackagePart.GetStream(FileMode.Create, FileAccess.Write))
            {
                chartDoc.Save(chartStream);
                chartStream.Flush();
            }
            return chartRelation.Id;
        }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:15,代码来源:ExcelWriter.cs

示例7: CreateImagePart

        private void CreateImagePart(PackagePart sourcePart, BitmapSource imageSource, string imageContentType, int imageIndex)
        {
            // Generate a new unique image part name
            string imagePartUriString = GetImageName(imageIndex, imageContentType);

            // Define an image part uri
            Uri imagePartUri = new Uri(XamlPayloadDirectory + imagePartUriString, UriKind.Relative);

            // Create a part for the image
            PackagePart imagePart = _package.CreatePart(imagePartUri, imageContentType, CompressionOption.NotCompressed);

            // Create the relationship referring from the enrty part to the image part
            PackageRelationship componentRelationship = sourcePart.CreateRelationship(imagePartUri, TargetMode.Internal, XamlRelationshipFromXamlPartToComponentPart);

            // Encode the image data
            BitmapEncoder bitmapEncoder = GetBitmapEncoder(imageContentType);
            bitmapEncoder.Frames.Add(BitmapFrame.Create(imageSource));

            // Save encoded image data into the image part in the package
            Stream imageStream = imagePart.GetStream();
            using (imageStream)
            {
                bitmapEncoder.Save(imageStream);
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:25,代码来源:WpfPayload.cs

示例8: StmCreatePart

        /* S T M  C R E A T E  P A R T */
        /*----------------------------------------------------------------------------
            %%Function: StmCreatePart
            %%Qualified: ArbWeb.OOXML.StmCreatePart
            %%Contact: rlittle

        ----------------------------------------------------------------------------*/
        public static Stream StmCreatePart(Package pkg, string sUri, string sContentType, out PackagePart prt)
        {
            Uri uriTeams = new System.Uri(sUri, UriKind.Relative);

            prt = pkg.GetPart(uriTeams);

            List<PackageRelationship> plrel = new List<PackageRelationship>();

            foreach (PackageRelationship rel in prt.GetRelationships())
                {
                plrel.Add(rel);
                }

            prt = null;

            pkg.DeletePart(uriTeams);
            prt = pkg.CreatePart(uriTeams, sContentType);

            foreach (PackageRelationship rel in plrel)
                {
                prt.CreateRelationship(rel.TargetUri, rel.TargetMode, rel.RelationshipType, rel.Id);
                }

            return prt.GetStream(FileMode.Create, FileAccess.Write);
        }
开发者ID:rlittletht,项目名称:ArbWeb,代码行数:32,代码来源:ooxml.cs


注:本文中的System.IO.Packaging.PackagePart.CreateRelationship方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。