List of usage examples for org.apache.poi.ss.usermodel Workbook createSheet
Sheet createSheet();
From source file:hjow.hgtable.util.XLSXUtil.java
License:Apache License
/** * <p>? ? XLSX ? ? .</p>/* w w w .j a va 2 s.c o m*/ * * @param tableSet : ? ? * @param file : ? ? */ public static void save(TableSet tableSet, File file) { org.apache.poi.ss.usermodel.Workbook workbook = null; if (file == null) throw new NullPointerException(Manager.applyStringTable("Please select file !!")); FileOutputStream fileStream = null; ChainOutputStream chainStream = null; try { String targetPath = StreamUtil.getDirectoryPathOfFile(file); File dir = new File(targetPath); // Main.println(dir); if (!dir.exists()) dir.mkdir(); } catch (Throwable e) { Main.logError(e, "On mkdir on saving xlsx"); } try { fileStream = new FileOutputStream(file); chainStream = new ChainOutputStream(fileStream); StreamUtil.additionalSetting(chainStream); workbook = new org.apache.poi.xssf.streaming.SXSSFWorkbook(); // workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(); org.apache.poi.ss.usermodel.Sheet sheet = workbook.createSheet(); org.apache.poi.ss.usermodel.Row headerRow = sheet.createRow(0); for (int i = 0; i < tableSet.getColumns().size(); i++) { org.apache.poi.ss.usermodel.Cell headerCell = headerRow.createCell(i); headerCell.setCellValue(tableSet.getColumns().get(i).getName()); } for (int i = 0; i < tableSet.getRecordCount(); i++) { org.apache.poi.ss.usermodel.Row row = sheet.createRow(i + 1); for (int j = 0; j < tableSet.getColumns().size(); j++) { org.apache.poi.ss.usermodel.Cell cell = row.createCell(j); if (Column.TYPE_STRING == tableSet.getColumns().get(j).getType()) { cell.setCellValue(tableSet.getColumns().get(j).getData().get(i)); } else if (Column.TYPE_NUMERIC == tableSet.getColumns().get(j).getType()) { cell.setCellValue(Double.parseDouble(tableSet.getColumns().get(j).getData().get(i))); } else if (Column.TYPE_DATE == tableSet.getColumns().get(j).getType()) { cell.setCellValue(tableSet.getColumns().get(j).getData().get(i)); } else if (Column.TYPE_BOOLEAN == tableSet.getColumns().get(j).getType()) { cell.setCellValue(DataUtil.parseBoolean(tableSet.getColumns().get(j).getData().get(i))); } else if (Column.TYPE_BLANK == tableSet.getColumns().get(j).getType()) { cell.setCellValue(""); } else { cell.setCellValue(tableSet.getColumns().get(j).getData().get(i)); } } } workbook.write(chainStream.getOutputStream()); workbook.close(); } catch (Throwable e) { e.printStackTrace(); } finally { try { workbook.close(); } catch (Throwable e) { } try { chainStream.close(); } catch (Throwable e) { } try { fileStream.close(); } catch (Throwable e) { } } }
From source file:hu.webhejj.commons.io.table.excel.ExcelUtils.java
License:Apache License
public static void ensureSheet(Workbook workbook, int index) { for (int i = workbook.getNumberOfSheets(); i <= index; i++) { workbook.createSheet(); }//w w w . j av a2 s . c o m }
From source file:Import.Utils.XSSFConvert.java
public void convert() throws IOException { Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() }; for (int i = 0; i < wbs.length; i++) { Workbook wb = wbs[i]; CreationHelper createHelper = wb.getCreationHelper(); // create a new sheet org.apache.poi.ss.usermodel.Sheet s = wb.createSheet(); // declare a row object reference Row r = null;/*from w w w .ja va 2 s .c o m*/ // declare a cell object reference Cell c = null; // create 2 cell styles CellStyle cs = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); DataFormat df = wb.createDataFormat(); // create 2 fonts objects Font f = wb.createFont(); Font f2 = wb.createFont(); // Set font 1 to 12 point type, blue and bold f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.RED.getIndex()); f.setBoldweight(Font.BOLDWEIGHT_BOLD); // Set font 2 to 10 point type, red and bold f2.setFontHeightInPoints((short) 10); f2.setColor(IndexedColors.RED.getIndex()); f2.setBoldweight(Font.BOLDWEIGHT_BOLD); // Set cell style and formatting cs.setFont(f); cs.setDataFormat(df.getFormat("#,##0.0")); // Set the other cell style and formatting cs2.setBorderBottom(cs2.BORDER_THIN); cs2.setDataFormat(df.getFormat("text")); cs2.setFont(f2); // Define a few rows for (int rownum = 0; rownum < 30; rownum++) { r = s.createRow(rownum); for (int cellnum = 0; cellnum < 10; cellnum += 2) { c = r.createCell(cellnum); Cell c2 = r.createCell(cellnum + 1); c.setCellValue((double) rownum + (cellnum / 10)); c2.setCellValue(createHelper.createRichTextString("Hello! " + cellnum)); } } // Save String filename = "workbook.xls"; if (wb instanceof XSSFWorkbook) { filename = filename + "x"; } FileOutputStream out = null; try { out = new FileOutputStream(filename); } catch (FileNotFoundException ex) { Logger.getLogger(XSSFConvert.class.getName()).log(Level.SEVERE, null, ex); } wb.write(out); out.close(); } }
From source file:joinery.impl.Serialization.java
License:Open Source License
public static <V> void writeXls(final DataFrame<V> df, final OutputStream output) throws IOException { final Workbook wb = new HSSFWorkbook(); final Sheet sheet = wb.createSheet(); // add header Row row = sheet.createRow(0);//from w w w. j a va 2s.c o m final Iterator<Object> it = df.columns().iterator(); for (int c = 0; c < df.size(); c++) { final Cell cell = row.createCell(c); writeCell(cell, it.hasNext() ? it.next() : c); } // add data values for (int r = 0; r < df.length(); r++) { row = sheet.createRow(r + 1); for (int c = 0; c < df.size(); c++) { final Cell cell = row.createCell(c); writeCell(cell, df.get(r, c)); } } // write to stream wb.write(output); output.close(); }
From source file:Modelo.Manager_BD.java
public Workbook tareasParaReporte(String fechaI, String fechaF, String cliente, String proyecto) { Workbook libro = new XSSFWorkbook(); // Se crea una hoja dentro del libro Sheet hoja = libro.createSheet(); // Se crea una fila dentro de la hoja Row fila = hoja.createRow(1);/*from w w w . j a v a 2s . c o m*/ try { Statement st = (Statement) connect.createStatement(); ResultSet rs = st.executeQuery("select * from " + baseDatos + ".Tareas inner join " + baseDatos + ".Usuarios on Tareas.idUsuarios=Usuarios.idUsuarios inner join " + baseDatos + ".Clientes on Clientes.idClientes=Tareas.idCliente ORDER BY nombre_Cliente"); Calendar c1 = GregorianCalendar.getInstance(); Calendar c2 = GregorianCalendar.getInstance(); Calendar fb = GregorianCalendar.getInstance(); SimpleDateFormat formatoSlash = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat formatoGuion = new SimpleDateFormat("yyyy-MM-dd"); c1.setTime(formatoSlash.parse(fechaI)); c2.setTime(formatoSlash.parse(fechaF)); // Se crea una celda dentro de la fila Cell celda = fila.createCell(1); celda.setCellValue("Reporte de Horas de:"); fila.createCell(2).setCellValue(fechaI); fila.createCell(3).setCellValue("al"); fila.createCell(4).setCellValue(fechaF); int filas = 3; int filasabajo = filas + 3; while (rs.next()) { fb.setTime(formatoGuion.parse(rs.getString("fecha").toString())); for (int i = 0; i < 999; i++) { } if (fb.before(c2) && fb.after(c1)) { if (cliente.equals("TODOS")) { if (proyecto.equals("TODOS")) { } else { } } else { if (proyecto.equals("TODOS")) { } else { hoja.createRow(filas).createCell(1).setCellValue(cliente); hoja.createRow(filas + 1).createCell(1).setCellValue(proyecto); if (cliente.equals(rs.getString("nombre_Cliente"))) { Row filaX = hoja.createRow(filasabajo); filaX.createCell(2).setCellValue(rs.getString("email")); filaX.createCell(3).setCellValue(rs.getString("nombre_Tarea")); filaX.createCell(4).setCellValue(rs.getString("horas_Tarea")); filaX.createCell(5).setCellValue(rs.getString("fecha")); filasabajo++; } } } } } rs.close(); st.close(); } catch (Exception e) { e.printStackTrace(); } return libro; }
From source file:org.activityinfo.server.report.renderer.excel.ExcelMapDataExporter.java
License:Open Source License
@Override public void render(ReportElement element, OutputStream stm) throws IOException { if (!(element instanceof MapReportElement)) { throw new RuntimeException("ExcelMapDataExporter accepts only MapElements"); }// www . java 2s. co m MapContent content = ((MapReportElement) element).getContent(); Workbook book = new HSSFWorkbook(); Sheet sheet = book.createSheet(); Helper helper = new Helper(book); Row headerRow = sheet.createRow(0); helper.addCell(headerRow, 0, "Latitude"); helper.addCell(headerRow, 1, "Longitude"); helper.addCell(headerRow, 2, "Value"); helper.addCell(headerRow, 3, "Color"); helper.addCell(headerRow, 4, "Icon"); int rowIndex = 1; for (MapMarker marker : content.getMarkers()) { Row dataRow = sheet.createRow(rowIndex++); helper.addCell(dataRow, 0, marker.getLat()); helper.addCell(dataRow, 1, marker.getLng()); if (marker instanceof BubbleMapMarker) { BubbleMapMarker bmarker = (BubbleMapMarker) marker; helper.addCell(dataRow, 2, bmarker.getValue()); helper.addCell(dataRow, 3, bmarker.getColor()); } if (marker instanceof IconMapMarker) { IconMapMarker imarker = (IconMapMarker) marker; if (imarker.getIcon() != null) { helper.addCell(dataRow, 4, imarker.getIcon().getName()); } } } book.write(stm); }
From source file:org.apache.jena.examples.ExampleARQ_06.java
License:Apache License
public static void main(String[] args) throws IOException { FileManager.get().addLocatorClassLoader(ExampleARQ_01.class.getClassLoader()); Model model = FileManager.get().loadModel("data/data.ttl"); Query query = QueryFactory.create("SELECT * WHERE { ?s ?p ?o }"); QueryExecution qexec = QueryExecutionFactory.create(query, model); FileOutputStream out = new FileOutputStream("target/sxssf.xlsx"); Workbook wb = new SXSSFWorkbook(100); Sheet sh = wb.createSheet(); int rows = 0; int columns = 0; try {/*from w w w . ja va 2 s .c o m*/ ResultSet resultSet = qexec.execSelect(); List<String> varNames = resultSet.getResultVars(); List<Var> vars = new ArrayList<Var>(varNames.size()); // first row with var names Row row = sh.createRow(rows++); for (String varName : varNames) { Var var = Var.alloc(varName); Cell cell = row.createCell(columns++); cell.setCellValue(var.toString()); vars.add(var); } // other rows with bindings while (resultSet.hasNext()) { Binding bindings = resultSet.nextBinding(); row = sh.createRow(rows++); columns = 0; for (Var var : vars) { Node n = bindings.get(var); if (n != null) { Cell cell = row.createCell(columns++); String value = FmtUtils.stringForNode(n, (SerializationContext) null); cell.setCellValue(value); } } } } finally { qexec.close(); } wb.write(out); out.close(); }
From source file:org.apache.ranger.biz.ServiceDBStore.java
License:Apache License
private void writeExcel(List<RangerPolicy> policies, String excelFileName, HttpServletResponse response) throws IOException { Workbook workbook = null; OutputStream outStream = null; try {/*from www . j av a 2 s .co m*/ workbook = new HSSFWorkbook(); Sheet sheet = workbook.createSheet(); createHeaderRow(sheet); int rowCount = 0; if (!CollectionUtils.isEmpty(policies)) { for (RangerPolicy policy : policies) { long serviceType = daoMgr.getXXService().findByName(policy.getService()).getType(); List<RangerPolicyItem> policyItems = policy.getPolicyItems(); List<RangerRowFilterPolicyItem> rowFilterPolicyItems = policy.getRowFilterPolicyItems(); List<RangerDataMaskPolicyItem> dataMaskPolicyItems = policy.getDataMaskPolicyItems(); if (CollectionUtils.isNotEmpty(policyItems)) { for (RangerPolicyItem policyItem : policyItems) { Row row = sheet.createRow(++rowCount); writeBookForPolicyItems(policy, policyItem, null, null, row); } } else if (CollectionUtils.isNotEmpty(dataMaskPolicyItems)) { for (RangerDataMaskPolicyItem dataMaskPolicyItem : dataMaskPolicyItems) { Row row = sheet.createRow(++rowCount); writeBookForPolicyItems(policy, null, dataMaskPolicyItem, null, row); } } else if (CollectionUtils.isNotEmpty(rowFilterPolicyItems)) { for (RangerRowFilterPolicyItem rowFilterPolicyItem : rowFilterPolicyItems) { Row row = sheet.createRow(++rowCount); writeBookForPolicyItems(policy, null, null, rowFilterPolicyItem, row); } } else if (serviceType == 100) { Row row = sheet.createRow(++rowCount); writeBookForTag(policy, row); } } } ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); workbook.write(outByteStream); byte[] outArray = outByteStream.toByteArray(); response.setContentType("application/ms-excel"); response.setContentLength(outArray.length); response.setHeader("Expires:", "0"); response.setHeader("Content-Disposition", "attachment; filename=" + excelFileName); outStream = response.getOutputStream(); outStream.write(outArray); outStream.flush(); } catch (IOException ex) { LOG.error("Failed to create report file " + excelFileName, ex); } catch (Exception ex) { LOG.error("Error while generating report file " + excelFileName, ex); } finally { if (outStream != null) { outStream.close(); } if (workbook != null) { workbook.close(); } } }
From source file:org.castafiore.groovy.Main.java
License:Open Source License
/** * @param args/* www . j a v a 2 s .c o m*/ */ public static void main(String[] args) throws Exception { // Main m = new Main(); // m.startContainer(); // TutorialService tService = (TutorialService)m.getObject("tutorial"); // tService.testMethod(); // List<ASTNode> nodes = new AstBuilder().buildFromString("def w; def v; System.out.println(\"fsdfsdfs\");"); // // // for(ASTNode n : nodes){ // if(n instanceof BlockStatement){ // BlockStatement block = (BlockStatement)n; // // List<Statement> stms = block.getStatements(); // for(Statement s : stms){ // if(s instanceof ExpressionStatement){ // ExpressionStatement expression = (ExpressionStatement)s; // Expression exp = expression.getExpression(); // if(exp instanceof DeclarationExpression){ // DeclarationExpression declaration = (DeclarationExpression)exp; // System.out.println( declaration.getLeftExpression().getText()); // } // // //System.out.println(expression.getExpression().getClass().getName()); // // } // //System.out.println(s.getClass().getName()); // } // } // // System.out.println(n.getText()); // } ///root/users/erevolution/Applications/e-Shop/erevolution/DefaultCashBook/entries/2012/ //INSERT INTO WFS_FILE VALUES ('Account', '/root/users/erevolution/Applications/e-Shop/erevolution/DefaultCashBook/accounts/1351867186927', 'org.castafiore.accounting.Account', NULL, '2012-11-02 23:23:20', NULL, '2012-11-02 23:23:20', '\0', '1351867186927', 'erevolution', '*:users', 0, 0, '', NULL, 1, 1, '', 'Whenever there is a sales', NULL, 'Sales Account', NULL, NULL, NULL, NULL, NULL, 'SALES', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Income', 0.00, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '/root/users/erevolution/Applications/e-Shop/erevolution/DefaultCashBook/accounts', NULL); // List<String> tier1 = new ArrayList<String>(); // List<String> tier2 = new ArrayList<String>(); // Sheet s = new HSSFWorkbook(new FileInputStream(new File("c:\\java\\erevolution\\tiers.xls"))).getSheetAt(0); // for(int i =1; i <= s.getLastRowNum();i++){ // // Row r = s.getRow(i); // if(r != null && r.getCell(1) != null && r.getCell(1).getNumericCellValue() >0){ // //tier 1 agent for erevolution // //System.out.println("insert into SECU_RELATIONSHIP values ("+(i+11000)+",'erevolution', 'Tier 2 Agent', '"+new Double(r.getCell(1).getNumericCellValue()).intValue()+"');"); // tier2.add(new Double(r.getCell(1).getNumericCellValue()).intValue() + ""); // // } // // if(r != null && r.getCell(0) != null && r.getCell(0).getNumericCellValue() >0){ // //tier 1 agent for erevolution // //System.out.println("insert into SECU_RELATIONSHIP values ("+(i+11000)+",'erevolution', 'Tier 2 Agent', '"+new Double(r.getCell(1).getNumericCellValue()).intValue()+"');"); // tier1.add(new Double(r.getCell(0).getNumericCellValue()).intValue() + ""); // // } //// if(s.getRow(i).getCell(0).getStringCellValue().equalsIgnoreCase("merchant")) //// System.out.println("insert into SECU_RELATIONSHIP values ("+(i+10000)+",'erevolution', '"+s.getRow(i).getCell(3).getStringCellValue()+"', '"+s.getRow(i).getCell(1).getStringCellValue()+"');"); // } //FileOutputStream fout = new FileOutputStream(new File("c:\\java\\erevolution\\tiers.sql")); //FileWriter writer = new FileWriter(new File("c:\\java\\erevolution\\tiers.sql")); //int i = 12000; // for(String t1 : tier1){ // for(String t2 : tier2){ // //writer.write(str) // writer.write("insert into SECU_RELATIONSHIP values ("+(i++)+",'"+t1+"', 'Customer', '"+t2+"');\n"); // writer.write("insert into SECU_RELATIONSHIP values ("+(i++)+",'"+t2+"', 'Supplier', '"+t1+"');\n"); // } // } //writer.flush(); //writer.close(); // FileWriter writer = new FileWriter(new File("c:\\java\\erevolution\\tiers.sql")); // tier2.add("erevolution"); // String[] accs = new String[]{"Sales:SALES","Purchases:PURCHASES", // "Travelling Expenses:TRAVELLING", "Salary:SALARY", "Tax:TAX", "Misc:MISC", // "Electricity:ELEC,Water,Telecom","NPS,NPF:NPS", "Bank charges and Interest:BNKCHGS","Loan:LOAN","Petty cash:PETTY", "Vehicle expenses:VEHICLE"}; // // // // for(String t1 : tier1){ // // for(String ss : accs){ // String[] parts = StringUtil.split(ss, ":"); // String code = parts[1]; // String acco = parts[0]; // String name = System.currentTimeMillis()+StringUtil.nextString(10); // writer.write("INSERT INTO WFS_FILE VALUES ('Account', '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts/"+name+ "', 'org.castafiore.accounting.Account', NULL, '2012-11-02 23:23:20', NULL, '2012-11-02 23:23:20', '\0', '1351867186927', '"+t1+"', '*:users', 0, 0, ' ', NULL, 1, 1, ' ', '"+acco+"', NULL, '"+acco+"', NULL, NULL, NULL, NULL, NULL, '"+code+"', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Income', 0.00, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts', NULL);\n"); // } // // // // } // // for(String t1 : tier2){ // for(String ss : accs){ // String[] parts = StringUtil.split(ss, ":"); // String code = parts[1]; // String acco = parts[0]; // String name = System.currentTimeMillis()+StringUtil.nextString(10); // writer.write("INSERT INTO WFS_FILE VALUES ('Account', '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts/"+name+ "', 'org.castafiore.accounting.Account', NULL, '2012-11-02 23:23:20', NULL, '2012-11-02 23:23:20', '\0', '1351867186927', '"+t1+"', '*:users', 0, 0, ' ', NULL, 1, 1, ' ', '"+acco+"', NULL, '"+acco+"', NULL, NULL, NULL, NULL, NULL, '"+code+"', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'Income', 0.00, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '/root/users/"+t1+"/Applications/e-Shop/"+t1+"/DefaultCashBook/accounts', NULL);\n"); // } // } // // writer.flush(); // writer.close(); Workbook hs = new HSSFWorkbook(); Cell c = hs.createSheet().createRow(0).createCell(0); c.setCellValue("45"); c.getCellStyle().setDataFormat(HSSFDataFormat.getBuiltinFormat("$#,##0_);($#,##0)")); DataFormatter d = new HSSFDataFormatter(); System.out.println(d.formatCellValue(c)); //MessageFormat.format(pattern, arguments) }
From source file:org.drools.decisiontable.parser.xls.ExcelParserTest.java
License:Apache License
/** * This should test to see if a cell is in a certain range or not. * If it is in a merged range, then it should return the top left cell. * @throws Exception//from ww w .jav a2 s . c o m */ @Test public void testCellMerge() throws Exception { ExcelParser parser = new ExcelParser((Map<String, List<DataListener>>) null); CellRangeAddress[] ranges = new CellRangeAddress[1]; Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(); Cell cell = sheet.createRow(2).createCell(2); ranges[0] = new CellRangeAddress(2, 7, 2, 5); cell.setCellValue(FIRST_CELL_CONTENT); cell = sheet.createRow(7).createCell(5); cell.setCellValue(LAST_CELL_VALUE); cell = sheet.createRow(1).createCell(1); assertNull(parser.getRangeIfMerged(cell, ranges)); cell = sheet.getRow(2).createCell(5); cell.setCellValue("wrong"); CellRangeAddress rangeIfMerged = parser.getRangeIfMerged(cell, ranges); assertEquals(FIRST_CELL_CONTENT, sheet.getRow(rangeIfMerged.getFirstRow()) .getCell(rangeIfMerged.getFirstColumn()).getStringCellValue()); }