The autofit property in MS Excel is a designer property. Microsoft uses an internal algorithm that is not known to do the conversion between pixels and the display height/width. The workaround for this is to manually measure the lengths of the strings in the cells and use an approximate scaling factor to convert the pixels to appropriate measurements. This method is not available in the current ExcelRW API. However we will be adding this functionality shortly. The development team will implement a better algorithm to do the conversion. As a temporary workaround i have been using the following scaling
sheet.Range[i,j].ColumnWidth = (grid.ColWidths[j]/7.43);
sheet.Range[i,1].RowHeight = (grid.RowHeights[i]/1.33);
This scaling factor seems to work fine for me. I have a sample that exports the contents of a GridControl to excel. You will not be able to run the sample because it uses some of the new methods that were added for the final release. I am attaching it in case you might find something useful in the ExportToExcel method that exports the grid control.
Thanks you for your co-operation in this issue. Please let me know if you any any other questions.
>Thansk for your reply
>I am trying to write a function that exports out an ordinary Syncfusion grid to Excel. I have already resized all the columns in the Syncfusion grid and have stored their widths in pixels in an array.
>I want to set the corresponding widths of the columns of the Excel sheet but dont know how to convert the widhts from pixels to the unit that Excel needs (number of characters ??)
>If your can help me out with the example you mentioned in your reply or by letting me know what function I have to call in the ExcelRW API to convert the pixels into for proper display in Excel,then that would be great.
>Thanks and regards
>>The grid that I am exporting to Excel has columns of varying widths. When I open up the Excel file, part of the columns appear "chopped off" because the text in the longer columns is not completely displayed.
>>Is there some sort of resize function call for a range of cells that can be called. I remember that we have a call like this for the Syncfusion grids to automatically update row and column heights after the data is filled.
>>I am looking for something similar for the Excel gird that I create. I dont know what the height/width could be and so cannot use row.height or column.width.