Home Tutorials Poi Creating Shapes using Shape Groups
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Creating Shapes using Shape Groups

Advertisement
In this section, you will learn how to create shapes using Apache POI library.

Creating Shapes using Shape Groups

In this section, you will learn how to create shapes using Apache POI library.

EXAMPLE

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFChildAnchor;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFShapeGroup;
import org.apache.poi.hssf.usermodel.HSSFSimpleShape;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class XLShapeGroup {
public static void main(String args[]) throws FileNotFoundException {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("Data Validation");
HSSFPatriarch patriarch = (HSSFPatriarch) sheet
.createDrawingPatriarch();
// Create a shape group.
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor(0, 0,
900, 200, (short) 0, 1, (short) 1, 0));

// Create a couple of lines in the group.
HSSFSimpleShape shape1 = group.createShape(new HSSFChildAnchor(3, 3,
500, 500));
shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
((HSSFChildAnchor) shape1.getAnchor())
.setAnchor((short) 3, 3, 500, 500);
HSSFSimpleShape shape2 = group.createShape(new HSSFChildAnchor(
(short) 0, 200, 400, 600));
shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
FileOutputStream fileOut = new FileOutputStream("xls/XLShapeGroup.xls");
try {
workbook.write(fileOut);
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

OUTPUT

Download Source Code

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 24, 2011

Related Tutorials

Ask Questions?    Discuss: Creating Shapes using Shape Groups  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Raghu
May 19, 2014
Tickmark in Excel.

Hi, Can anyone help me in understanding how to show a tickmark in a cell for excel while generating using POI.
DMCA.com