FAQ/Questions/Add-Formatting-Options.md
... ...
@@ -6,6 +6,16 @@
6 6
7 7
Here we will show you how to easily add a new formatting option to the "Formats" dropdown menu on the Fields tab of the Report Designer. These should be handled in your ``InitializeReporting()`` method in your global.asax.
8 8
9
+##Update since version 6.10.0.4
10
+
11
+As of version 6.10.0.4, the best practice for custom formatters has changed:
12
+
13
+1) Replace IFormatter with BaseFormatter
14
+2) Replace all DataTable occurrences with AdHocDataTable
15
+3) Add override key words to the methods, so:
16
+- "public Type GetOutputDataType" -> "public override Type GetOutputDataType"
17
+- "public object Format" -> "public override object Format"
18
+
9 19
##Exporting to Excel
10 20
11 21
Excel uses internal formatting and attempts to 'guess' what the proper format for a value should be. This means that sometimes, Excel guesses incorrectly and while the correct value might be exported to Excel, the format will be wrong - for example, .623 instead of 62.3%. In this case, it is necessary to specify the data type group exactly using the full constructor to specify data type:
... ...
@@ -127,6 +137,60 @@ Please see this sample code:
127 137
128 138
```
129 139
140
+##Example 5 - Running total
141
+
142
+```csharp
143
+
144
+AdHocSettings.Formats.Add("RowNumber", new RowNumberFormat());
145
+
146
+public class RowNumberFormat : IFormat
147
+{
148
+ public SqlTypeGroupCollection AllowedTypeGroups
149
+ {
150
+ get { return null; }
151
+ }
152
+
153
+ public SqlTypeGroupCollection DisallowedTypeGroups
154
+ {
155
+ get { return null; }
156
+ }
157
+
158
+ public string Name
159
+ {
160
+ get { return "RowNumber"; }
161
+ }
162
+
163
+ public bool Visible
164
+ {
165
+ get { return true; }
166
+ }
167
+
168
+ public SqlTypeGroup DefaultFor
169
+ {
170
+ get { return SqlTypeGroup.None; }
171
+ }
172
+
173
+ public IFormatter[] CreateFormatters()
174
+ {
175
+ return new IFormatter[] { new RowNumberFormatter() };
176
+ }
177
+}
178
+
179
+
180
+public class RowNumberFormatter : BaseFormatter
181
+{
182
+ public override Type GetOutputDataType(AdHocDataTable table, int columnNumber, ReportOutputOptions reportOutputOptions, Field field)
183
+ {
184
+ return table.Columns[columnNumber].DataType;
185
+ }
186
+
187
+ public override object Format(AdHocDataTable table, int rowNumber, int columnNumber, Field field, AdHocDataTable originalTable, Field nameField)
188
+ {
189
+ return rowNumber + 1;
190
+ }
191
+}
192
+
193
+```
130 194
131 195
###Results
132 196