Beispiel #1
0
        /// <summary>
        /// Add hyperlink
        /// </summary>
        /// <param name="hyperlink"></param>
        /// <returns></returns>
        private string AddHyperlink(Hyperlink hyperlink)
        {
            string        styleTemplate    = "<span style='STYLE_CONTENT'>HYPERLINK_CONTENT</span>";
            string        style            = "";
            List <string> cssStyleElements = new List <string>();

            HyperlinkRelationship relation = (from rel in document.MainDocumentPart.HyperlinkRelationships
                                              where rel.Id == hyperlink.Id
                                              select rel).FirstOrDefault() as HyperlinkRelationship;

            if (relation != null)
            {
                string result = "<a href=\"" + relation.Uri.ToString() + "\">" + hyperlink.Descendants <Run>().Select(x => x.InnerText).Aggregate((i, j) => i + j) + "</a>";

                FontSize fontSize = hyperlink.Descendants <FontSize>().FirstOrDefault();

                if (fontSize != null)
                {
                    cssStyleElements.Add(string.Format("font-size:{0}pt", Convert.ToInt32(fontSize.Val.Value) / 2));
                }

                foreach (string element in cssStyleElements)
                {
                    style += element + " ";
                }

                result = styleTemplate.Replace("HYPERLINK_CONTENT", result).Replace("STYLE_CONTENT", style);

                Italic italic = hyperlink.Descendants <Italic>().FirstOrDefault();

                if (italic != null)
                {
                    result = AddFormat(result, "i");
                }

                return(result);
            }
            else
            {
                return("");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add hyperlink
        /// </summary>
        /// <param name="hyperlink"></param>
        /// <returns></returns>
        private string AddHyperlink(Hyperlink hyperlink)
        {
            string styleTemplate = "<span style='STYLE_CONTENT'>HYPERLINK_CONTENT</span>";
            string style = "";
            List<string> cssStyleElements = new List<string>();

            HyperlinkRelationship relation = (from rel in document.MainDocumentPart.HyperlinkRelationships
                                              where rel.Id == hyperlink.Id
                                              select rel).FirstOrDefault() as HyperlinkRelationship;
            if (relation != null)
            {
                string result = "<a href=\"" + relation.Uri.ToString() + "\">" + hyperlink.Descendants<Run>().Select(x => x.InnerText).Aggregate((i, j) => i + j) + "</a>";

                FontSize fontSize = hyperlink.Descendants<FontSize>().FirstOrDefault();

                if (fontSize != null)
                    cssStyleElements.Add(string.Format("font-size:{0}pt", Convert.ToInt32(fontSize.Val.Value) / 2));

                foreach (string element in cssStyleElements)
                    style += element + " ";

                result = styleTemplate.Replace("HYPERLINK_CONTENT", result).Replace("STYLE_CONTENT", style);

                Italic italic = hyperlink.Descendants<Italic>().FirstOrDefault();

                if (italic != null)
                    result = AddFormat(result, "i");

                return result;
            }
            else
                return "";
        }