本文整理汇总了Java中org.apache.poi.ss.usermodel.Drawing类的典型用法代码示例。如果您正苦于以下问题:Java Drawing类的具体用法?Java Drawing怎么用?Java Drawing使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Drawing类属于org.apache.poi.ss.usermodel包,在下文中一共展示了Drawing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDefaultLogo
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* @작성자 : KYJ
* @작성일 : 2016. 9. 9.
* @param sheet
* @throws Exception
*/
final static void createDefaultLogo(Sheet sheet) throws Exception {
Workbook workbook = sheet.getWorkbook();
byte[] defaultLogoImage = getDefaultLogoImage();
if(defaultLogoImage == null)
return;
int pictureIdx = workbook.addPicture(defaultLogoImage, Workbook.PICTURE_TYPE_PNG);
CreationHelper creationHelper = workbook.getCreationHelper();
ClientAnchor anchor = creationHelper.createClientAnchor(); //new XSSFClientAnchor();
// anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
Drawing createDrawingPatriarch = sheet.createDrawingPatriarch();
anchor.setDx1(0);
anchor.setCol1(0);
anchor.setRow1(0);
//#1 테이블 셀의 너비에 의존적이지않게 사이즈조절.
anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
Picture createPicture = createDrawingPatriarch.createPicture(anchor, pictureIdx);
//#2 테이블 셀의 너비에 의존적이지않게 사이즈조절.
createPicture.resize();
}
示例2: setComment
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* See the comment for the given cell
*
* @param cell
* the cell
* @param message
* the comment message
*/
public static void setComment(HSSFCell cell, String message) {
Drawing drawing = cell.getSheet().createDrawingPatriarch();
CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(cell.getRowIndex());
anchor.setRow2(cell.getRowIndex() + 1);
anchor.setDx1(100);
anchor.setDx2(1000);
anchor.setDy1(100);
anchor.setDy2(1000);
// Create the comment and set the text+author
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString(message);
comment.setString(str);
comment.setAuthor("TURNUS");
// Assign the comment to the cell
cell.setCellComment(comment);
}
示例3: buildExcelChart
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* 构建多个图形对象
* @param dataSourceSheet
* @param tragetSheet
* @param graphList
*/
private static void buildExcelChart(Sheet dataSourceSheet, Sheet tragetSheet,
List<ExcelGraph> graphList) {
int len = graphList.size();
if (len == 1) {
buildExcelChart(dataSourceSheet, tragetSheet, graphList.get(0));
} else {
int drawStart = 0;
int drawEnd = 20;
Drawing drawing = tragetSheet.createDrawingPatriarch();
for (int i = 0; i < len; i++) {
ExcelGraph graph = graphList.get(i);
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, drawStart, 15, drawEnd);
buildExcelChart(drawing, anchor, dataSourceSheet, graph);
drawStart = drawStart + drawEnd;
drawEnd = drawEnd + drawEnd;
}
}
}
示例4: createListCells
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* 创建List之后的各个Cells
*
* @param styles
*/
public void createListCells(Drawing patriarch, int index, int cellNum, Object obj,
List<ExcelExportEntity> excelParams, Sheet sheet, Workbook workbook)
throws Exception {
ExcelExportEntity entity;
Row row;
if (sheet.getRow(index) == null) {
row = sheet.createRow(index);
row.setHeight(getRowHeight(excelParams));
} else {
row = sheet.getRow(index);
}
for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
entity = excelParams.get(k);
Object value = getCellValue(entity, obj);
if (entity.getType() == 1) {
createStringCell(row, cellNum++, value == null ? "" : value.toString(),
row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity);
} else {
createImageCell(patriarch, entity, row, cellNum++,
value == null ? "" : value.toString(), obj);
}
}
}
示例5: createCellComment
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
private Comment createCellComment(String author, String comment) {
// comments only supported for XLSX
if (data.sheet instanceof XSSFSheet) {
CreationHelper factory = data.wb.getCreationHelper();
Drawing drawing = data.sheet.createDrawingPatriarch();
ClientAnchor anchor = factory.createClientAnchor();
Comment cmt = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString(comment);
cmt.setString(str);
cmt.setAuthor(author);
return cmt;
}
return null;
}
示例6: createCellComment
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
private Comment createCellComment( String author, String comment ) {
// comments only supported for XLSX
if ( data.sheet instanceof XSSFSheet ) {
CreationHelper factory = data.wb.getCreationHelper();
Drawing drawing = data.sheet.createDrawingPatriarch();
ClientAnchor anchor = factory.createClientAnchor();
Comment cmt = drawing.createCellComment( anchor );
RichTextString str = factory.createRichTextString( comment );
cmt.setString( str );
cmt.setAuthor( author );
return cmt;
}
return null;
}
示例7: extractPicturePortion
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* 抽象出图片生成业务代码
*
* @throws IOException
*/
private void extractPicturePortion(String svgString, XSSFWorkbook wb,
XSSFSheet sheet, int startCol, int endCol, int startRow, int endRow)
throws IOException {
// 图片
if (org.apache.commons.lang3.StringUtils.isNotBlank(svgString)) {
byte[] safeDataBytes = new BASE64Decoder().decodeBuffer(svgString);
int pictureIdx = wb.addPicture(safeDataBytes,
Workbook.PICTURE_TYPE_JPEG);
CreationHelper helper = wb.getCreationHelper();
// Create the drawing patriarch. This is the top level container for
// all shapes.
Drawing drawing = sheet.createDrawingPatriarch();
// add a picture shape
ClientAnchor anchor = helper.createClientAnchor();
// set top-left corner of the picture,
// subsequent call of Picture#resize() will operate relative to it
anchor.setCol1(startCol);
anchor.setCol2(endCol);
anchor.setRow1(startRow);
anchor.setRow2(endRow);
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(0);
anchor.setDy2(0);
anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize(1);
}
}
示例8: createListCells
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* 创建List之后的各个Cells
* @param patriarch
* @param index
* @param cellNum
* @param obj
* @param excelParams
* @param sheet
* @param workbook
* @throws Exception
*/
public void createListCells(Drawing patriarch, int index, int cellNum, Object obj,
List<ExcelExportEntity> excelParams, Sheet sheet,
Workbook workbook) throws Exception {
ExcelExportEntity entity;
Row row;
if (sheet.getRow(index) == null) {
row = sheet.createRow(index);
row.setHeight(getRowHeight(excelParams));
} else {
row = sheet.getRow(index);
}
for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
entity = excelParams.get(k);
Object value = getCellValue(entity, obj);
if (entity.getType() == BaseEntityTypeConstants.StringType) {
createStringCell(row, cellNum++, value == null ? "" : value.toString(),
row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity);
if (entity.isHyperlink()) {
row.getCell(cellNum - 1)
.setHyperlink(dataHanlder.getHyperlink(
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(),
value));
}
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) {
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity);
if (entity.isHyperlink()) {
row.getCell(cellNum - 1)
.setHyperlink(dataHanlder.getHyperlink(
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(),
value));
}
} else {
createImageCell(patriarch, entity, row, cellNum++,
value == null ? "" : value.toString(), obj);
}
}
}
示例9: addDataToSheet
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* 往Sheet 填充正常数据,根据表头信息 使用导入的部分逻辑,坐对象映射
*
* @param sheet
* @param pojoClass
* @param dataSet
* @param workbook
*/
private void addDataToSheet(Class<?> pojoClass, Collection<?> dataSet, Sheet sheet,
Workbook workbook) throws Exception {
if (workbook instanceof XSSFWorkbook) {
super.type = ExcelType.XSSF;
}
// 获取表头数据
Map<String, Integer> titlemap = getTitleMap(sheet);
Drawing patriarch = sheet.createDrawingPatriarch();
// 得到所有字段
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
String targetId = null;
if (etarget != null) {
targetId = etarget.value();
}
// 获取实体对象的导出数据
List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>();
getAllExcelField(null, targetId, fileds, excelParams, pojoClass, null);
// 根据表头进行筛选排序
sortAndFilterExportField(excelParams, titlemap);
short rowHeight = getRowHeight(excelParams);
int index = teplateParams.getHeadingRows() + teplateParams.getHeadingStartRow(),
titleHeight = index;
//下移数据,模拟插入
sheet.shiftRows(teplateParams.getHeadingRows() + teplateParams.getHeadingStartRow(),
sheet.getLastRowNum(), getShiftRows(dataSet, excelParams), true, true);
if (excelParams.size() == 0) {
return;
}
Iterator<?> its = dataSet.iterator();
while (its.hasNext()) {
Object t = its.next();
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight);
}
// 合并同类项
mergeCells(sheet, excelParams, titleHeight);
}
示例10: addDataToSheet
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* 往Sheet 填充正常数据,根据表头信息 使用导入的部分逻辑,坐对象映射
*
* @param teplateParams
* @param pojoClass
* @param dataSet
* @param workbook
*/
private void addDataToSheet(Class<?> pojoClass, Collection<?> dataSet, Sheet sheet,
Workbook workbook) throws Exception {
if (workbook instanceof XSSFWorkbook) {
super.type = ExcelType.XSSF;
}
// 获取表头数据
Map<String, Integer> titlemap = getTitleMap(sheet);
Drawing patriarch = sheet.createDrawingPatriarch();
// 得到所有字段
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
String targetId = null;
if (etarget != null) {
targetId = etarget.value();
}
// 获取实体对象的导出数据
List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>();
getAllExcelField(null, targetId, fileds, excelParams, pojoClass, null);
// 根据表头进行筛选排序
sortAndFilterExportField(excelParams, titlemap);
short rowHeight = getRowHeight(excelParams);
int index = teplateParams.getHeadingRows() + teplateParams.getHeadingStartRow(), titleHeight = index;
//下移数据,模拟插入
sheet.shiftRows(teplateParams.getHeadingRows() + teplateParams.getHeadingStartRow(),
sheet.getLastRowNum(), getShiftRows(dataSet, excelParams), true, true);
if (excelParams.size() == 0) {
return;
}
Iterator<?> its = dataSet.iterator();
while (its.hasNext()) {
Object t = its.next();
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight);
}
// 合并同类项
mergeCells(sheet, excelParams, titleHeight);
}
示例11: addChart
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
protected void addChart(HSSFWorkbook workbook, byte[] chart, String name) {
int pictureIndex = workbook.addPicture(chart, HSSFWorkbook.PICTURE_TYPE_PNG);
HSSFSheet sheet = workbook.createSheet(name);
addTitle(sheet, name, 0);
Drawing drawing = sheet.createDrawingPatriarch();
CreationHelper helper = workbook.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setRow1(1);
anchor.setCol1(0);
Picture picture = drawing.createPicture(anchor, pictureIndex);
picture.resize();
}
示例12: main
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithworkbook/addimages/data/";
//create a new workbook
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
//add picture data to this workbook.
InputStream is = new FileInputStream(dataPath + "aspose.jpg");
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
CreationHelper helper = wb.getCreationHelper();
//create sheet
Sheet sheet = wb.createSheet();
// Create the drawing patriarch. This is the top level container for all shapes.
Drawing drawing = sheet.createDrawingPatriarch();
//add a picture shape
ClientAnchor anchor = helper.createClientAnchor();
//set top-left corner of the picture,
//subsequent call of Picture#resize() will operate relative to it
anchor.setCol1(3);
anchor.setRow1(2);
Picture pict = drawing.createPicture(anchor, pictureIdx);
//auto-size picture relative to its top-left corner
pict.resize();
//save workbook
String file = dataPath + "ApacheImage.xls";
if(wb instanceof XSSFWorkbook) file += "x";
FileOutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.close();
System.out.println("Done...");
}
示例13: createDrawing
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* Returns the <code>Sheet's</code> <code>Drawing</code> object, creating it
* if it doesn't exist. It is hoped that this would be replaced by a call
* to <code>getDrawingPatriarch</code> in the POI "ss" package, and that
* that call would NOT corrupt drawings, charts, etc.
* @return A <code>Drawing</code>.
* @since 0.2.0
*/
public Drawing createDrawing()
{
if (myDrawing == null)
{
myDrawing = mySheet.createDrawingPatriarch();
}
return myDrawing;
}
示例14: writeHeader
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
protected void writeHeader(Sheet sheet, Drawing drawing, Row nameRow, Row labelRow, int i, ExcelColumn column, CellStyle boldStyle)
{
CreationHelper helper = sheet.getWorkbook().getCreationHelper();
// Notify the listeners
for (ExcelExportListener listener : listeners)
{
listener.preHeader(column);
}
nameRow.createCell(i).setCellValue(helper.createRichTextString(column.getAttributeName()));
Cell cell = labelRow.createCell(i);
cell.setCellValue(helper.createRichTextString(column.getDisplayLabel()));
if (column.isRequired() && boldStyle != null)
{
cell.setCellStyle(boldStyle);
}
if (column.getDescription() != null && column.getDescription().length() > 0)
{
ClientAnchor anchor = helper.createClientAnchor();
anchor.setDx1(0);
anchor.setDy1(0);
anchor.setDx2(0);
anchor.setDy2(0);
anchor.setCol1(0);
anchor.setRow1(0);
anchor.setCol2(0);
anchor.setRow2(4);
Comment comment = drawing.createCellComment(anchor);
comment.setString(helper.createRichTextString(column.getDescription()));
cell.setCellComment(comment);
}
sheet.autoSizeColumn((short) i);
}
示例15: createCells
import org.apache.poi.ss.usermodel.Drawing; //导入依赖的package包/类
/**
* 创建 最主要的 Cells
*
* @param styles
* @param rowHeight
* @throws Exception
*/
public int createCells(Drawing patriarch, int index, Object t,
List<ExcelExportEntity> excelParams, Sheet sheet, Workbook workbook,
short rowHeight) throws Exception {
ExcelExportEntity entity;
Row row = sheet.createRow(index);
row.setHeight(rowHeight);
int maxHeight = 1, cellNum = 0;
int indexKey = createIndexCell(row, index, excelParams.get(0));
cellNum += indexKey;
for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) {
entity = excelParams.get(k);
if (entity.getList() != null) {
Collection<?> list = getListCellValue(entity, t);
int listC = 0;
for (Object obj : list) {
createListCells(patriarch, index + listC, cellNum, obj, entity.getList(),
sheet, workbook);
listC++;
}
cellNum += entity.getList().size();
if (list != null && list.size() > maxHeight) {
maxHeight = list.size();
}
} else {
Object value = getCellValue(entity, t);
if (entity.getType() == 1) {
createStringCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity);
} else {
createImageCell(patriarch, entity, row, cellNum++,
value == null ? "" : value.toString(), t);
}
}
}
// 合并需要合并的单元格
cellNum = 0;
for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) {
entity = excelParams.get(k);
if (entity.getList() != null) {
cellNum += entity.getList().size();
} else if (entity.isNeedMerge()) {
for (int i = index + 1; i < index + maxHeight; i++) {
sheet.getRow(i).createCell(cellNum);
sheet.getRow(i).getCell(cellNum).setCellStyle(getStyles(false, entity));
}
sheet.addMergedRegion(new CellRangeAddress(index, index + maxHeight - 1, cellNum,
cellNum));
cellNum++;
}
}
return maxHeight;
}