Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
430
Excel Exporter cell formats
posted

Hello,

I am exporting my xamdatagrid with Infragistics.Windows.DataPresenter.ExcelExporter.

I have 6 decimal columns in my datagrid and some string columns. 

In 3 of decimal columns I show them in xamdatagrid with the style below to show numbers like that;

453653.00 as 453.653 with no zeros and thousands seperator as you notice 

 

<Style x:Key="DecimalStyleMiktar" TargetType="{x:Type igEditors:XamCurrencyEditor}">

<Setter Property="Format" Value="#,###"/>

</Style>

 

Other 3 decimal columns with the format below

6.435543 as 6,43

0.23432 as 0.23

7.00 as 7

 

 <Style x:Key="DecimalStyle" TargetType="{x:Type igEditors:XamCurrencyEditor}">

<Setter Property="Format" Value="N"/>          

 </Style>

When I exporting this decimalstyles to excel, I use the below code. But Is there any single format that 

combine my two format("#,###" and  "#,##0.00"; ) into one? Or Is there any easier , cleaner way to set number format in columns in the excel?

Thanks

for (int i = 0; i < tempGrid.FieldLayouts[0].Fields.Count; i++)

 {

 if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle != null)

 {

 if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle.Setters.OfType<Setter>().FirstOrDefault(setter => setter.Property.Name == "Format").Value.ToString() == "#,###")

      worksheet.Columns[i].CellFormat.FormatString = "#,###";

else if (tempGrid.FieldLayouts[0].Fields[i].Settings.EditorStyle.Setters.OfType<Setter>().FirstOrDefault(setter => setter.Property.Name == "Format").Value.ToString() == "N")

         worksheet.Columns[i].CellFormat.FormatString = "#,##0.00";

 }

 }