Working with border of the cell in POI

Working with border of the cell in POI

Previous Home Next

 

In this page of the example we are going to show you how to work with the border of the cell with help of the POI API. this is allow to set the border of cell in excel page. 


 


web.xml

package r4r;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import java.io.*;
public class workonborder {
public static void main(String args[])
{
	try{
		HSSFWorkbook wkb = new HSSFWorkbook();
	    HSSFSheet st = wkb.createSheet("Newsheet");

	    // Create a row and put some cells.
	    HSSFRow hr = st.createRow(1);

	    // Create a cell and put a value.
	    Cell cell = (Cell) row.createCell((short) 1);
	    cell.setCellValue(4);

	    // Style the cell with borders.
	    HSSFCellStyle style = wkb.createCellStyle();
	    style.setBorderBottom(CellStyle.BORDER_THIN);
	    style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
	    style.setBorderLeft(CellStyle.BORDER_THIN);
	    style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
	    style.setBorderRight(CellStyle.BORDER_THIN);
	    style.setRightBorderColor(IndexedColors.BLUE.getIndex());
	    style.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);
	    style.setTopBorderColor(IndexedColors.BLACK.getIndex());
	    cell.setCellStyle((CellStyle) style);

	    // Write the output to a file
	    FileOutputStream fileOut = new FileOutputStream("workbook.xls");
	    wb.write(fileOut);
	    fileOut.close();
	}
	catch(Exception e)
	{
		
	}
	
}
}


Previous Home Next