File tree 2 files changed +41
-1
lines changed
tests/ClosedXML.Report.Tests
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -187,7 +187,10 @@ string EvalString(string str)
187
187
{
188
188
var rangeWithoutOptionsRow = growedRange . Worksheet
189
189
. Range ( growedRange . FirstCell ( ) , growedRange . LastCell ( ) . CellAbove ( ) ) ;
190
- rangeWithoutOptionsRow . Delete ( XLShiftDeletedCells . ShiftCellsUp ) ;
190
+ if ( growedRange . Worksheet . Tables . Any ( t => t . Contains ( rangeWithoutOptionsRow ) ) )
191
+ growedRange . Clear ( ) ;
192
+ else
193
+ rangeWithoutOptionsRow . Delete ( XLShiftDeletedCells . ShiftCellsUp ) ;
191
194
}
192
195
continue ;
193
196
}
Original file line number Diff line number Diff line change 1
1
using ClosedXML . Excel ;
2
2
using FluentAssertions ;
3
3
using System . Collections . Generic ;
4
+ using System . Data ;
4
5
using System . Linq ;
5
6
using Xunit ;
6
7
using Xunit . Abstractions ;
@@ -104,6 +105,42 @@ public void ShouldNotThrowExceptionIfAccessSomeChildrenNullProp()
104
105
ws . Cell ( "B4" ) . GetString ( ) . Should ( ) . Be ( "Material 1" ) ;
105
106
}
106
107
108
+ [ Fact ]
109
+ public void ShouldClearPlaceHolders ( )
110
+ {
111
+ var wbTemplate = new XLWorkbook ( ) ;
112
+ var ws = wbTemplate . AddWorksheet ( ) ;
113
+ var template = new XLTemplate ( wbTemplate ) ;
114
+
115
+ ws . Cell ( "B8" ) . InsertTable ( new DataTable ( )
116
+ {
117
+ Columns =
118
+ {
119
+ "Id" ,
120
+ "Name"
121
+ } ,
122
+ Rows =
123
+ {
124
+ { "{{item.Id}}" , "{{item.Name}}" }
125
+ }
126
+ } ) ;
127
+ ws . Range ( "B9:C9" ) . AddToNamed ( "TestRange" ) ;
128
+
129
+ var model = new
130
+ {
131
+ TestRange = new List < Item > ( )
132
+ } ;
133
+
134
+ template . AddVariable ( model ) ;
135
+
136
+ template . Generate ( ) ;
137
+
138
+ ws . Cell ( "B8" ) . GetString ( ) . Should ( ) . Be ( "Id" ) ;
139
+ ws . Cell ( "C8" ) . GetString ( ) . Should ( ) . Be ( "Name" ) ;
140
+ ws . Cell ( "B9" ) . GetString ( ) . Should ( ) . BeEmpty ( ) ;
141
+ ws . Cell ( "C9" ) . GetString ( ) . Should ( ) . BeEmpty ( ) ;
142
+ }
143
+
107
144
[ Fact ]
108
145
public void ShouldDestroyEmptyTable ( )
109
146
{
You can’t perform that action at this time.
0 commit comments