Ejemplo n.º 1
0
        /// <summary>
        /// Чистый класс, добавление числителя и знаменателя осуществляется через XMLNumerator, XMLDenominator
        /// </summary>
        public OXMLMathFractionWrap()
        {
            XMLFraction = new M.Fraction();

            XMLNumerator = new M.Numerator();
            XMLDenominator = new M.Denominator();

            XMLFraction.Append(OXMLMathControlPropertiesWrap.DefaultFractionProperties());
            XMLFraction.Append(XMLNumerator);
            XMLFraction.Append(XMLDenominator);
        }
        //.....................................................................
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private OpxM.Denominator mathDenom_2_A( )
        {
            OpxM.Denominator denominator1 = new OpxM.Denominator( );

            OpxM.Run run10 = mathNumP002( );
            OpxM.Run run11 = mathA( );

            denominator1.Append(OpenDocxMathExprs.MakeMathRun("2a"));
            denominator1.Append(run11);

            return(denominator1);
        }
        //.....................................................................
        /// <summary>
        /// 使用常规的字符串生成一个分式(标准的、上下格式)
        /// </summary>
        /// <param name="upper"></param>
        /// <param name="lower"></param>
        /// <returns></returns>
        public static M.Fraction MakeFraction(string upper, string lower)
        {
            M.Fraction fraction = new M.Fraction( );

            M.Numerator upperNUM = new M.Numerator( );
            upperNUM.Append(OpenDocxMathExprs.MakeMathRun(upper));

            M.Denominator lowerDEN = new M.Denominator( );
            lowerDEN.Append(OpenDocxMathExprs.MakeMathRun(lower));

            fraction.Append(OpenDocxMathExprs.MakeFractionProperties( ));
            fraction.Append(upperNUM);
            fraction.Append(lowerDEN);

            return(fraction);
        }
        //.....................................................................
        /// <summary>
        ///
        /// </summary>
        /// <param name="upper"></param>
        /// <param name="lower"></param>
        /// <returns></returns>
        public static M.Fraction MakeFraction(OpenXmlElement upper, OpenXmlElement lower)
        {
            M.Fraction fraction = new M.Fraction( );

            M.Numerator upperNUM = new M.Numerator( );
            upperNUM.Append(upper);

            M.Denominator lowerDEN = new M.Denominator( );
            lowerDEN.Append(lower);

            fraction.Append(OpenDocxMathExprs.MakeFractionProperties( ));
            fraction.Append(upperNUM);
            fraction.Append(lowerDEN);

            return(fraction);
        }
        ///// <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);
        }