You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by John Sims <Si...@wyeth.com> on 2005/04/26 14:24:34 UTC

Automatically expanding each column to accomodate largest/widest cell using POI-HSSF

Hi,
 
I'm using POI-HSSF in a JSP application to stream an Excel spreadsheet to a web browser. This is working great! 
 
But, I cannot find a way to easily expland each column's width to accomodate the widest cell in the column (ie. Fit the contents). That is, i'd like to have the Excel spreadsheet initially open as if the user  double-clicked the boundary to the right of each column heading. 
 
Anyone know of a way to do this programatically?
 
thanks,
-john



Re: Automatically expanding each column to accomodate largest/widest cell using POI-HSSF

Posted by Sanjiv Jivan <sa...@gmail.com>.
Not sure if HHSF has an API for this but you can add the following
code in the Open  subroutine of  your workbook.

Private Sub Workbook_Open()
   Dim i As Integer
   Application.ScreenUpdating = False
   For i = 1 To Sheet1.UsedRange.Columns.Count
        Sheet1.UsedRange.Columns(i).EntireColumn.AutoFit
    Next
   Application.ScreenUpdating = True
End Sub

Hope this helps,
Sanjiv

On 4/26/05, John Sims <Si...@wyeth.com> wrote:
> Hi,
> 
> I'm using POI-HSSF in a JSP application to stream an Excel spreadsheet to a web browser. This is working great!
> 
> But, I cannot find a way to easily expland each column's width to accomodate the widest cell in the column (ie. Fit the contents). That is, i'd like to have the Excel spreadsheet initially open as if the user  double-clicked the boundary to the right of each column heading.
> 
> Anyone know of a way to do this programatically?
> 
> thanks,
> -john
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/