I am not certain just what your requirements/constraints are so this suggestion may be useless; can you not simply increase the width of the cell so that it is able to accomodate the String? Obvisouly, this means that the width of the column will be set to accomodate the longest String but there is already a method in the API to accomplish just this task. Take a look at the autoSizeColumn() method that is defined on both of the HSSFSheet and XSSFSheet classes. Typically, you use this by iterating through all of the columns on a sheet immediately prior to saving the workbook away.
To answer your original question, yes it is possible to recover the width of the column, find out how long the String is, insert a carriage return/carriage returns at the appropriate place(s) in the String, write the String way to the cell and set the cells format so that it's contents wrap but this could present you with other problems; what if the row was not high enough? Then the users would have to scroll the contents of the cell up and down within the cell to view them fully. Of course you can increase the rows' height but it may be that setting the columns width is the easiest, neatest answer if this fits your requirement. Yours Mark B Michael L-3 wrote: > > Is there a way to format the string put in a cell so that it will attempt > to fit > in the visible dimensions of the cell? Currently, if I put a string whose > length > is longer than that of the cell's width, the string is cut off and can > only be > read if the reader manually extends the width of the cell. I guess what I > really > want is for the string to go to a new line in the cell when it reaches the > end > of the cell's width. Is this possible using POI? > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > -- View this message in context: http://old.nabble.com/String-formatting-in-cells--tp26649280p26653493.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
