Ticket T543554
Visible to All Users

GridView.BestFitColumns doesn't fit all content

created 8 years ago

Trying to export to xlsx I am creating a GridView and GridControl in code. After binding a DataTable to the GridControl I call the BestFitColumns method. To my surprise most columns in the exported Excel file have a width which is smaller than their longest content. I want the column width to adjust to the longest content. How can I achieve this desired result?
Below is all the code I use for manipulating the result:

Visual Basic
gridControl.BindingContext = New BindingContext() gridControl.MainView = gridView gridView.GridControl = gridControl gridControl.DataSource = dataTable gridControl.ForceInitialize() gridView.PopulateColumns() gridView.OptionsPrint.PrintHeader = True gridView.OptionsPrint.PrintFooter = False 'Disable grid lines gridView.OptionsPrint.PrintVertLines = False gridView.OptionsPrint.PrintHorzLines = False 'Best fit columns gridView.OptionsPrint.AutoWidth = False gridView.OptionsView.ColumnAutoWidth = False gridView.BestFitColumns()

Answers approved by DevExpress Support

created 8 years ago (modified 8 years ago)

Hello Brecht,
The behavior you describe is due to the difference in fonts used in your app and in Excel (by default, in GridView, Tahoma 8.25 is used, and in Excel - Calibri 11). The solutions to this problem are already described in the Export to Excel column auto fit thread. I have created a project in which these solutions are demonstrated.
Try these solutions, choose the one that suits you, and tell me the results.

    Show previous comments (3)
    DevExpress Support Team 8 years ago

      I look forward to your results.

      BD BD
      Brecht Debaere 8 years ago

        Thank you Igor, we have updated our assemblies a month or so ago.

        DevExpress Support Team 8 years ago

          You are welcome!
          Please feel free to contact us in case of any difficulty. We will be happy to assist you.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.