private static void drawManyLines(HSSFPatriarch patriarch) {
// Draw bunch of lines
int x1 = 100;
int y1 = 100;
int x2 = 800;
int y2 = 200;
int color = 0;
for (int i = 0; i < 10; i++) {
HSSFClientAnchor a2 = new HSSFClientAnchor();
a2.setAnchor((short) 2, 2, x1, y1, (short) 2, 2, x2, y2);
HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2);
shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
shape2.setLineStyleColor(color);
y1 -= 10;
y2 -= 10;
color += 30;
}
}
private static void drawGrid(HSSFPatriarch patriarch) {
// This draws a grid of lines. Since the coordinates space fixed at
// 1024 by 256 we use a ratio to get a reasonably square grids.
double xRatio = 3.22;
double yRatio = 0.6711;
int x1 = 000;
int y1 = 000;
int x2 = 000;
int y2 = 200;
for (int i = 0; i < 20; i++) {
HSSFClientAnchor a2 = new HSSFClientAnchor();
a2.setAnchor((short) 2, 2, (int) (x1 * xRatio), (int) (y1 * yRatio),
(short) 2, 2, (int) (x2 * xRatio), (int) (y2 * yRatio));
HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2);
shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
private static void drawSheet2(HSSFSheet sheet2) {
// Create a row and size one of the cells reasonably large.
HSSFRow row = sheet2.createRow(2);
row.setHeightInPoints(240);
sheet2.setColumnWidth((short) 2, (short) 9000);
// Create the drawing patriarch. This is the top level container for
// all shapes. This will clear out any existing shapes for that sheet.
HSSFPatriarch patriarch = sheet2.createDrawingPatriarch();
// Draw a grid in one of the cells.
drawGrid(patriarch);
}
private static void drawSheet3(HSSFSheet sheet3) {
// Create a row and size one of the cells reasonably large
HSSFRow row = sheet3.createRow(2);
row.setHeightInPoints(140);
sheet3.setColumnWidth((short) 2, (short) 9000);
// Create the drawing patriarch. This is the top level container for
// all shapes. This will clear out any existing shapes for that sheet.
HSSFPatriarch patriarch = sheet3.createDrawingPatriarch();
// Create a shape group.
HSSFShapeGroup group = patriarch.createGroup(
new HSSFClientAnchor(0, 0, 900, 200, (short) 2, 2, (short) 2, 2));
// 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)
1, 200, 400, 600));
shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE);
}
private static void drawSheet4(HSSFSheet sheet4, HSSFWorkbook wb) {
// Create the drawing patriarch. This is the top level container for
// all shapes. This will clear out any existing shapes for that sheet.
HSSFPatriarch patriarch = sheet4.createDrawingPatriarch();
// Create a couple of textboxes
HSSFTextbox textbox1 = patriarch.createTextbox(
new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 2, 2));
textbox1.setString(new HSSFRichTextString("This is a test"));
HSSFTextbox textbox2 = patriarch.createTextbox(
new HSSFClientAnchor(0, 0, 900, 100, (short) 3, 3, (short) 3, 4));
textbox2.setString(new HSSFRichTextString("Woo"));
textbox2.setFillColor(200, 0, 0);
textbox2.setLineStyle(HSSFSimpleShape.LINESTYLE_DOTGEL);
// Create third one with some fancy font styling.
HSSFTextbox textbox3 = patriarch.createTextbox(
new HSSFClientAnchor(0, 0, 900, 100, (short) 4, 4, (short) 5,
4 + 1));
HSSFFont font = wb.createFont();
font.setItalic(true);
font.setUnderline(HSSFFont.U_DOUBLE);
HSSFRichTextString string = new HSSFRichTextString("Woo!!!");
string.applyFont(2, 5, font);
textbox3.setString(string);
textbox3.setFillColor(0x08000030);
textbox3.setLineStyle(HSSFSimpleShape.LINESTYLE_NONE); // no line around the textbox.
textbox3.setNoFill(true); // make it transparent
}
private static void drawOval(HSSFPatriarch patriarch) {
// Create an oval and style to taste.
HSSFClientAnchor a = new HSSFClientAnchor();
a.setAnchor((short) 2, 2, 20, 20, (short) 2, 2, 190, 80);
HSSFSimpleShape s = patriarch.createSimpleShape(a);
s.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
s.setLineStyleColor(10, 10, 10);
s.setFillColor(90, 10, 200);
s.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT * 3);
s.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);
}