zwwcn

Just another WordPress.com site

Monthly Archives: November 2017

print css example

I had a task to print a dashboard page.  The print review looks quite different from the web page, so I have to create a print css to customize the display.

Create a print link on the page to call the below function.

		function printDiv() {					    
                     //backup dom
		     var originalContents = document.body.innerHTML;
		     
                     //make whatever change you want, remove unnecessary elements	
	             $("li").removeClass("gs-w");
		
                     //print the modified page
		     window.print();

                     //reset page 	
	             document.body.innerHTML = originalContents;
		}

Include the css on the page,  apply the page break only in print mode.

@media all {
	.page-break {
		display: none !important;
	}
}

@media print {
	html, body, ul {
		float: none !important;
	}
	.page-break {
		display: block;
		page-break-after: always;
	}
}

 

Advertisements

POI add number cell

Make sure you add cell value as number, otherwise you can’t sort the columns in new file.

Add number:

HSSFRow row = sheet.createRow(sheet.getLastRowNum());
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = workbook.createCellStyle();
style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
cell.setCellStyle(style);
cell.setCellValue(Float.parseFloat("21.5"));

Add percentage:

cell.setCellValue(0.123); // set value as number
CellStyle style = workbook.createCellStyle();
style.setDataFormat(workbook.createDataFormat().getFormat("0%"));
cell.setCellStyle(style);