Setting Line Style

In this program we are going to create a sheet then create oval then after set style of line and color.

Setting Line Style

setting line style

     

In this program we are going to create a sheet  then create oval then after set style of line and color. 

Code description
The package we need to import is java.io.*,java.util.* ,org.apache.poi.hssf.usermodel.HSSFSheet,org.apache.poi.hssf.usermodel. HSSFPrintSetup, org.apache.poi.hssf.usermodel.HSSFPatriarch,org.apache.poi.hssf.usermodel.HSSFClientAnchor,org.apache. poi.hssf.usermodel.HSSFSimpleShape and org.apache.poi.hssf.usermodel. HSSFWorkbook.

The method used in this example shift row

setLineWidth(int lineWidth):
This method is used to set the width of the liine.The value is coresponding 1pt=12700 or LINEWIDTH_ONE_PT

setLineStyle(int lineStyle):
This method is used to set the line style.

setLineStyleColor(int lineStyleColor):
This method is used to set color to the lines of this shape.

setLineStyleColor(int red,int green,int blue)
The color applied to the lines of this shape.

You can be used the following fields for color style 
static int LINESTYLE_DASHDOTDOTSYS
static int LINESTYLE_DASHDOTGEL
static int LINESTYLE_DASHDOTSYS
static int LINESTYLE_DASHGEL
static int LINESTYLE_DASHSYS
static int LINESTYLE_DOTGEL
static int LINESTYLE_DOTSYS
static int LINESTYLE_LONGDASHDOTDOTGEL
static int LINESTYLE_LONGDASHDOTGEL
static int LINESTYLE_LONGDASHGEL
static int LINESTYLE_NONE
static int LINESTYLE_SOLID
static int LINEWIDTH_DEFAULT
static int LINEWIDTH_ONE_PT 

 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.HSSFPrintSetup"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFPatriarch"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFClientAnchor"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFSimpleShape"%>
<%page import="org.apache.poi.hssf.usermodel.HSSFShape"%>
<%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");
  HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
  HSSFClientAnchor a2 = new HSSFClientAnchor
001023255(short10(short5);
  HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2);
  shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
  shape2.setLineStyleColor(102,101,10);
  shape2.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT * 4);
  shape2.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);
  FileOutputStream fileOut = new FileOutputStream
(
"c:\\excel\\setLineStyleOfOval.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.