Home Tutorials Poi Creating Shapes using Shape Groups



Creating Shapes using Shape Groups
Posted on: August 24, 2011 at 12:00 AM
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

 

Related Tags for Creating Shapes using Shape Groups:


More Tutorials from this section

Ask Questions?    Discuss: Creating Shapes using Shape Groups  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.