Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
JSP
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

different borders

                         

In this program we are going create a sheet  after that  enter the values in that cell then we create different borders and we also sets the different colors. .
Code description 
The package we need to import is java.io.*,java.util.* ,org.apache.poi.hssf.usermodel.HSSFSheet,org.apache.poi.hssf.usermodel.
HSSFCell,org.apache.poi.hssf.usermodel.
HSSFCellStyle,org.apache.poi.hssf.usermodel.HSSFRow, org.apache.poi.usermodel. HSSFColor
and org.apache.poi.hssf.usermodel. HSSFWorkbook.
 
We can set  various borders and set various color of the borders.
The method used in this example shift row

setBorderLeft(short border):
This method is used to set the type of border to use for the left border of the cell In this method we pass only one parameter. That is border type. 

setBorderRight(short border):
This method is used to set the type of border to use for the right border of the cell 

 setBorderTop(short border):
This method is used to set the type of border to use for the top border of the cell 

setBorderBottom(short border):
This method is used to set the type of border to use for the bottom border of the cell 

 setLeftBorderColor(short color):
This method is used to set the color to use for the left border 

 setRightBorderColor(short color):
This method is used to set the color to use for the right border 

 setTopBorderColor(short color):
This method is used to set the color to use for the top border 

setBottomBorderColor(short color):
This method is used to set the color to use for the bottom border 

We can pass following short  type for border.
BORDER_NONE, BORDER_THIN, BORDER_MEDIUM, BORDER_DASHED, BORDER_DOTTED, BORDER_THICK, BORDER_DOUBLE, BORDER_HAIR, BORDER_MEDIUM_DASHED, BORDER_DASH_DOT, BORDER_MEDIUM_DASH_DOT, BORDER_DASH_DOT_DOT, BORDER_MEDIUM_DASH_DOT_DOT, BORDER_SLANTED_DASH_DOT

 The code of the program is given below:

<%page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFCellStyle"%>
<%page import="org.apache.poi.hssf.util.HSSFColor"%>
<%page contentType="application/vnd.ms-excel" %>
<%page import="java.io.*" %>
<%page import="java.util.*" %>
<%
try{
  HSSFWorkbook hwb = new HSSFWorkbook();
  HSSFSheet sheet = hwb.createSheet("new sheet");
  HSSFCellStyle style1 = hwb.createCellStyle();
  HSSFCellStyle style2 = hwb.createCellStyle();
  HSSFCellStyle style3 = hwb.createCellStyle();
  HSSFCellStyle style4 = hwb.createCellStyle();
  HSSFCellStyle style = hwb.createCellStyle();
  HSSFRow row = sheet.createRow((short1);
  HSSFCell cell = row.createCell((short0);
  cell.setCellValue(1);
  style.setBorderRight(HSSFCellStyle.BORDER_THIN);
  style.setRightBorderColor(HSSFColor.BLUE.index);
  HSSFCell cell4 = row.createCell((short1);
  cell4.setCellValue(2);
  style1.setBorderTop(HSSFCellStyle.BORDER_MEDIUM_DASHED);
  style1.setTopBorderColor(HSSFColor.BLACK.index);
  HSSFCell cell1 = row.createCell((short2);
  cell1.setCellValue(3);
  style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  style2.setBottomBorderColor(HSSFColor.BLACK.index);
  HSSFCell cell2 = row.createCell((short3);
  cell2.setCellValue(4);
  HSSFCell cell3 = row.createCell((short4);
  cell3.setCellValue(5);
  style3.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  style3.setBottomBorderColor(HSSFColor.BLACK.index);
  style4.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  style4.setBottomBorderColor(HSSFColor.BLACK.index);
  style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
  style.setLeftBorderColor(HSSFColor.GREEN.index);  
  cell.setCellStyle(style);
  cell1.setCellStyle(style1);
  cell2.setCellStyle(style2);
  cell3.setCellStyle(style3);
  cell4.setCellStyle(style4);
 FileOutputStream fileOut = new FileOutputStream
(
"C:\\excel\\border.xls");
  hwb.write(fileOut);
  fileOut.close();
  out.println("Your excel file has been generated");     
        catch Exception ex ) {          
        }   


%>

The output of the program is given below:

Download this example.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.