Exemplo n.º 1
0
        /// <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("");
        }
Exemplo n.º 2
0
        public ShapeInfo(Shape shape)
        {
            string strStyle = shape.Style.Value;

            ParseStyle(strStyle);
            Text = shape.InnerText;
            Name = shape.Id.Value;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create object for grouped image in Word
        /// </summary>
        public ImageUsageInfo(OpenXmlPart part, DocumentFormat.OpenXml.Vml.Shape shape)
        {
            Part = part;

            var imageData = shape?.Descendants <DocumentFormat.OpenXml.Vml.ImageData>().FirstOrDefault();

            RelId = imageData?.RelationshipId;

            var attributes = new Dictionary <string, string>();
            var enumerable =
                shape?.Style?.Value?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)?.ToList();

            if (enumerable != null)
            {
                foreach (var pair in enumerable)
                {
                    var split = pair.Split(':');
                    if (attributes.ContainsKey(split[0]))
                    {
                        attributes[split[0]] = split[1];
                    }
                    else
                    {
                        attributes.Add(split[0], split[1]);
                    }
                }
            }


            if (imageData == null ||
                //attributes == null ||
                !attributes.ContainsKey("height") ||
                !attributes.ContainsKey("width"))
            {
                return;
            }

            Size = new Size
            {
                Width  = (int)Converters.SmthToEmu(attributes["width"]),
                Height = (int)Converters.SmthToEmu(attributes["height"])
            };

            Crop = ParseCrop(imageData);
        }
Exemplo n.º 4
0
        public void FillTableCell(int tableIndex, int colIndex, int rowIndex, TextBoxProps tbp)
        {
            Table table = doc.MainDocumentPart.Document.Body.Elements <Table>().ElementAt(tableIndex);

            // Find the second row in the table.
            TableRow row = table.Elements <TableRow>().ElementAt(rowIndex);

            // Find the third cell in the row.
            TableCell cell = row.Elements <TableCell>().ElementAt(colIndex);

            // Find the first paragraph in the table cell.
            Paragraph p = cell.Elements <Paragraph>().First();

            Picture pict = new Picture();

            DocumentFormat.OpenXml.Vml.Shape s = new DocumentFormat.OpenXml.Vml.Shape()
            {
                Style = "position:absolute;top:" + (tbp.y * 3.79).ToString() + ";left:" + (tbp.x * 4).ToString() + ";width:" + (tbp.width * 3.79).ToString() + ";height:" + (tbp.height * 3.79).ToString() + ";margin-left:0pt;margin-top:0pt;rotation:0;v-rotate-letters:true;mso-rotate:90", Filled = false, Stroked = false
            };
            //DocumentFormat.OpenXml.Vml.Shapetype st = new DocumentFormat.OpenXml.Vml.Shapetype();
            //st.

            DocumentFormat.OpenXml.Vml.TextBox tb = new DocumentFormat.OpenXml.Vml.TextBox()
            {
                Inset = "0,0,0,0"
            };
            Paragraph           par = new Paragraph();
            ParagraphProperties paragraphProperties = new ParagraphProperties();
            SpacingBetweenLines spacing             = new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            };

            paragraphProperties.Append(spacing);
            paragraphProperties.Append(new ParagraphStyleId()
            {
                Val = "No Spacing"
            });
            par.Append(paragraphProperties);
            Run           r   = new Run();
            RunProperties rPr = new RunProperties(new RunFonts()
            {
                HighAnsi = tbp.font.Name, Ascii = tbp.font.Name, ComplexScript = tbp.font.Name
            }, new FontSize()
            {
                Val = ((int)(tbp.font.Size * 2)).ToString()
            }, new DocumentFormat.OpenXml.Wordprocessing.Color()
            {
                Val = tbp.color.R.ToString("X2") + tbp.color.G.ToString("X2") + tbp.color.B.ToString("X2")
            });                                                                                                                                                                                                                                                                                                                                                           // fontsize in half-points

            r.PrependChild <RunProperties>(rPr);
            r.Append(new Text(tbp.text));
            par.Append(r);
            TextBoxContent tbc = new TextBoxContent();

            tbc.Append(par);
            tb.Append(tbc);
            s.Append(tb);
            pict.Append(s);
            p.Append(new Run(pict));


            // Set the text for the run.
            //Text t = r.Elements<Text>().First();
            //t.Text = txt;
        }