Free Support Forum - aspose.com

Shrunken text boxes in workbook (JAVA)

Dear Warren,

When calling setTextWrapped(true) for a couple of cells in a sheet, textboxes on the affected rows are shrunken even though they are placed in completely different columns. Setting text wrap from Excel does not give the same error.

I have attached a sample program that generates the error:

public static void asposeWrapWithTextBoxTest(String fileName, String
saveAs) {

try{

File file = new File(fileName);

Workbook wb = new Workbook();

wb.read(new BufferedInputStream(new FileInputStream(file)));



Worksheet sheet = wb.getSheet(0);



for (int row = 5; row < 20; row++) {

sheet.getCell(row, 0).getStyle().setTextWrapped(true);

}



file = new File(saveAs);



if (!file.exists()) {

file.getParentFile().mkdirs();

}



OutputStream out = null;

out = new BufferedOutputStream(new FileOutputStream(file));

wb.write(out, FileFormatType.EXCEL2003);



out.flush();

out.close();

}

catch(Exception e) {

e.printStackTrace();

}

}

I have also attached the input and output files used by this program.

Thanks for looking into this!

Best regards,

Ulf Ekström, COO

Trade Extensions


Phone: +46 18 13 66 34

Mobile: +46 733 66 55 14



Kungsängsg. 17-19

753 22 Uppsala

Sweden

Phone: +46 18 13 66 00

Fax: +46 18 13 66 01



http://www.tradeextensions.com





Hi,

Please try this fix .

Which version do you use.If you want to set style of the cell now,you must call the Cell.setStyle() method.

Thanks Warren!

Your fix solved the problem. However, when we tried your fix we discovered another bug. When modifying a sheet all rows that doesn’t contain any values (except formatting information) are loosing their heights. Instead they are given the default row height.

The following code sample reproduces the bug (see the attached input and output files):

try{

File file = new File(fileName);

Workbook wb = new Workbook();

wb.read(new BufferedInputStream(new FileInputStream(file)));



Worksheet sheet = wb.getSheet(0);



for (int row = 5; row < 20; row++) {

Cell cell = sheet.getCell(row, 0);



Style style = cell.getStyle();

style.setTextWrapped(true);



cell.setStyle(style);

}



file = new File(saveAs);



if (!file.exists()) {

file.getParentFile().mkdirs();

}



OutputStream out = null;

out = new BufferedOutputStream(new FileOutputStream(file));

wb.write(out, FileFormatType.EXCEL2003);



out.flush();

out.close();

}

catch(Exception e) {

e.printStackTrace();

}


Thanks and best regards,
Ulf Ekström

Hi Ulf,

Please try this fix .We don't auto set row to use default row height when setting Text Wrapped . But another problem occures,the text wrapped will not auto effect . In order to make the text wrapped effect , you should custom the row height or set row to use the default row height .

Now we plan to support Worksheet.autoFitRow() method to auto fit the row height.And it will take us about a month to do.

Dear Warren,

The latest fix solved the problem. Everything works perfect!

Thanks a lot!

Best regards,
Ulf Ekström

Dear Warren,

Does this mean that you will support Worksheet.autoFitColumn() as well?

Thanks,
Ulf

Hi Ulf,

Yes. We will support to auto fit row and column.