Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Automatically resize columns in exported excel sheet.
Automatically resize columns in exported excel sheet. [message #1610198] Tue, 10 February 2015 16:30 Go to next message
Thomas Zwickl is currently offline Thomas ZwicklFriend
Messages: 37
Registered: May 2014
Member
Hi,

I'm using the POI excel exporter and I wondered if it is possible to automatically resize the columns ...
The problem is after I've exported the NatTable all columns have only a very small size and you really cannot read anything. Because of the fact that we have a lot of columns it is always very cumbersome to manually resize each column separately.
Any help or pointers would be appreciated Smile
Re: Automatically resize columns in exported excel sheet. [message #1610406 is a reply to message #1610198] Tue, 10 February 2015 19:39 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
http://poi.apache.org/spreadsheet/quick-guide.html#Autofit

I guess you need to extend our exporter to add the necessary command
Re: Automatically resize columns in exported excel sheet. [message #1610510 is a reply to message #1610406] Tue, 10 February 2015 21:12 Go to previous message
Thomas Zwickl is currently offline Thomas ZwicklFriend
Messages: 37
Registered: May 2014
Member
Thanks for the link Smile No sooner said than done Wink
If someone has the same problem here is the class I added, which additionally adds borders around each cell:

public class CustomisedHSSFExcelExporter extends HSSFExcelExporter {

	@Override
	public final void exportEnd(final OutputStream outputStream) throws IOException {

		if (this.xlSheet.getRow(0) != null) {

			for (int r = 0; r < this.xlSheet.getPhysicalNumberOfRows(); r++) {
				Row row = this.xlSheet.getRow(r);

				for (int c = 0; c < row.getPhysicalNumberOfCells(); c++) {
					Cell cell = row.getCell(c);

					if (cell != null) {
						CellStyle style = cell.getCellStyle();

                                                // add a border around each cell
						style.setBorderBottom(CellStyle.BORDER_THIN);
						style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
						style.setBorderLeft(CellStyle.BORDER_THIN);
						style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
						style.setBorderRight(CellStyle.BORDER_THIN);
						style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
						style.setBorderTop(CellStyle.BORDER_THIN);
						style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
					}
				}
			}

			int numberOfColumns = this.xlSheet.getRow(0).getPhysicalNumberOfCells();

			for (int i = 0; i < numberOfColumns; i++) {
                                // auto-resize each cell according to its current content
				this.xlSheet.autoSizeColumn(i);
			}

		}

		super.exportEnd(outputStream);
	}
}

[Updated on: Tue, 10 February 2015 21:40]

Report message to a moderator

Previous Topic:How add a Cancel function for nattable search
Next Topic:Auto scroll to bottom of table without any cell selection
Goto Forum:
  


Current Time: Thu Apr 25 18:12:25 GMT 2024

Powered by FUDForum. Page generated in 0.04252 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top