Example #1
0
        //.....................................................................
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private Paragraph MakeP2( )
        {
            Paragraph paragraph3 = new Paragraph( )
            {
                RsidParagraphMarkRevision = "00985895", RsidParagraphAddition = "00985895", RsidRunAdditionDefault = "00985895"
            };

            M.Paragraph paragraph4 = new M.Paragraph( );

            M.OfficeMath officeMath2 = new M.OfficeMath( );

            M.Run run3 = OpenDocxMathExprs.MakeMathRun("y=2+1");   // new M.Run( );

            officeMath2.Append(run3);

            M.Justification justification = new M.Justification( )
            {
                Val = M.JustificationValues.Left
            };

            M.ParagraphProperties paraProperties = new M.ParagraphProperties( );
            paraProperties.Append(justification);

            paragraph4.Append(paraProperties);
            paragraph4.Append(officeMath2);

            paragraph3.Append(paragraph4);

            return(paragraph3);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private Paragraph MakeP1( )
        {
            Paragraph paragraphNORM = new Paragraph( )
            {
                RsidParagraphMarkRevision = "00985895", RsidParagraphAddition = "00337477", RsidRunAdditionDefault = "00985895"
            };

            M.Justification justification = new M.Justification( )
            {
                Val = M.JustificationValues.Right
            };

            M.ParagraphProperties paraProperties = new M.ParagraphProperties( );
            paraProperties.Append(justification);

            M.Paragraph paragraphMATH = new M.Paragraph( );

            M.OfficeMath paraMathLine = new M.OfficeMath( );

            M.Run run1 = OpenDocxMathExprs.MakeMathRun("x=1+2/3=1.6667");   // new M.Run( );

            paraMathLine.Append(run1);

            paragraphMATH.Append(paraMathLine);
            paragraphMATH.Append(paraProperties);

            paragraphNORM.Append(paragraphMATH);

            return(paragraphNORM);
        }
Example #3
0
        public OXMLMath(string sFormula)
        {
            _formula = sFormula;

            XMLMathParagraph = new M.Paragraph();
            XMLMathOffice = new M.OfficeMath();

            StrParse(sFormula, XMLMathOffice);
            XMLMathParagraph.Append(XMLMathOffice);
        }
Example #4
0
        public TokenTree build(OfficeMath expression)
        {
            foundIdentifiers.Clear();

            TokenList rootTokens = new TokenList();

            foreach (OpenXmlElement element in expression.ChildElements)
            {
                IToken processedElement = processElement(element);
                rootTokens.Append(processedElement);
            }

            return(new TokenTree(rootTokens, foundIdentifiers));
        }
Example #5
0
        private Paragraph MakeP3( )
        {
            Paragraph paragraph3 = new Paragraph( )
            {
                RsidParagraphMarkRevision = "00985895", RsidParagraphAddition = "00985895", RsidRunAdditionDefault = "00985895"
            };

            M.Paragraph paragraph4 = new M.Paragraph( );

            M.OfficeMath officeMath2 = new M.OfficeMath( );

            M.Run run3 = OpenDocxMathExprs.MakeMathRun("z=x+y=2.667");

            officeMath2.Append(run3);

            paragraph4.Append(officeMath2);

            paragraph3.Append(paragraph4);

            return(paragraph3);
        }
        //.....................................................................
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override Document GenerateDocument()
        {
            Document document1 = new Document()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "w14 wp14"
                }
            };

            document1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            document1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            document1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            document1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            document1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            document1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            document1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            document1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            document1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            document1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            document1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            document1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            document1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            Body body1 = new Body();

            Paragraph paragraph1 = new Paragraph()
            {
                RsidParagraphMarkRevision = "00814392", RsidParagraphAddition = "00666F86", RsidRunAdditionDefault = "00814392"
            };

            //---------------------------------------------
            M.Paragraph paragraph2 = new M.Paragraph();

            M.OfficeMath officeMath1 = new M.OfficeMath();

            //---------------------------------------------
            M.Radical mathpart1 = OpenDocxMathExprs.MakeMathRadical("x", "2");

            M.Run mathpart2 = OpenDocxMathExprs.MakeMathRun("+");

            M.Radical mathpart3 = OpenDocxMathExprs.MakeMathRadical("y", "4");

            M.Run mathpart4 = OpenDocxMathExprs.MakeMathRun("=w");

            //---------------------------------------------
            officeMath1.Append(mathpart1);
            officeMath1.Append(mathpart2);
            officeMath1.Append(mathpart3);
            officeMath1.Append(mathpart4);

            paragraph2.Append(officeMath1);

            paragraph1.Append(paragraph2);

            //---------------------------------------------
            Paragraph paragraph3 = new Paragraph()
            {
                RsidParagraphMarkRevision = "00814392", RsidParagraphAddition = "00814392", RsidRunAdditionDefault = "00814392"
            };

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();

            ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
            RunFonts runFonts9 = new RunFonts()
            {
                Hint = FontTypeHintValues.EastAsia
            };

            paragraphMarkRunProperties1.Append(runFonts9);

            paragraphProperties1.Append(paragraphMarkRunProperties1);
            BookmarkStart bookmarkStart1 = new BookmarkStart()
            {
                Name = "_GoBack", Id = "0"
            };
            BookmarkEnd bookmarkEnd1 = new BookmarkEnd()
            {
                Id = "0"
            };

            paragraph3.Append(paragraphProperties1);
            paragraph3.Append(bookmarkStart1);
            paragraph3.Append(bookmarkEnd1);

            SectionProperties sectionProperties1 = new SectionProperties()
            {
                RsidRPr = "00814392", RsidR = "00814392"
            };
            PageSize pageSize1 = new PageSize()
            {
                Width = (UInt32Value)11906U, Height = (UInt32Value)16838U
            };
            PageMargin pageMargin1 = new PageMargin()
            {
                Top = 1440, Right = (UInt32Value)1800U, Bottom = 1440, Left = (UInt32Value)1800U, Header = (UInt32Value)851U, Footer = (UInt32Value)992U, Gutter = (UInt32Value)0U
            };
            Columns columns1 = new Columns()
            {
                Space = "425"
            };
            DocGrid docGrid1 = new DocGrid()
            {
                Type = DocGridValues.Lines, LinePitch = 312
            };

            sectionProperties1.Append(pageSize1);
            sectionProperties1.Append(pageMargin1);
            sectionProperties1.Append(columns1);
            sectionProperties1.Append(docGrid1);

            body1.Append(paragraph1);
            body1.Append(paragraph3);
            body1.Append(sectionProperties1);

            document1.Append(body1);

            return(document1);
        }
        ///// <summary>
        /////
        ///// </summary>
        //private string NamePath = "d:\\123-test-openxml";

        ///// <summary>
        /////
        ///// </summary>
        //private string NameXlsx = "easy-table.docx";

        ////.....................................................................
        ///// <summary>
        /////
        ///// </summary>
        //public void MakeWord( )
        //{
        //    string docxfile = this.NamePath + "\\" + this.NameXlsx;

        //    // Creates the new instance of the WordprocessingDocument class from the specified file
        //    // WordprocessingDocument.Open(String, Boolean) method
        //    // Parameters:
        //    // string docxfile - docxfile is a string which contains the docxfile of the wordocument
        //    // bool isEditable

        //    using ( WordprocessingDocument wordocument = WordprocessingDocument.Create( docxfile, WordprocessingDocumentType.Document ) )
        //    {
        //        // Defines the MainDocumentPart
        //        MainDocumentPart mainDocxPart = wordocument.AddMainDocumentPart( );

        //        mainDocxPart.Document = this.GenerateDocument( );

        //        //mainDocxPart.Document = new Document( );
        //        //Body docxbody = mainDocxPart.Document.AppendChild( new Body( ) );
        //        //// Create a new table
        //        //Table docxtable = new Table( );
        //        //// Add the table to the docxbody
        //        //docxbody.AppendChild( docxtable );

        //        mainDocxPart.Document.Save( );
        //    }

        //    return;
        //}

        //.....................................................................
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override Document GenerateDocument( )
        {
            Document document1 = new Document( )
            {
                MCAttributes = new MarkupCompatibilityAttributes( )
                {
                    Ignorable = "w14 wp14"
                }
            };

            document1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            document1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            document1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            document1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            document1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            document1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            document1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            document1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            document1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            document1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            document1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            document1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            document1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            Body docxBody = new Body( );

            Paragraph normParagraph = new Paragraph( )
            {
                RsidParagraphAddition = "0037253E", RsidRunAdditionDefault = "0078119C"
            };

            //---------------------------------------------
            OpxM.Paragraph mathParagraph = new OpxM.Paragraph( );

            OpxM.OfficeMath mathOffice = new OpxM.OfficeMath( );

            //---------------------------------------------
            OpxM.Run run1 = mathX( );
            OpxM.Run run2 = mathEQ( );

            mathOffice.Append(run1);
            mathOffice.Append(run2);

            //---------------------------------------------
            OpxM.Fraction fraction1 = new OpxM.Fraction( );

            OpxM.FractionProperties fractionProperties1 = MakeFractionProperties( );

            OpxM.Numerator numerator1 = mathNumer_B_B2_4AC( );

            OpxM.Denominator denominator1 = mathDenom_2_A( );

            fraction1.Append(fractionProperties1);
            fraction1.Append(numerator1);
            fraction1.Append(denominator1);

            mathOffice.Append(fraction1);

            //---------------------------------------------
            mathParagraph.Append(mathOffice);

            //---------------------------------------------
            //BookmarkStart bookmarkStart1 = new BookmarkStart( ) { Name = "_GoBack", Id = "0" };
            //BookmarkEnd bookmarkEnd1 = new BookmarkEnd( ) { Id = "0" };

            normParagraph.Append(mathParagraph);

            //normParagraph.Append( bookmarkStart1 );
            //normParagraph.Append( bookmarkEnd1 );

            SectionProperties sectionProperties1 = new SectionProperties( )
            {
                RsidR = "0037253E"
            };

            PageSize pageSize1 = new PageSize( )
            {
                Width = ( UInt32Value )11906U, Height = ( UInt32Value )16838U
            };

            PageMargin pageMargin1 = new PageMargin( )
            {
                Top = 1440, Right = ( UInt32Value )1800U, Bottom = 1440, Left = ( UInt32Value )1800U, Header = ( UInt32Value )851U, Footer = ( UInt32Value )992U, Gutter = ( UInt32Value )0U
            };

            Columns columns1 = new Columns( )
            {
                Space = "425"
            };

            DocGrid docGrid1 = new DocGrid( )
            {
                Type = DocGridValues.Lines, LinePitch = 312
            };

            sectionProperties1.Append(pageSize1);
            sectionProperties1.Append(pageMargin1);
            sectionProperties1.Append(columns1);
            sectionProperties1.Append(docGrid1);

            docxBody.Append(normParagraph);
            docxBody.Append(sectionProperties1);

            document1.Append(docxBody);

            return(document1);
        }
Example #8
0
        private static Table genTable(List <CalcValueBase> calcVals)
        {
            Table tableOfInputs = new Table();
            var   tableGrid     = new TableGrid();

            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableGrid.AppendChild(new GridColumn());
            tableOfInputs.AppendChild(tableGrid);
            var tableProps = new TableProperties();

            tableProps.AppendChild(new TableLayout()
            {
                Type = TableLayoutValues.Fixed
            });
            tableProps.AppendChild(new TableWidth()
            {
                Width = "9000", Type = TableWidthUnitValues.Dxa
            });
            tableProps.AppendChild(new TableBorders()
            {
                InsideHorizontalBorder = new InsideHorizontalBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                BottomBorder = new BottomBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            tableProps.AppendChild(new TableBorders()
            {
                TopBorder = new TopBorder()
                {
                    Color = "c0c0c0", Size = 4, Val = BorderValues.Single
                }
            });
            //tableProps.AppendChild(new TableBorders() { LeftBorder = new LeftBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { InsideVerticalBorder = new InsideVerticalBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });
            //tableProps.AppendChild(new TableBorders() { RightBorder = new RightBorder() { Color = "c0c0c0", Size = 4, Val = BorderValues.Single } });

            tableOfInputs.AppendChild(tableProps);

            foreach (var item in calcVals)
            {
                TableRow row    = new TableRow();
                var      para1  = new Paragraph();
                var      myMath = new M.OfficeMath(new M.Run(new M.Text(item.Symbol)
                {
                    Space = SpaceProcessingModeValues.Preserve
                }));
                para1.AppendChild(myMath);
                para1.AppendChild(new Run(new Text(" ")
                {
                    Space = SpaceProcessingModeValues.Preserve
                }));
                TableCell cell1 = new TableCell();
                cell1.Append(para1);
                cell1.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1200"
                }));
                var       para2 = new Paragraph(new Run(new Text(item.Name)));
                TableCell cell2 = new TableCell();
                cell2.AppendChild(para2);
                cell2.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "6100"
                }));
                var para3 = new Paragraph();
                if (item.Type == CalcValueType.DOUBLE)
                {
                    myMath = new M.OfficeMath(new M.Run(new M.Text(item.ValueAsString + item.Unit)
                    {
                        Space = SpaceProcessingModeValues.Preserve
                    }));
                    para3.AppendChild(myMath);
                    para3.AppendChild(new Run(new Text(" ")
                    {
                        Space = SpaceProcessingModeValues.Preserve
                    }));
                }
                else if (item.Type == CalcValueType.SELECTIONLIST)
                {
                    para3.AppendChild(new Run(new Text(item.ValueAsString)));
                }
                else
                {
                    cell2.AppendChild(new Paragraph(new Run(new Text(item.ValueAsString))));
                }
                TableCell cell3 = new TableCell();
                cell3.Append(para3);
                cell3.Append(new TableCellProperties(new TableCellWidth()
                {
                    Type = TableWidthUnitValues.Dxa, Width = "1700"
                }));
                row.Append(cell1, cell2, cell3);
                tableOfInputs.AppendChild(row);
            }
            return(tableOfInputs);
        }