HSSFShape

1.接口Shape

从POI 3.16-beta2开始,POI中HSSF和XSSF中形状都实现公共接口Shape,以后就可以根据接口编程,而不用麻烦单独处理HSSF和XSSF中的形状



2. 接口Shape方法



3.抽象类HSSFShape

实现接口Shape


4.常量

 // shape边框的宽度以点为单位,1pt=1/72英寸,是个绝对单位
 public static final int LINEWIDTH_ONE_PT = 12700;
 // shape边框的默认宽度
 public static final int LINEWIDTH_DEFAULT = 9525;
 // shape边框的默认颜色,08表示透明度,0x00******为透明色
 public static final int LINESTYLE__COLOR_DEFAULT = 0x08000040;
 
 // shape的默认填充色
 public static final int FILL__FILLCOLOR_DEFAULT = 0x08000009;
 
 // shape是否填充默认值,默认不填充
 public static final boolean NO_FILL_DEFAULT = true;

 // shape边框样式:实线 -----------------
 public static final int LINESTYLE_SOLID = 0;              // Solid (continuous) pen
 
 // shape边框样式:PS_DASH系统中的短线风格
 public static final int LINESTYLE_DASHSYS = 1;            // PS_DASH system   dash style
 
 // shape边框样式:PS_DOT系统中的短线风格
 public static final int LINESTYLE_DOTSYS = 2;             // PS_DOT system   dash style
 
 // shape边框样式:PS_DASHDOT系统中的短线风格
 public static final int LINESTYLE_DASHDOTSYS = 3;         // PS_DASHDOT system dash style
 
 // shape边框样式:PS_DASHDOTDOT系统中的短线风格
 public static final int LINESTYLE_DASHDOTDOTSYS = 4;      // PS_DASHDOTDOT system dash style
 
 // shape边框样式:方形点 ...............
 public static final int LINESTYLE_DOTGEL = 5;             // square dot style
 
 // shape边框样式:短线风格 - - - - - - - - - - 
 public static final int LINESTYLE_DASHGEL = 6;            // dash style
 
 // shape边框样式:长一些的短线 -- -- -- -- -- --
 public static final int LINESTYLE_LONGDASHGEL = 7;        // long dash style
 
 // shape边框样式:短线和点间隔 - . - .- .- . - .
 public static final int LINESTYLE_DASHDOTGEL = 8;         // dash short dash
 
 // shape边框样式:长一些的短线和点间隔 -- . -- . -- .--
 public static final int LINESTYLE_LONGDASHDOTGEL = 9;     // long dash short dash
 
 // shape边框样式:长一些的短线和两个点间隔 --- . . --- . . --- . . --- . . ---
 public static final int LINESTYLE_LONGDASHDOTDOTGEL = 10; // long dash short dash short dash
 
 // shape边框样式:无边框
 public static final int LINESTYLE_NONE = -1;

 // shape边框默认值:无边框
 public static final int LINESTYLE_DEFAULT = LINESTYLE_NONE;

 // 标记shape没有填充色
 public final static int NO_FILLHITTEST_TRUE = 0x00110000;
 
 // 标记shape有填充色
 public final static int NO_FILLHITTEST_FALSE = 0x00010000;
3.方法


5.实例

package hssf;

import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.hssf.usermodel.HSSFTextbox;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public class TestHSSFTextBoxLineStyle {

	public static void main(String[] args) throws Exception {
		// 创建一个工作博
				Workbook workbook = new HSSFWorkbook();
				// 创建一个sheet
				Sheet sheet = workbook.createSheet();
				// 画图的顶级管理器对象HSSFPatriarch, 一个sheet只能获取一个
				HSSFPatriarch hssfPatriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
				
				// 形状在sheet中的锚点位置
				HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short)1, 2, (short)3, 8);
				HSSFTextbox textbox = hssfPatriarch.createTextbox(anchor);
				// 设置文本框边框颜色 - 蓝色
				textbox.setLineStyleColor(0, 0, 255);
				// 设置文本框边框宽度 - 3pt
				textbox.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				// 设置文本框边框样式
				textbox.setLineStyle(HSSFShape.LINESTYLE_SOLID);
				
				// 形状在sheet中的锚点位置
				HSSFClientAnchor anchor1 = new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 8);
				HSSFTextbox textbox1 = hssfPatriarch.createTextbox(anchor1);
				textbox1.setLineStyleColor(0, 0, 255);
				textbox1.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox1.setLineStyle(HSSFShape.LINESTYLE_DASHSYS);
				
				HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 0, 0, (short)7, 2, (short)9, 8);
				HSSFTextbox textbox2 = hssfPatriarch.createTextbox(anchor2);
				textbox2.setLineStyleColor(0, 0, 255);
				textbox2.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox2.setLineStyle(HSSFShape.LINESTYLE_DOTSYS);
				
				HSSFClientAnchor anchor3 = new HSSFClientAnchor(0, 0, 0, 0, (short)10, 2, (short)12, 8);
				HSSFTextbox textbox3 = hssfPatriarch.createTextbox(anchor3);
				textbox3.setLineStyleColor(0, 0, 255);
				textbox3.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox3.setLineStyle(HSSFShape.LINESTYLE_DASHDOTSYS);
				
				HSSFClientAnchor anchor4 = new HSSFClientAnchor(0, 0, 0, 0, (short)13, 2, (short)15, 8);
				HSSFTextbox textbox4 = hssfPatriarch.createTextbox(anchor4);
				textbox4.setLineStyleColor(0, 0, 255);
				textbox4.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox4.setLineStyle(HSSFShape.LINESTYLE_DASHDOTDOTSYS);
				
				HSSFClientAnchor anchor5 = new HSSFClientAnchor(0, 0, 0, 0, (short)16, 2, (short)18, 8);
				HSSFTextbox textbox5 = hssfPatriarch.createTextbox(anchor5);
				textbox5.setLineStyleColor(0, 0, 255);
				textbox5.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox5.setLineStyle(HSSFShape.LINESTYLE_DOTGEL);
				
				HSSFClientAnchor anchor6 = new HSSFClientAnchor(0, 0, 0, 0, (short)1, 16, (short)3, 22);
				HSSFTextbox textbox6 = hssfPatriarch.createTextbox(anchor6);		
				textbox6.setLineStyleColor(0, 0, 255);
				textbox6.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox6.setLineStyle(HSSFShape.LINESTYLE_DASHGEL);
				
				// 形状在sheet中的锚点位置
				HSSFClientAnchor anchor7 = new HSSFClientAnchor(0, 0, 0, 0, (short)4, 16, (short)6, 22);
				HSSFTextbox textbox7 = hssfPatriarch.createTextbox(anchor7);
				textbox7.setLineStyleColor(0, 0, 255);
				textbox7.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox7.setLineStyle(HSSFShape.LINESTYLE_LONGDASHGEL);
				
				HSSFClientAnchor anchor8 = new HSSFClientAnchor(0, 0, 0, 0, (short)7, 16, (short)9, 22);
				HSSFTextbox textbox8 = hssfPatriarch.createTextbox(anchor8);
				textbox8.setLineStyleColor(0, 0, 255);
				textbox8.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox8.setLineStyle(HSSFShape.LINESTYLE_DASHDOTGEL);
				
				HSSFClientAnchor anchor9 = new HSSFClientAnchor(0, 0, 0, 0, (short)10, 16, (short)12, 22);
				HSSFTextbox textbox9 = hssfPatriarch.createTextbox(anchor9);
				textbox9.setLineStyleColor(0, 0, 255);
				textbox9.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox9.setLineStyle(HSSFShape.LINESTYLE_LONGDASHDOTGEL);
				
				HSSFClientAnchor anchor10 = new HSSFClientAnchor(0, 0, 0, 0, (short)13, 16, (short)15, 22);
				HSSFTextbox textbox10 = hssfPatriarch.createTextbox(anchor10);
				textbox10.setLineStyleColor(0, 0, 255);
				textbox10.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox10.setLineStyle(HSSFShape.LINESTYLE_LONGDASHDOTDOTGEL);
				
				// 无边框
				HSSFClientAnchor anchor11 = new HSSFClientAnchor(0, 0, 0, 0, (short)16, 16, (short)18, 22);
				HSSFTextbox textbox11 = hssfPatriarch.createTextbox(anchor11);
				textbox11.setLineStyleColor(0, 0, 255);
				textbox11.setLineWidth(3 * HSSFShape.LINEWIDTH_ONE_PT);
				textbox11.setLineStyle(HSSFShape.LINESTYLE_NONE);
				
				FileOutputStream file = new FileOutputStream("C://Users//Administrator//Desktop//test.xls");
				workbook.write(file);
				file.close();
	}

}
结果



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在I中,可以使用 `HFSimpleShape` 类来入带箭头的条。下面是示例代码: ```java import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.*; public class ArrowLineExample { public static void main(String[] args) throws Exception { // 创建工作簿和工作表 HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Sheet1"); // 创建画布和绘制器 HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 0, 0, (short) 10, 10); HSSFSimpleShape shape = patriarch.createSimpleShape(anchor); // 设置线条属性 shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); shape.setLineStyleColor(0, 0, 0); shape.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT); shape.setLineStyle(HSSFShape.LINESTYLE_SOLID); // 设置箭头属性 shape.setArrowStyle(HSSFSimpleShape.ARROW_ARROW); shape.setArrowWidth(HSSFShape.ARROW_WIDTH_NARROW); shape.setArrowHeight(HSSFShape.ARROW_HEIGHT_MEDIUM); // 输出到文件 FileOutputStream fileOut = new FileOutputStream("ArrowLineExample.xls"); workbook.write(fileOut); fileOut.close(); } } ``` 在这个示例中,我们创建了一个带箭头的线条,并将其插入到了工作表中。具体实现步骤如下: 1. 创建工作簿和工作表。 2. 创建画布和绘制器,并设置绘制范围。 3. 创建 `HSSFSimpleShape` 对象,并设置线条属性。 4. 设置箭头属性。 5. 将绘制的对象输出到文件中。 你可以根据需要修改线条和箭头的属性,以实现你想要的效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值