It is time for me to retire I think. Ignore last message and simply try this;

    public static void main(String[] args) {
        File file = null;
        FileOutputStream fos = null;
        HSSFWorkbook workbook = null;
        HSSFSheet sheet = null;
        HSSFRow row = null;
        HSSFCell cell = null;
        HSSFCellStyle wrapStyle = null;
        try {
            file = new File("C:/temp/Wrap Test.xls");
            fos = new FileOutputStream(file);

            workbook = new HSSFWorkbook();

            wrapStyle = workbook.createCellStyle();
            wrapStyle.setWrapText(true);

            sheet = workbook.createSheet("Wrap Demo.");
            row = sheet.createRow(0);
            cell = row.createCell(0);

            cell.setCellValue("This is a slightly longer String.");
            cell.setCellStyle(wrapStyle);

            workbook.write(fos);
        }
        catch(IOException ioEx) {
            System.out.println("Caught: " + ioEx.getClass().getName());
            System.out.println("Message: " + ioEx.getMessage());
            System.out.println("Stacktrace follows:............");
            ioEx.printStackTrace(System.out);
        }
        finally {
            if(fos != null) {
                try {
                    fos.close();
                }
                catch(IOException ioEx) {
                    // I G N O R E
                }
            }
        }
    }

The key is the cell style object, it ensures that the long String will be
wrapped in the cell, that the 'breaks' occur at the word boundaries and
Excel itself ensures that the row is shown expanded to the correct height to
accomodate the cells contents.

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--tp26649280p26654385.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]

Reply via email to