Category / Section
How can we preserve the type string in Templatemarkers?
1 min read
We do not provide direct support for preserving data type when template marker is used. However you can use IsStringsPreserved property of IWorksheet, which would preserve the values in the workbook as string. And you can use the IgnoreErrorOptions to ignore the green error indicator. The below code illustrates this:
C#
//Indicates if all cell values are preserved as strings sheet.IsStringsPreserved = true; string[] array2 = new string[] { "2.5", "1.2", "1.3" }; string[] array1 = new string[] { "11", "12", "13" }; ITemplateMarkersProcessor marker = workbook.CreateTemplateMarkersProcessor(); marker.AddVariable("ArrayProperty1", array1); marker.AddVariable("ArrayProperty2", array2); marker.ApplyMarkers(); //Ignore the green indicator sheet.UsedRange.IgnoreErrorOptions = ExcelIgnoreError.All;
VB
'Indicates if all cell values are preserved as strings sheet.IsStringsPreserved = True Dim array2() As String = New String() {"2.5", "1.2", "1.3"} Dim array1() As String = New String() {"11", "12", "13"} Dim marker As ITemplateMarkersProcessor = workbook.CreateTemplateMarkersProcessor() marker.AddVariable("ArrayProperty1", array1) marker.AddVariable("ArrayProperty2", array2) marker.ApplyMarkers() 'Ignore the green indicator sheet.UsedRange.IgnoreErrorOptions = ExcelIgnoreError.All
Here is the sample for your reference:
http://www.syncfusion.com/downloads/support/directtrac/87766/StringInTemplateMarker-1461232599.zip