Hello,
I have a grid that has GroupLayout. When the group's text is wider than the total width of the columns in the group, the last column's width is increased so the full text of the groups is shown (I call PerformAutoResizeColumns with includeHeaders = True at the end of InitializeLayout).
Here is an example where one column is in the group and the group's text is wider than the column. In the grid I get what I expect:
Now I export it to Excel using UltragridExcelExporter and it changes the width of the column under the group. It now changed, the width is fitting the column only and does not take the group into account:
I assume this is a bug? Anybody know a way to force this to account for the group?
Thanks,
Trausti
Hi Trausti,
Try calling PerformAutoSize on the column in the export layout inside the BeginExport event of the UltraGridExcelExporter.
Thanks for the reply Mike.
PerformAutoResize on the column while exporting did not change anything.
What exactly is the version of the Infragistics controls, that you are using? I have created a sample where I have a grid with “Row Layout with Groups” and when I export the grid, columns and groups in the exported file are with same width as in the UltraGrid.
Please let me know if you have any further questions or I am missing something .
My version is 10.1.
I replicated the issue outside of our application by creating a form with one grid that is bound to UltraDatasource which has two columns. Each column is 30 pixels wide in the grid.
Same thing happens, it looks good on screen and not in Excel. I can see at run time that the width of the group is 60 pixels (total width of the two columns), but it clearly is wider on screen.
Below is my code. Please let me know if you spot something wrong in it.
Thanks!
Private Sub grd_InitializeLayout(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles grd.InitializeLayout Dim myGroup As UltraWinGrid.UltraGridGroup Dim band As UltraWinGrid.UltraGridBand Dim col As UltraWinGrid.UltraGridColumn
band = e.Layout.Bands(0)
myGroup = band.Groups.Add("Test") myGroup.RowLayoutGroupInfo.OriginX = 1 myGroup.RowLayoutGroupInfo.OriginY = 0 myGroup.RowLayoutGroupInfo.SpanY = 1 myGroup.RowLayoutGroupInfo.SpanX = 2 myGroup.RowLayoutGroupInfo.LabelPosition = UltraWinGrid.LabelPosition.Top myGroup.RowLayoutGroupInfo.LabelSpan = 1 myGroup.Header.Caption = "Here is a very wide text in the group"
band.RowLayoutStyle = UltraWinGrid.RowLayoutStyle.GroupLayout band.RowLayoutLabelStyle = UltraWinGrid.RowLayoutLabelStyle.Separate
For Each col In band.Columns col.RowLayoutColumnInfo.SpanX = 1 col.RowLayoutColumnInfo.SpanY = 1 col.RowLayoutColumnInfo.OriginX = col.Index + 1 col.RowLayoutColumnInfo.OriginY = 1 col.RowLayoutColumnInfo.LabelPosition = UltraWinGrid.LabelPosition.Top col.Group = myGroup Next
e.Layout.PerformAutoResizeColumns(False, UltraWinGrid.PerformAutoSizeType.AllRowsInBand, True) End Sub
Private Sub UltraButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UltraButton1.Click Dim expFile As String = "C:\temp\TestExp.xlsx" exp.Export(grd, expFile, Infragistics.Excel.WorkbookFormat.Excel2007) Process.Start(expFile) End Sub
To be more detailed regarding the version I'm using, it's 10.1.20101.1007
Any ideas?
Hi,
I just wanted to know if you were able to solve your issue based on my suggestions or you still need help? Just let me know.
Thank you.
Thanks for the follow up.
No, that changed nothing. I can see it changing the column width in HeaderCellExporting, but the Excel sheet is created as before.
Can you confirm if this is a bug in latest version or if this has been fixed in a HotFix?
I am glad to hear that my sample helps you to find solution for your issue.
As I mentioned in my previous post, where I have provided you a sample named “WinGridRowLayputExcelExporting”, everything work just fine in Infragistics 11.1. So my suggestion is to compare the code generated from the designer from the “WinGridRowLayputExcelExporting” with your code in order to find the difference which causes your issue.
Please let me know if you have any further questions.
Hristo,
I got this to work. I made few changes to the code you included in your example:
1. Removed this from Initialize Layout:
myGroup.RowLayoutGroupInfo.LabelPosition = UltraWinGrid.LabelPosition.LabelOnly
2. Added this in Initialize Layout:
band.PerformAutoResizeColumns(True, UltraWinGrid.PerformAutoSizeType.AllRowsInBand, True)
3. In HeaderCellExporting, ensure sizing is only done on the last column in the group:
Private Sub exp_HeaderCellExporting(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.ExcelExport.HeaderCellExportingEventArgs) Handles exp.HeaderCellExporting If Not e.GridHeader.Column Is Nothing AndAlso e.GridHeader.Column.Index = e.GridHeader.Column.Group.Columns.Count - 1 Then e.CurrentWorksheet.Columns(e.CurrentColumnIndex).Width = (e.GridHeader.Column.RowLayoutColumnInfo.ActualCellSize.Width) * (256 / grd.Font.Size) End If End Sub
This resulted in a correct export:
Is this going to be fixed in feture release?
Thanks for that. This is not enough to trigger the bug. You need this line in InitializeLayout (which is vital for me):
band.PerformAutoResizeColumns(False, UltraWinGrid.PerformAutoSizeType.AllRowsInBand, True)
This is what kills it. Without this, the columns are wide enough to start with so the issue does not come up. The auto resize reduces the width of the columns and now the group text does not fit in Excel.
Hello ,
I am not exactly sure what is the issue here. So I have created a sample, where I have implement my suggestion. Please see the attached sample and also the video. Please let me know what I am missing.
I am waiting for your response.