@@ -487,7 +487,6 @@ export class XlsxToJson {
487487 conditionCache . push ( condition ) ;
488488 }
489489 }
490-
491490 row = table . end . r + 1 ;
492491 const expressions : XlsxExpressions = new XlsxExpressions ( ) ;
493492 for ( ; row < range . e . r ; row ++ ) {
@@ -878,15 +877,13 @@ export class XlsxToJson {
878877 if ( worksheet . empty ( table . start . c , table . end . c , row ) ) {
879878 return null ;
880879 }
881- if ( worksheet . getRow ( row ) . getOutline ( ) ) {
882- return null ;
883- }
884880
885881 const key = XlsxToJson . getFieldKey ( worksheet , table , row , xlsxResult ) ;
886- const field = fields . find ( ( f ) => f . title === key . path ) ;
882+ const field = allFields . get ( key . path ) || fields . find ( ( f ) => f . title === key . path ) ;
883+ const targetPath = fieldPaths . get ( key . path ) ;
884+ const isNested = targetPath && targetPath . length > 1 ;
887885
888886 try {
889- //visibility
890887 if ( worksheet . outColumnRange ( table . getCol ( Dictionary . VISIBILITY ) ) ) {
891888 return ;
892889 }
@@ -922,41 +919,49 @@ export class XlsxToJson {
922919 }
923920
924921 if ( result . type === 'const' ) {
925- field . hidden = field . hidden || ! result . value ;
922+ if ( field ) { field . hidden = field . hidden || ! result . value ; }
926923 return ;
927924 }
928925
926+ const addToCondition = ( holder : XlsxSchemaConditions , invert : boolean ) => {
927+ if ( isNested && field ) {
928+ holder . addTarget ( field , targetPath , invert ) ;
929+ } else if ( field ) {
930+ holder . addField ( field , invert ) ;
931+ }
932+ } ;
933+
929934 if ( result . op && Array . isArray ( result . items ) ) {
930935 const resolved = result . items . map ( it => {
931- const target = allFields . get ( it . fieldPath ) || fields . find ( f => f . title === it . fieldPath ) ;
932- if ( ! target ) {
936+ const trigger = allFields . get ( it . fieldPath ) || fields . find ( f => f . title === it . fieldPath ) ;
937+ if ( ! trigger ) {
933938 throw new Error ( `Invalid target in ${ result . op } condition: ${ it . fieldPath } ` ) ;
934939 }
935- return { field : target , value : it . compareValue , fieldPath : fieldPaths . get ( it . fieldPath ) } ;
940+ return { field : trigger , value : it . compareValue , fieldPath : fieldPaths . get ( it . fieldPath ) } ;
936941 } ) ;
937942
938943 const conditionKey = { op : result . op , items : resolved } ;
939944 const existed = conditionCache . find ( c => ( c as any ) . equal ( conditionKey ) ) ;
940945 const holder = existed || new XlsxSchemaConditions ( conditionKey as any ) ;
941946
942- holder . addField ( field , ! ! result . invert ) ;
947+ addToCondition ( holder , ! ! result . invert ) ;
943948 if ( ! existed ) {
944949 return holder ;
945950 }
946951 return null ;
947952 } else {
948- const target = allFields . get ( result . fieldPath ) || fields . find ( ( f ) => f . title === result . fieldPath ) ;
949- if ( ! target ) {
950- throw new Error ( 'Invalid target ' ) ;
953+ const trigger = allFields . get ( result . fieldPath ) || fields . find ( ( f ) => f . title === result . fieldPath ) ;
954+ if ( ! trigger ) {
955+ throw new Error ( 'Invalid trigger field ' ) ;
951956 }
952- const fieldPath = fieldPaths . get ( result . fieldPath ) ;
953- const condition = conditionCache . find ( c => c . equal ( target , result . compareValue ) ) ;
957+ const triggerPath = fieldPaths . get ( result . fieldPath ) ;
958+ const condition = conditionCache . find ( c => c . equal ( trigger , result . compareValue ) ) ;
954959 if ( condition ) {
955- condition . addField ( field , result . invert ) ;
960+ addToCondition ( condition , result . invert ) ;
956961 return null ;
957962 } else {
958- const newCondition = new XlsxSchemaConditions ( target , result . compareValue , fieldPath ) ;
959- newCondition . addField ( field , result . invert ) ;
963+ const newCondition = new XlsxSchemaConditions ( trigger , result . compareValue , triggerPath ) ;
964+ addToCondition ( newCondition , result . invert ) ;
960965 return newCondition ;
961966 }
962967 }
@@ -1098,6 +1103,15 @@ export class XlsxToJson {
10981103 }
10991104 }
11001105
1106+ if ( ( node as any ) . type === 'AssignmentNode' ) {
1107+ const assign = node as any ;
1108+ const obj = assign . object ;
1109+ const val = assign . value ;
1110+ if ( obj ?. type === 'SymbolNode' && val ?. type === 'ConstantNode' ) {
1111+ return { type : 'formulae' , fieldPath : obj . name , compareValue : val . value , invert } ;
1112+ }
1113+ }
1114+
11011115 throw new Error ( `Failed to parse formulae: ${ formulae } .` ) ;
11021116 } ;
11031117
0 commit comments