Skip to content

Commit 78f6e2c

Browse files
author
Daniel Peichev
committed
add autofit functionality, correct the location of the ResumeLayoutUpdate
1 parent 4e309de commit 78f6e2c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

grid/grid-dpl-integration/GridExcelSpreadProcessing/Controllers/HomeController.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ public JsonResult Export(string model, string data, string format, string title)
2828

2929
var modelObject = JsonConvert.DeserializeObject<dynamic>(model);
3030
var dataObject = JsonConvert.DeserializeObject<dynamic>(data);
31+
var columnCount = modelObject.Count;
3132

32-
workbook.ResumeLayoutUpdate();
33-
34-
for (int idx = 0; idx < modelObject.Count; idx++)
33+
for (int idx = 0; idx < columnCount; idx++)
3534
{
3635
var modelCol = modelObject[idx];
3736
string columnName = modelCol.title ?? modelCol.field;
@@ -46,6 +45,14 @@ public JsonResult Export(string model, string data, string format, string title)
4645
}
4746
}
4847

48+
if (format == "XLSX")
49+
{
50+
ColumnSelection columnSelection = worksheet.Columns[0, columnCount];
51+
columnSelection.AutoFitWidth();
52+
}
53+
54+
workbook.ResumeLayoutUpdate();
55+
4956
IWorkbookFormatProvider formatProvider = null;
5057
if (format == "XLSX")
5158
{

grid/grid-dpl-integration/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The Home and Stream views are basically the same, but there are major difference
1010
### Home controller
1111
This is a barebone example of [RadSpreadProcessing](http://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/overview)
1212
and [Grid](http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/overview) integration. It supports CSV and XLSX formats and
13-
demonstrates how you could create the basic building components of the Workbook.
13+
demonstrates how you could create the basic building components of the Workbook. XLSX export utilizes an autofit functionality in this demo.
1414
There are some performance features enabled like disabling the history and suspending the layout update which
1515
are described in the [Performance Tips and Tricks](http://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/performance)
1616
section.
@@ -26,7 +26,8 @@ using Telerik.Windows.Documents.Spreadsheet.Model;
2626
Sometimes we need to get the best performance and minimal resource consumption in order to export greater amounts of records. For cases like that,
2727
the [RadSpreadStreamProcessing](http://docs.telerik.com/devtools/document-processing/libraries/radspreadstreamprocessing/overview) may be a better choice.
2828
This simple demo should be a good starting point for integration between [Grid](http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/overview)
29-
and the aforementioned library. Supported format are once again, CSV and XLSX.
29+
and the aforementioned library.
30+
Note that the stream-based library does not support autofit functionality (XLSX). Supported format are once again, CSV and XLSX.
3031

3132
```
3233
using Telerik.Documents.SpreadsheetStreaming;

0 commit comments

Comments
 (0)