List of usage examples for org.apache.poi.xwpf.usermodel XWPFTableRow setHeight
public void setHeight(int height)
From source file:cn.afterturn.easypoi.word.parse.excel.ExcelEntityParse.java
License:Apache License
private int createCells(int index, Object t, List<ExcelExportEntity> excelParams, XWPFTable table, short rowHeight) { try {/*from www . j av a 2 s .c o m*/ ExcelExportEntity entity; XWPFTableRow row = table.insertNewTableRow(index); if (rowHeight != -1) { row.setHeight(rowHeight); } int maxHeight = 1, cellNum = 0; for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { Collection<?> list = (Collection<?>) entity.getMethod().invoke(t, new Object[] {}); int listC = 0; for (Object obj : list) { createListCells(index + listC, cellNum, obj, entity.getList(), table, rowHeight); listC++; } cellNum += entity.getList().size(); if (list != null && list.size() > maxHeight) { maxHeight = list.size(); } } else { Object value = getCellValue(entity, t); if (entity.getType() == 1) { setCellValue(row, value, cellNum++); } } } // ???? cellNum = 0; for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { cellNum += entity.getList().size(); } else if (entity.isNeedMerge() && maxHeight > 1) { table.setCellMargins(index, index + maxHeight - 1, cellNum, cellNum); cellNum++; } } return maxHeight; } catch (Exception e) { LOGGER.error("excel cell export error ,data is :{}", ReflectionToStringBuilder.toString(t)); throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e); } }
From source file:cn.afterturn.easypoi.word.parse.excel.ExcelEntityParse.java
License:Apache License
/** * List??Cells// ww w . j a v a2s. co m * * @param index * @param cellNum * @param obj ? * @param excelParams ?? * @param table ? * @param rowHeight * @throws Exception */ public void createListCells(int index, int cellNum, Object obj, List<ExcelExportEntity> excelParams, XWPFTable table, short rowHeight) throws Exception { ExcelExportEntity entity; XWPFTableRow row; if (table.getRow(index) == null) { row = table.createRow(); row.setHeight(rowHeight); } else { row = table.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) { setCellValue(row, value, cellNum++); } } }
From source file:com.qihang.winter.poi.word.parse.excel.ExcelEntityParse.java
License:Apache License
private int createCells(int index, Object t, List<com.qihang.winter.poi.excel.entity.params.ExcelExportEntity> excelParams, XWPFTable table, short rowHeight) throws Exception { com.qihang.winter.poi.excel.entity.params.ExcelExportEntity entity; XWPFTableRow row = table.createRow(); row.setHeight(rowHeight); int maxHeight = 1, cellNum = 0; for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k);//from w w w. j av a 2 s . co m if (entity.getList() != null) { Collection<?> list = (Collection<?>) entity.getMethod().invoke(t, new Object[] {}); int listC = 0; for (Object obj : list) { createListCells(index + listC, cellNum, obj, entity.getList(), table); listC++; } cellNum += entity.getList().size(); if (list != null && list.size() > maxHeight) { maxHeight = list.size(); } } else { Object value = getCellValue(entity, t); if (entity.getType() == 1) { setCellValue(row, value, cellNum++); } } } // ???? cellNum = 0; for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { entity = excelParams.get(k); if (entity.getList() != null) { cellNum += entity.getList().size(); } else if (entity.isNeedMerge()) { table.setCellMargins(index, index + maxHeight - 1, cellNum, cellNum); cellNum++; } } return maxHeight; }
From source file:com.qihang.winter.poi.word.parse.excel.ExcelEntityParse.java
License:Apache License
/** * List??Cells// w w w .ja va 2 s . c o m * * @param styles */ public void createListCells(int index, int cellNum, Object obj, List<com.qihang.winter.poi.excel.entity.params.ExcelExportEntity> excelParams, XWPFTable table) throws Exception { com.qihang.winter.poi.excel.entity.params.ExcelExportEntity entity; XWPFTableRow row; if (table.getRow(index) == null) { row = table.createRow(); row.setHeight(getRowHeight(excelParams)); } else { row = table.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) { setCellValue(row, value, cellNum++); } } }
From source file:MainPackage.Controllers.OrderController.java
public void Print(Frame frame, Orders order, Account _account) { try {/*from w w w. java 2 s.c o m*/ XWPFDocument document = new XWPFDocument(); File file = new File("Ha n " + order.getIdCode() + ".doc"); if (file.exists()) { file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); XWPFParagraph paragraph = document.createParagraph(); paragraph.setAlignment(ParagraphAlignment.CENTER); XWPFRun run; // BookViewModel bookView = new BookViewModel(book); ///////////////// run = createFieldRun(paragraph, "CHI TIT HA ?N"); run.setFontSize(24); paragraph = createPrintInformation(document, _account); paragraph = createBookProductInformation(document, order); paragraph = createBookInformation(document, order); //create table XWPFTable table = document.createTable(); setTableAlignment(table, STJc.CENTER); table.setCellMargins(50, 50, 50, 50); table.setInsideHBorder(XWPFTable.XWPFBorderType.SINGLE, 10, 10, ""); table.setInsideVBorder(XWPFTable.XWPFBorderType.NONE, 20, 20, ""); //create first row XWPFTableRow row = table.getRow(0); row.setHeight(40); row.getCell(0).setText("STT"); row.addNewTableCell().setText("M Sn phm"); row.addNewTableCell().setText("Tn Sn phm"); row.addNewTableCell().setText("?n v"); row.addNewTableCell().setText("S lng"); row.addNewTableCell().setText("Gi ti?n"); row.addNewTableCell().setText("Thnh ti?n"); List<OrderLine> list = (List<OrderLine>) order.getOrderLineCollection(); for (int i = 0; i < list.size(); i++) { OrderLine line = list.get(i); row = table.createRow(); row.getCell(0).setText((i + 1) + ""); row.getCell(1).setText(line.getProductId().getIdCode()); row.getCell(2).setText(line.getProductId().getName()); row.getCell(3).setText("Quyn "); row.getCell(4).setText(line.getQuantity() + " "); row.getCell(5).setText(IntToVND(line.getUnitPrice()) + " "); row.getCell(6).setText(IntToVND(line.getTotalPrice()) + " "); } document.write(out); out.close(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(file); } JOptionPane .showMessageDialog(frame, "Xut file " + file.getName() + " thnh cng" + '\n' + "Ti v tr: " + file.getAbsolutePath(), "In thng tin Ha n", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { System.out.println(e); JOptionPane.showMessageDialog(frame, "Xut file tht bi." + '\n' + "Vui lng ng ca s ang s dng file", "In thng tin Ha n", JOptionPane.WARNING_MESSAGE); } }