Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
{description}
{excerpt}If you set [PreserveStrings|ExcelTemplate.PreserveStrings] to {{true}}, ExcelWriter will preserve numeric strings as strings. 
{excerpt}
{signature:C#}
 public boolean PreserveStrings{ get; set; }
{signature}{signature:vb.net}
Public Property PreserveStrings() As Boolean
{signature}
{remarks}
By default, when populating template data markers, ExcelWriter tries to convert numeric strings to numbers. 

{{PreserveStrings}} is a *Read/Write* property.

This property can be set for individual data markers using the [Preserve data marker modifier|Creating Data Markers#modifiers].
          

{remarks}
{example}{code:csharp|title=C#}

          ExcelTemplate xlt = new ExcelTemplate();
          xlt.Open(@"C:\DataBinding\ArrayBindingTemplate.xls");
          string[][] twodim = {
               new string[]{"Watertown", "MA", "02472"},
               new string[]{"Washington","DC", "20500"}
               };
          string[] names = {"City", "State", "Zip"};
          xlt.BindData(twodim,
               names,
               "TwoDimArray",
               xlt.CreateDataBindingProperties());
          xlt.PreserveStrings = true;
          xlt.Process();
          xlt.Save(Page.Response, "ArrayBinding.xls", false);
        {code}
{code:vb.net|title=vb.net}

          Dim xlw As New ExcelTemplate()
          xlt.Open("C:\DataBinding\ArrayBindingTemplate.xls")
          Dim twodim As String()() = { _
               New String(){"Watertown", "MA", "02472"}, _
               New String(){"Washington", "DC", "20500"}, _
               }
          Dim names As String() = {"City", "State", "Zip"}
          xlt.BindData(twodim, _
               names, _
               "TwoDimArray", _
               xlt.CreateDataBindingProperties())
          xlt.PreserveStrings = True
          xlt.Process()
          xlt.Save(Page.Response, "ArrayBinding.xls", False)
        {code}

{example}