@@ -85,6 +85,8 @@ private static void Generate(this OpenXmlElement xmlElement, WordprocessingDocum
8585 dic . Add ( dicKey , e . Value ) ;
8686 }
8787
88+ ReplaceStatements ( newTr , tags : dic ) ;
89+
8890 ReplaceText ( newTr , docx , tags : dic ) ;
8991 table . Append ( newTr ) ;
9092 }
@@ -95,6 +97,8 @@ private static void Generate(this OpenXmlElement xmlElement, WordprocessingDocum
9597 }
9698 }
9799
100+ ReplaceStatements ( xmlElement , tags ) ;
101+
98102 ReplaceText ( xmlElement , docx , tags ) ;
99103 }
100104
@@ -490,6 +494,35 @@ private static void ReplaceText(OpenXmlElement xmlElement, WordprocessingDocumen
490494 }
491495 }
492496 }
497+
498+ private static void ReplaceStatements ( OpenXmlElement xmlElement , Dictionary < string , object > tags )
499+ {
500+ var paragraphs = xmlElement . Descendants < Paragraph > ( ) . ToList ( ) ;
501+
502+ while ( paragraphs . Any ( s => s . InnerText . Contains ( "@if" ) ) )
503+ {
504+ var ifIndex = paragraphs . FindIndex ( 0 , s => s . InnerText . Contains ( "@if" ) ) ;
505+ var endIfFinalIndex = paragraphs . FindIndex ( ifIndex , s => s . InnerText . Contains ( "@endif" ) ) ;
506+
507+ var statement = paragraphs [ ifIndex ] . InnerText . Split ( ' ' ) ;
508+
509+ var tagValue = tags [ statement [ 1 ] ] ;
510+ var checkStatement = statement . Length == 4 ? EvaluateStatement ( tagValue . ToString ( ) , statement [ 2 ] , statement [ 3 ] ) : ! bool . Parse ( tagValue . ToString ( ) ) ;
511+
512+ if ( ! checkStatement )
513+ {
514+ for ( int i = ifIndex + 1 ; i <= endIfFinalIndex - 1 ; i ++ )
515+ {
516+ paragraphs [ i ] . Remove ( ) ;
517+ }
518+ }
519+
520+ paragraphs [ ifIndex ] . Remove ( ) ;
521+ paragraphs [ endIfFinalIndex ] . Remove ( ) ;
522+
523+ paragraphs = xmlElement . Descendants < Paragraph > ( ) . ToList ( ) ;
524+ }
525+ }
493526
494527 private static string EvaluateIfStatement ( string text )
495528 {
0 commit comments