`
defrag_sly
  • 浏览: 131336 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

操作excel--稍后整理

    博客分类:
  • java
阅读更多
OfficeDrawingWithGraphics


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.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class Line {

/**
* @param args
*/
public static void main(String[] args) {
FileOutputStream fileOut = null;

try {

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");

// HSSFRow row = sheet1.createRow(2);
HSSFPatriarch patriarch = sheet1.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0,
(short) 10, 10, (short) 20, 20);

HSSFShapeGroup g = patriarch.createGroup(anchor);
g.setCoordinates(0, 0, 100, 100);
HSSFChildAnchor lAnchor = new HSSFChildAnchor(0, 100, 100, 0);
g.createShape(lAnchor);
int length = 6;
Math.abs(lAnchor.getDy1() - Math.sin(30 * Math.PI / 180) * length);
Math.abs(lAnchor.getDx1() - Math.cos(30 * Math.PI / 180) * length);
Math.abs(lAnchor.getDy1() - Math.sin(60 * Math.PI / 180) * length);
Math.abs(lAnchor.getDx1() - Math.cos(60 * Math.PI / 180) * length);

Math.abs(lAnchor.getDy2() - Math.sin(30 * Math.PI / 180) * length);
Math.abs(lAnchor.getDx2() - Math.cos(30 * Math.PI / 180) * length);
Math.abs(lAnchor.getDy2() - Math.sin(60 * Math.PI / 180) * length);
Math.abs(lAnchor.getDx2() - Math.cos(60 * Math.PI / 180) * length);

// Math.sin(60 * Math.PI / 180)*length;
// Math.cos(60 * Math.PI / 180)*length;
HSSFChildAnchor al = new HSSFChildAnchor(lAnchor.getDx1(), lAnchor
.getDy1(), (int) Math.abs(lAnchor.getDx1()
- Math.cos(30 * Math.PI / 180) * length), (int) Math
.abs(lAnchor.getDy1() - Math.sin(30 * Math.PI / 180)
* length));
HSSFChildAnchor ar = new HSSFChildAnchor(lAnchor.getDx1(), lAnchor
.getDy1(), (int) Math.abs(lAnchor.getDx1()
- Math.cos(60 * Math.PI / 180) * length), (int) Math
.abs(lAnchor.getDy1() - Math.sin(60 * Math.PI / 180)
* length));

HSSFChildAnchor atl = new HSSFChildAnchor(lAnchor.getDx2(), lAnchor
.getDy2(), (int) Math.abs(lAnchor.getDx2()
- Math.cos(30 * Math.PI / 180) * length), (int) Math
.abs(lAnchor.getDy2() - Math.sin(30 * Math.PI / 180)
* length));
HSSFChildAnchor atr = new HSSFChildAnchor(lAnchor.getDx2(), lAnchor
.getDy2(), (int) Math.abs(lAnchor.getDx2()
- Math.cos(60 * Math.PI / 180) * length), (int) Math
.abs(lAnchor.getDy2() - Math.sin(60 * Math.PI / 180)
* length));

g.createShape(al);
g.createShape(ar);
g.createShape(atl);
g.createShape(atr);

fileOut = new FileOutputStream("d:/workbook.xls");

wb.write(fileOut);
fileOut.close();

} catch (IOException io) {
io.printStackTrace();
System.out.println("io erorr :  " + io.getMessage());
} finally {
if (fileOut != null) {

try {
fileOut.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

}










import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFTextbox;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

;

public class TestPOI {

public static void main(String[] args) {
FileOutputStream fileOut = null;
BufferedImage bufferImg = null;
BufferedImage bufferImg1 = null;
try {

// 先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream();
bufferImg = ImageIO.read(new File("d:/Control_Treeview.jpg"));
bufferImg1 = ImageIO.read(new File("d:/Control_Treeview.jpg"));
ImageIO.write(bufferImg, "jpg", byteArrayOut);
ImageIO.write(bufferImg1, "jpg", byteArrayOut1);

// 创建一个工作薄
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("new sheet");
// HSSFRow row = sheet1.createRow(2);
HSSFPatriarch patriarch = sheet1.createDrawingPatriarch();
HSSFClientAnchor anchor3 = new HSSFClientAnchor(0, 0, 512, 255,
(short) 1, 1, (short) 10, 20);
HSSFClientAnchor anchor1 = new HSSFClientAnchor(0, 0, 512, 255,
(short) 2, 30, (short) 10, 60);
anchor1.setAnchorType(2);
// HSSFClientAnchor anchor3 = new
// HSSFClientAnchor(0,0,512,255,(short) 1,1,(short)10,20);
// 插入图片

patriarch.createPicture(anchor3, wb.addPicture(byteArrayOut
.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
patriarch.createPicture(anchor3, wb.addPicture(byteArrayOut1
.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
HSSFTextbox createComment = patriarch.createTextbox(anchor3);
createComment.setString(new HSSFRichTextString("aaaaaaaaa"));
patriarch.createSimpleShape(anchor3);

fileOut = new FileOutputStream("d:/workbook.xls");
// 写入excel文件
wb.write(fileOut);
fileOut.close();

} catch (IOException io) {
io.printStackTrace();
System.out.println("io erorr :  " + io.getMessage());
} finally {
if (fileOut != null) {

try {
fileOut.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
分享到:
评论
1 楼 xinxinlong 2013-07-18  
lAnchor.getDy1() 是什么意思

相关推荐

    中小学简易成绩管理系统(excel)

    本作品采用EXCEL 公式+VBA制作,既可根据你平时使用EXCEL的习惯和方式操作充分发挥EXCEL的功能,又能利用本作品提高效率。 结构紧凑,界面简洁 本作品工作表个数极少,分别是总表、表册、设置。你可以先在总表输入、...

    excel2021双向条形图制作方法.docx

    1. **准备工作**: 首先,你需要整理好数据,确保数据已经按照你想要展示的方式排列在 Excel 工作表的不同列中。双向条形图通常会有一列共享的分类轴,而两列数值数据分别对应正向和负向的条形。 2. **选中工作区域*...

    中小学简易成绩分析系统

    本作品采用EXCEL 公式+VBA制作,既可根据你平时使用EXCEL的习惯和方式操作充分发挥EXCEL的功能,又能利用本作品提高效率。 2、 结构紧凑,界面简洁 本作品工作表个数极少,分别是总表、表册、设置。你可以先在总表...

    Link Saver-crx插件

    **Link Saver-crx插件详解** Link Saver是一款针对Chrome浏览器设计的扩展程序,它主要功能是帮助用户管理和保存网页链接。...通过它的简单操作,用户可以更有效地整理和利用网络资源,提升工作和学习的效率。

    2014华师在线计算机基础作业及答案.pdf

    包括计算机应用、网络安全、多媒体技术、网络设备、搜索引擎技巧、电子邮件管理、计算机硬件历史、操作系统功能、计算机系统结构、数字转换、病毒行为、信息表示、Word编辑操作、键盘快捷键、Excel格式对齐、安全...

    poi实现合并word文档共4页.pdf.zip

    总的来说,Apache POI的使用能够帮助Java开发者高效地处理和操作Office文档,而将Word文档合并成PDF则是一种常见的需求,特别是在需要整理和汇总信息的场合。这个压缩包提供的资源可能就是一个完整的解决方案,包括...

Global site tag (gtag.js) - Google Analytics