When I export to excel the width is always set to 100%. This can be seen by exporting to excel and opening the file in notepad. For example, notice the 100% below:
<table rules="all" border="1" id="ctl05_grdBudget_ctl00" style="width:100%;table-layout:auto;empty-cells:show;">
Is there a way to prevent this? When I set the width in the NeedDataSource handler the grid displays on the page with the set width. However, this does not persist when exported to excel. I have tried setting the width prior to calling MasterTableView.ExportToExcel however this does not seem to make a difference as it is always 100% for the export.
From what I have seen, the only way around this is to set the width of each column which I do not want to do. I want to have the grid auto size when exported. If you edit the exported file and remove width:100% then open it in Excel, it will display the way I would like it to.
The reason I am asking is because the columns are too wide to fit on a single page when you go to print in Excel. Below is the code I am using if it is of any help.
<table rules="all" border="1" id="ctl05_grdBudget_ctl00" style="width:100%;table-layout:auto;empty-cells:show;">
Is there a way to prevent this? When I set the width in the NeedDataSource handler the grid displays on the page with the set width. However, this does not persist when exported to excel. I have tried setting the width prior to calling MasterTableView.ExportToExcel however this does not seem to make a difference as it is always 100% for the export.
From what I have seen, the only way around this is to set the width of each column which I do not want to do. I want to have the grid auto size when exported. If you edit the exported file and remove width:100% then open it in Excel, it will display the way I would like it to.
The reason I am asking is because the columns are too wide to fit on a single page when you go to print in Excel. Below is the code I am using if it is of any help.
<%--Button to perform the export--%>
<
asp:LinkButton
runat
=
"server"
ID
=
"lnkExport"
Text
=
"Export"
></
asp:LinkButton
>
<%--The grid itseld--%>
<
telerik:RadGrid
ID
=
"grdTest"
runat
=
"server"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"Name"
HeaderText
=
"Supervisor"
DataField
=
"Name"
/>
<
telerik:GridBoundColumn
SortExpression
=
"Unconfirmed"
HeaderText
=
"Unconfirmed"
DataField
=
"Unconfirmed"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Private Sub grdTest_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdTest.NeedDataSource
Me.grdTest.DataSource = New List(Of Object) From {New With {.Name = "Name 1", .Unconfirmed = 5},
New With {.Name = "Name 2", .Unconfirmed = 3}}
'manually setting the width, this displays as it should on the page
Me.grdTest.Width = Unit.Pixel(500)
End Sub
Private Sub lnkExport_Click(sender As Object, e As EventArgs) Handles lnkExport.Click
Me.grdTest.MasterTableView.ExportToExcel()
End Sub