12
12
using System . Linq ;
13
13
using OfficeOpenXml . Utils ;
14
14
using System . Net ;
15
+ using OfficeOpenXml . FormulaParsing . Ranges ;
15
16
16
17
namespace OfficeOpenXml . FormulaParsing . LexicalAnalysis
17
18
{
@@ -833,6 +834,36 @@ internal ulong GetTopLeftCellId()
833
834
return ExcelCellBase . GetCellId ( WorksheetIx , FromRow , FromCol ) ;
834
835
}
835
836
837
+ internal IRangeInfo GetAsRangeInfo ( )
838
+ {
839
+ if ( ExternalReferenceIx > 0 )
840
+ {
841
+ return GetAsExternalRangeInfo ( ) ;
842
+ }
843
+ else
844
+ {
845
+ return new RangeInfo ( this ) ;
846
+ }
847
+ }
848
+
849
+ internal IRangeInfo GetAsExternalRangeInfo ( )
850
+ {
851
+ var wb = _context . GetExternalWoorkbook ( ExternalReferenceIx ) ;
852
+ if ( wb == null )
853
+ {
854
+ return new RangeInfo ( null , - 1 , - 1 , - 1 , - 1 , _context , ExternalReferenceIx ) ;
855
+ }
856
+ else if ( wb . Package == null )
857
+ {
858
+ return new EpplusExcelExternalRangeInfo ( wb , this , _context ) ;
859
+ }
860
+ else
861
+ {
862
+ var ws = wb . Package . Workbook . GetWorksheetByIndexInList ( WorksheetIx ) ;
863
+ return new RangeInfo ( ws , FromRow , FromCol , ToRow , ToCol , _context ) ;
864
+ }
865
+ }
866
+
836
867
public FormulaRangeAddress Address => this ;
837
868
}
838
869
public class FormulaTableAddress : FormulaRangeAddress
@@ -904,11 +935,6 @@ internal void SetTableAddress(ExcelPackage package)
904
935
{
905
936
FixedFlag = FixedFlag . All ;
906
937
907
- FromRow = table . ShowHeader ? table . Address . _fromRow + 1 : table . Address . _fromRow ;
908
- ToRow = table . ShowTotal ? table . Address . _toRow - 1 : table . Address . _toRow ;
909
- FromCol = table . Address . _fromCol ;
910
- ToCol = table . Address . _toCol ;
911
-
912
938
if ( string . IsNullOrEmpty ( TablePart1 ) == false )
913
939
{
914
940
SetRowFromTablePart ( TablePart1 , table , ref FromRow , ref ToRow , ref FixedFlag ) ;
@@ -917,6 +943,11 @@ internal void SetTableAddress(ExcelPackage package)
917
943
SetRowFromTablePart ( TablePart2 , table , ref FromRow , ref ToRow , ref FixedFlag ) ;
918
944
}
919
945
}
946
+ else
947
+ {
948
+ FromRow = table . ShowHeader ? table . Address . _fromRow + 1 : table . Address . _fromRow ;
949
+ ToRow = table . ShowTotal ? table . Address . _toRow - 1 : table . Address . _toRow ;
950
+ }
920
951
921
952
if ( string . IsNullOrEmpty ( ColumnName1 ) == false )
922
953
{
@@ -926,6 +957,11 @@ internal void SetTableAddress(ExcelPackage package)
926
957
SetColFromTablePart ( ColumnName2 , table , ref FromCol , ref ToCol , true ) ;
927
958
}
928
959
}
960
+ else
961
+ {
962
+ FromCol = table . Address . _fromCol ;
963
+ ToCol = table . Address . _toCol ;
964
+ }
929
965
}
930
966
}
931
967
private void SetColFromTablePart ( string value , ExcelTable table , ref int fromCol , ref int toCol , bool lastColon )
0 commit comments