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


C# DocumentFormat.GetAttributes方法代码示例

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


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

示例1: DrawRoundRectangle

        /// <summary>
        /// Draw round rectangle
        /// </summary>
        /// <param name="roundRectangle"></param>
        /// <returns></returns>
        private string DrawRoundRectangle(DocumentFormat.OpenXml.Vml.RoundRectangle roundRectangle)
        {
            string fileName = Path.Combine(imageDirectory, roundRectangle.GetAttributes().Where(x => x.LocalName == "id").FirstOrDefault().Value + ".jpg");
            string style = roundRectangle.GetAttributes().Where(x => x.LocalName == "style").FirstOrDefault().Value;
            string position = GetValueOfProperty("position", style);
            int marginLeft = ConvertPointToPixel(GetValueOfProperty("margin-left", style));
            int marginTop = ConvertPointToPixel(GetValueOfProperty("margin-top", style));
            int width = ConvertPointToPixel(GetValueOfProperty("width", style));
            int height = ConvertPointToPixel(GetValueOfProperty("height", style));

            System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height);

            using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(newBmp))
            {
                System.Drawing.Pen pen = new System.Drawing.Pen(ConvertToColor(roundRectangle.StrokeColor.Value), ConvertPointToPixel(roundRectangle.StrokeWeight.Value));
                pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                System.Drawing.SolidBrush solidBrush = new System.Drawing.SolidBrush(ConvertToColor(roundRectangle.FillColor.Value));
                System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(0, 0, width, height);
                graphic.FillRectangle(solidBrush, rectangle);
                graphic.DrawRectangle(pen, rectangle);
            }
            newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

            return string.Format("<span style='position:{0};margin-left:{1}px;margin-top:{2}px;width:{3}px;height:{4}px'><img width=\"{3}\" height=\"{4}\" alt=\"{5}\" src=\"{6}\"/>", 
                position, marginLeft, marginTop, width, height, Path.GetFileName(fileName), Util.GetRelativePath(fileName));
        }
开发者ID:nkravch,项目名称:SALMA-2.0,代码行数:31,代码来源:DocxToHtml.cs

示例2: DrawLine

        /// <summary>
        /// Draw line
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        private string DrawLine(DocumentFormat.OpenXml.Vml.Line line)
        {
            string fileName = Path.Combine(imageDirectory, line.GetAttributes().Where(x => x.LocalName == "id").FirstOrDefault().Value + ".jpg");
            string style = line.GetAttributes().Where(x => x.LocalName == "style").FirstOrDefault().Value;
            string position = GetValueOfProperty("position", style);
            int marginLeft = ConvertPointToPixel(GetValueOfProperty("margin-left", style));
            int marginTop = ConvertPointToPixel(GetValueOfProperty("margin-top", style));
            int width = (int)(ConvertToPixel(line.To.Value.Split(",".ToCharArray())[0]) - ConvertToPixel(line.From.Value.Split(",".ToCharArray())[0]));
            int height = (int)(ConvertToPixel(line.To.Value.Split(",".ToCharArray())[1]) - ConvertToPixel(line.From.Value.Split(",".ToCharArray())[1]));
            string strokeWeight = line.StrokeWeight != null ? line.StrokeWeight.Value : "3pt";

            if (height == 0)
                height = ConvertPointToPixel(strokeWeight);

            System.Drawing.Bitmap newBmp = new System.Drawing.Bitmap(width, height);

            using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(newBmp))
            {
                System.Drawing.Pen pen = new System.Drawing.Pen(ConvertToColor(line.StrokeColor != null ? line.StrokeColor.Value : "black"), height);
                graphic.DrawLine(pen, 0, 0, newBmp.Width, newBmp.Height);
            }

            newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);

            return string.Format("<span style='position:{0};margin-left:{1}px;margin-top:{2}px;width:{3}px;height:{4}px'><img width=\"{3}\" height=\"{4}\" alt=\"{5}\" src=\"{6}\"/></span>", 
                position, marginLeft, marginTop, width, height, Path.GetFileName(fileName), Util.GetRelativePath(fileName)); 
        }
开发者ID:nkravch,项目名称:SALMA-2.0,代码行数:32,代码来源:DocxToHtml.cs

示例3: DrawShape

        /// <summary>
        /// Draw shape
        /// </summary>
        /// <param name="shape"></param>
        /// <returns></returns>
        private string DrawShape(DocumentFormat.OpenXml.Vml.Shape shape)
        {
            string style = shape.GetAttributes().Where(x => x.LocalName == "style").FirstOrDefault().Value;
            string position = GetValueOfProperty("position", style);

            string styleLeft = GetValueOfProperty("left", style);
            int marginLeft = ConvertToPixel(GetValueOfProperty("margin-left", style));
            int marginTop = ConvertToPixel(GetValueOfProperty("margin-top", style));
            int width = ConvertToPixel(GetValueOfProperty("width", style));
            int height = ConvertToPixel(GetValueOfProperty("height", style));
            string graphicName = shape.Id;

            foreach (OpenXmlElement element in shape.Elements())
                if (element is DocumentFormat.OpenXml.Vml.ImageData)
                    return DrawImageData(position, marginLeft, marginTop, width, height, (DocumentFormat.OpenXml.Vml.ImageData)element);
                else if (element is DocumentFormat.OpenXml.Vml.TextBox)
                    return AddTextBox((DocumentFormat.OpenXml.Vml.TextBox)element);

            return "";
        }
开发者ID:nkravch,项目名称:SALMA-2.0,代码行数:25,代码来源:DocxToHtml.cs


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