Question

we are using the Telerik's Grid component with ASP.net (the package is called ASP.NET AJAX). The grid is very comfortable, it offers a Export To Excel functionality. Unfortunately the ways of customizing the Excel seem to be limited. The question is:

How can I make the column width of the resulting excel fitting to the content of the widest cell?

  Public Sub ExportGridToExcel(vGrid As RadGrid)
    mIsExporting = True
    vGrid.Rebind()
    vGrid.ExportSettings.Excel.Format = GridExcelExportFormat.Biff
    vGrid.MasterTableView.ExportToExcel()
  End Sub
Was it helpful?

Solution

See here or here how to access and modify columns before export. On getting the longest string - I think you would need to query the datasource and traverse it to know. The control would have no way of knowing what data it will receive. If you expect exports to be common you can consider doing this calculation only once when data binding the grid, and storing the preferred widhts of the columns in the ViewState, Session or something. Of course, if your data is rather static, you can consider storing this infomormation about the database fields content in the database itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top