use of org.apache.poi.hssf.usermodel.HSSFPatriarch in project poi by apache.
the class TestDrawingShapes method testAllocateNewIds.
/**
* Test get new id for shapes from existing file
* File already have for 1 shape on each sheet, because document must contain EscherDgRecord for each sheet
*/
@Test
public void testAllocateNewIds() throws IOException {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("empty.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFPatriarch patriarch = sheet.getDrawingPatriarch();
/**
* 2048 - main SpContainer id
* 2049 - existing shape id
*/
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 2050);
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 2051);
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 2052);
sheet = wb.getSheetAt(1);
patriarch = sheet.getDrawingPatriarch();
/**
* 3072 - main SpContainer id
* 3073 - existing shape id
*/
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 3074);
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 3075);
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 3076);
sheet = wb.getSheetAt(2);
patriarch = sheet.getDrawingPatriarch();
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1026);
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1027);
assertEquals(HSSFTestHelper.allocateNewShapeId(patriarch), 1028);
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFPatriarch in project poi by apache.
the class TestDrawingShapes method testDgRecordNumShapes.
@Test
public void testDgRecordNumShapes() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
EscherAggregate aggregate = HSSFTestHelper.getEscherAggregate(patriarch);
EscherDgRecord dgRecord = (EscherDgRecord) aggregate.getEscherRecord(0).getChild(0);
assertEquals(dgRecord.getNumShapes(), 1);
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFPatriarch in project poi by apache.
the class TestDrawingShapes method testClearShapesForPatriarch.
@Test
public void testClearShapesForPatriarch() throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet sheet = wb1.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
patriarch.createSimpleShape(new HSSFClientAnchor());
patriarch.createSimpleShape(new HSSFClientAnchor());
patriarch.createCellComment(new HSSFClientAnchor());
EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch);
assertEquals(agg.getShapeToObjMapping().size(), 6);
assertEquals(agg.getTailRecords().size(), 1);
assertEquals(patriarch.getChildren().size(), 3);
patriarch.clear();
assertEquals(agg.getShapeToObjMapping().size(), 0);
assertEquals(agg.getTailRecords().size(), 0);
assertEquals(patriarch.getChildren().size(), 0);
HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
sheet = wb2.getSheetAt(0);
patriarch = sheet.getDrawingPatriarch();
assertEquals(agg.getShapeToObjMapping().size(), 0);
assertEquals(agg.getTailRecords().size(), 0);
assertEquals(patriarch.getChildren().size(), 0);
wb2.close();
}
use of org.apache.poi.hssf.usermodel.HSSFPatriarch in project poi by apache.
the class TestDrawingShapes method testCorrectOrderInOptRecord.
@Test
public void testCorrectOrderInOptRecord() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFTextbox textbox = patriarch.createTextbox(new HSSFClientAnchor());
EscherOptRecord opt = HSSFTestHelper.getOptRecord(textbox);
String opt1Str = opt.toXml();
textbox.setFillColor(textbox.getFillColor());
EscherContainerRecord container = HSSFTestHelper.getEscherContainer(textbox);
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineStyle(textbox.getLineStyle());
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineWidth(textbox.getLineWidth());
assertEquals(opt1Str, optRecord.toXml());
textbox.setLineStyleColor(textbox.getLineStyleColor());
assertEquals(opt1Str, optRecord.toXml());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFPatriarch in project adempiere by adempiere.
the class SmjXlsReport method generate.
public HSSFWorkbook generate(LinkedList<ReportTO> data, String[] generalTitle, String clientName, String clientNIT, String periodName, String currencyName, MReportColumn[] m_columns, String city, Integer logoId) {
int fila = 0;
HSSFRow row;
cols = m_columns.length + 2;
endRegion = (short) (cols - 1);
try {
// create workbook
HSSFWorkbook book = new HSSFWorkbook();
// crea hoja - create sheet
// Goodwill BF: Invalid sheet name
HSSFSheet sheet = book.createSheet(StringUtils.makePrefix(generalTitle[0]));
// crea fuente - Create Font
HSSFFont font = book.createFont();
font.setFontHeightInPoints((short) 13);
font.setFontName(HSSFFont.FONT_ARIAL);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// estio celda - cell style
HSSFCellStyle cellStyle = book.createCellStyle();
cellStyle.setWrapText(true);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyle.setFont(font);
// add logo
if (logoId > 0) {
MImage mimage = MImage.get(Env.getCtx(), logoId);
byte[] imageData = mimage.getData();
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFClientAnchor anchor;
anchor = new HSSFClientAnchor(100, 50, 200, 255, (short) 0, 0, (short) 1, 1);
anchor.setAnchorType(2);
int pictureIndex = book.addPicture(imageData, HSSFWorkbook.PICTURE_TYPE_PNG);
patriarch.createPicture(anchor, pictureIndex);
for (int i = 0; i < 5; i++) row = sheet.createRow(fila++);
}
//if Logo report
// Titulo General - general Title
row = sheet.createRow(fila++);
HSSFRichTextString text = new HSSFRichTextString(generalTitle[0]);
HSSFCell cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
Region region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// empresa - Company
row = sheet.createRow(fila++);
text = new HSSFRichTextString(clientName);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// Ciudad - City
row = sheet.createRow(fila++);
text = new HSSFRichTextString(city);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// NIT
row = sheet.createRow(fila++);
text = new HSSFRichTextString(clientNIT);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// periodo - Period
String pn = "";
if (generalTitle[1] != null && generalTitle[1].length() > 0) {
pn = generalTitle[1] + " " + periodName;
} else {
pn = periodName;
}
if (generalTitle[2] != null && generalTitle[2].length() > 0) {
pn = pn + " " + generalTitle[2];
}
row = sheet.createRow(fila++);
text = new HSSFRichTextString(pn);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
// tipo moneda - currency
row = sheet.createRow(fila++);
text = new HSSFRichTextString(currencyName);
cell = row.createCell((short) 0);
cell.setCellStyle(cellStyle);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(text);
region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
row = sheet.createRow(fila++);
titleTable(book, sheet, fila++, m_columns);
// llena datos del reporte - fill data report
reportTable(book, data, sheet, fila);
return book;
} catch (Exception e) {
e.printStackTrace();
return null;
}
//try/catch
}
Aggregations