List of usage examples for org.apache.poi.ss.usermodel Cell getRow
Row getRow();
From source file:nl.detoren.ijc.io.OutputExcel.java
License:Open Source License
private void borderRightBottom(Cell cell) { if (cell != null) { Workbook wb = cell.getRow().getSheet().getWorkbook(); CellStyle style = wb.createCellStyle(); style.setBorderBottom(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN); cell.setCellStyle(style);/* w w w .j a v a2 s .co m*/ } }
From source file:org.bbreak.excella.core.tag.excel2java.ArraysParserTest.java
License:Open Source License
@Test public final void testArraysParser() throws ParseException { Workbook wk = getWorkbook();/*from ww w. j a v a 2 s. c o m*/ Sheet sheet1 = wk.getSheetAt(0); Sheet sheet2 = wk.getSheetAt(1); Sheet sheet3 = wk.getSheetAt(2); Sheet sheet4 = wk.getSheetAt(3); ArraysParser arraysParser = new ArraysParser("@Arrays"); String tag = arraysParser.getTag(); arraysParser.setTag(tag); Cell tagCell = null; Object data = null; List<Object[]> list = null; // No.1 ? tagCell = sheet1.getRow(5).getCell(0); list = arraysParser.parse(sheet1, tagCell, data); Object[] arrays = list.get(0); assertEquals("value1-1", arrays[0]); assertEquals("value2-1", arrays[1]); assertEquals("value3-1", arrays[2]); assertEquals(3, arrays.length); arrays = list.get(1); assertEquals("value1-2", arrays[0]); assertEquals("value2-2", arrays[1]); assertEquals("value3-2", arrays[2]); assertEquals(3, arrays.length); arrays = list.get(2); assertEquals("value1-3", arrays[0]); assertEquals("value2-3", arrays[1]); assertEquals("value3-3", arrays[2]); assertEquals(3, arrays.length); arrays = list.get(3); assertEquals("value1-4", arrays[0]); assertEquals("value2-4", arrays[1]); assertEquals("value3-4", arrays[2]); assertEquals("value4-1", arrays[3]); assertEquals(4, arrays.length); arrays = list.get(4); assertEquals("value1-5", arrays[0]); assertEquals(null, arrays[1]); assertEquals("value3-5", arrays[2]); assertEquals("value4-2", arrays[3]); assertEquals(4, arrays.length); arrays = list.get(5); assertEquals("value1-6", arrays[0]); assertEquals("value2-5", arrays[1]); assertEquals(2, arrays.length); assertEquals(6, list.size()); // No.2 tagCell = sheet2.getRow(5).getCell(0); list.clear(); list = arraysParser.parse(sheet2, tagCell, data); arrays = list.get(0); assertEquals("value1-1", arrays[0]); assertEquals("value2-1", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(1); assertEquals("value1-2", arrays[0]); assertEquals("value2-2", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(2); assertEquals("value1-3", arrays[0]); assertEquals("value2-3", arrays[1]); assertEquals(2, arrays.length); assertEquals(3, list.size()); // No.3 ? tagCell = sheet2.getRow(13).getCell(0); list.clear(); list = arraysParser.parse(sheet2, tagCell, data); arrays = list.get(0); assertEquals("value1-4", arrays[0]); assertEquals("value2-4", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(1); assertEquals("value1-5", arrays[0]); assertEquals("value2-5", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(2); assertEquals("value1-6", arrays[0]); assertEquals("value2-6", arrays[1]); assertEquals(2, arrays.length); assertEquals(3, list.size()); // No.4 ?null tagCell = sheet2.getRow(22).getCell(0); list.clear(); list = arraysParser.parse(sheet2, tagCell, data); arrays = list.get(0); assertEquals("value1-7", arrays[0]); assertEquals("value2-7", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(1); assertEquals("value1-8", arrays[0]); assertEquals("value2-8", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(2); assertEquals("value1-9", arrays[0]); assertEquals("value2-9", arrays[1]); assertEquals(2, arrays.length); assertEquals(3, list.size()); // No.5 ?null tagCell = sheet2.getRow(31).getCell(0); list.clear(); list = arraysParser.parse(sheet2, tagCell, data); arrays = list.get(0); assertEquals(null, arrays[0]); assertEquals("value2-10", arrays[1]); assertEquals("value3-1", arrays[2]); assertEquals(3, arrays.length); arrays = list.get(1); assertEquals("value1-10", arrays[0]); assertEquals(null, arrays[1]); assertEquals("value3-2", arrays[2]); assertEquals(3, arrays.length); arrays = list.get(2); assertEquals("value1-11", arrays[0]); assertEquals("value2-11", arrays[1]); assertEquals(2, arrays.length); assertEquals(3, list.size()); // No.6 tagCell = sheet2.getRow(39).getCell(0); list.clear(); list = arraysParser.parse(sheet2, tagCell, data); arrays = list.get(0); assertEquals("value2-12", arrays[0]); assertEquals("value3-3", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(1); assertEquals("value2-13", arrays[0]); assertEquals("value3-4", arrays[1]); assertEquals(2, arrays.length); assertEquals(2, list.size()); // No.7 tagCell = sheet2.getRow(46).getCell(0); list.clear(); list = arraysParser.parse(sheet2, tagCell, data); arrays = list.get(0); assertEquals("value1-14", arrays[0]); assertEquals("value2-14", arrays[1]); assertEquals(null, arrays[2]); assertEquals(null, arrays[3]); assertEquals(null, arrays[4]); assertEquals(5, arrays.length); arrays = list.get(1); assertEquals("value1-15", arrays[0]); assertEquals("value2-15", arrays[1]); assertEquals("value3-5", arrays[2]); assertEquals(null, arrays[3]); assertEquals(null, arrays[4]); assertEquals(5, arrays.length); assertEquals(2, list.size()); // No.8 tagCell = sheet2.getRow(53).getCell(1); list.clear(); list = arraysParser.parse(sheet2, tagCell, data); arrays = list.get(0); assertEquals("value3-6", arrays[0]); assertEquals("value4-1", arrays[1]); assertEquals(null, arrays[2]); assertEquals(null, arrays[3]); assertEquals(4, arrays.length); arrays = list.get(1); assertEquals(null, arrays[0]); assertEquals("value4-2", arrays[1]); assertEquals("value5-1", arrays[2]); assertEquals(null, arrays[3]); assertEquals(4, arrays.length); arrays = list.get(2); assertEquals(null, arrays[0]); assertEquals(null, arrays[1]); assertEquals(null, arrays[2]); assertEquals(null, arrays[3]); assertEquals(4, arrays.length); assertEquals(3, list.size()); // No.9 tagCell = sheet3.getRow(7).getCell(0); list.clear(); list = arraysParser.parse(sheet3, tagCell, data); arrays = list.get(0); assertEquals("value1-1", arrays[0]); assertEquals("value2-1", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(1); assertEquals("value1-2", arrays[0]); assertEquals("value2-2", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(2); assertEquals("value1-3", arrays[0]); assertEquals("value2-3", arrays[1]); assertEquals(2, arrays.length); arrays = list.get(3); assertEquals("value1-4", arrays[0]); assertEquals("value2-4", arrays[1]); assertEquals(2, arrays.length); assertEquals(4, list.size()); // No.10 tagCell = sheet3.getRow(12).getCell(2); list.clear(); list = arraysParser.parse(sheet3, tagCell, data); arrays = list.get(0); assertEquals("value2-6", arrays[0]); assertEquals("value3-1", arrays[1]); assertEquals("value4-1", arrays[2]); assertEquals("value5-1", arrays[3]); assertEquals(4, arrays.length); arrays = list.get(1); assertEquals("value2-7", arrays[0]); assertEquals("value3-2", arrays[1]); assertEquals("value4-2", arrays[2]); assertEquals("value5-2", arrays[3]); assertEquals(4, arrays.length); assertEquals(2, list.size()); // No.11 tagCell = sheet3.getRow(21).getCell(2); list.clear(); list = arraysParser.parse(sheet3, tagCell, data); arrays = list.get(0); assertEquals("value2-8", arrays[0]); assertEquals("value3-3", arrays[1]); assertEquals("value4-3", arrays[2]); assertEquals("value5-3", arrays[3]); assertEquals(4, arrays.length); arrays = list.get(1); assertEquals("value2-9", arrays[0]); assertEquals("value3-4", arrays[1]); assertEquals("value4-4", arrays[2]); assertEquals("value5-4", arrays[3]); assertEquals(4, arrays.length); assertEquals(2, list.size()); // No.12 DataRowFrom > DataRowTo tagCell = sheet3.getRow(30).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(30, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.12:" + pe); } // No.13 DataColumnFrom > DataColumnTo tagCell = sheet3.getRow(40).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(40, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.13:" + pe); } // No.14 DataRowFrom?? tagCell = sheet3.getRow(48).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(48, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.14:" + pe); } // No.15 DataRowTo?? tagCell = sheet3.getRow(51).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(51, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.15:" + pe); } // No.16 DataColumnFrom?? tagCell = sheet3.getRow(54).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(54, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.16:" + pe); } // No.17 DataColumnTo?? tagCell = sheet3.getRow(57).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(57, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.17:" + pe); } // No.18 DataRowFrom?? tagCell = sheet3.getRow(60).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(60, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.18:" + pe); } // No.19 DataRowTo?? tagCell = sheet3.getRow(63).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(63, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.19:" + pe); } // No.20 DataColumnFrom?? tagCell = sheet3.getRow(66).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(66, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.20:" + pe); } // No.21 DataColumnTo?? tagCell = sheet3.getRow(69).getCell(0); list.clear(); try { list = arraysParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(69, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.21:" + pe); } // No.22 DataColumnFrom?A?? tagCell = sheet4.getRow(2).getCell(0); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(2, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.22:" + pe); } // No.23 DataColumnTo?A?? tagCell = sheet4.getRow(11).getCell(0); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(11, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.23:" + pe); } // No.24 DataRowFrom?1?? tagCell = sheet4.getRow(0).getCell(3); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(3, cell.getColumnIndex()); System.out.println("No.24:" + pe); } // No.25 DataRowTo?1?? tagCell = sheet4.getRow(0).getCell(6); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(6, cell.getColumnIndex()); System.out.println("No.25:" + pe); } // No.26 DataColumnFrom??? tagCell = sheet4.getRow(2).getCell(11); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(2, cell.getRow().getRowNum()); assertEquals(11, cell.getColumnIndex()); System.out.println("No.26:" + pe); } // No.27 DataColumnTo??? tagCell = sheet4.getRow(11).getCell(11); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(11, cell.getRow().getRowNum()); assertEquals(11, cell.getColumnIndex()); System.out.println("No.27:" + pe); } // No.28 DataRowFrom??? tagCell = sheet4.getRow(18).getCell(3); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(3, cell.getColumnIndex()); System.out.println("No.28:" + pe); } // No.29 DataRowTo??? tagCell = sheet4.getRow(18).getCell(6); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(6, cell.getColumnIndex()); System.out.println("No.29:" + pe); } // No.30 ? tagCell = sheet4.getRow(18).getCell(9); list.clear(); try { list = arraysParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(9, cell.getColumnIndex()); System.out.println("No.30:" + pe); } }
From source file:org.bbreak.excella.core.tag.excel2java.ListParserTest.java
License:Open Source License
@Test public final void testListParser() throws ParseException { Workbook wk = getWorkbook();// www . j av a2 s. co m Sheet sheet = wk.getSheetAt(0); ListParser listParser = new ListParser("@List"); Cell tagCell = null; Object data = null; List<?> list = null; // No.1 @List tagCell = sheet.getRow(2).getCell(0); list = listParser.parse(sheet, tagCell, data); assertEquals("?1", list.get(0)); assertEquals("?2", list.get(1)); assertEquals("@List{DataRowFrom=2,DataRowTo=5}", list.get(2)); assertEquals("", list.get(3)); assertEquals("?3", list.get(4)); assertEquals("?4", list.get(5)); assertEquals("?5", list.get(6)); assertEquals("@List{DataRowFrom=2,DataRowTo=3,ValueColumn=1}", list.get(7)); assertEquals(null, list.get(8)); assertEquals(null, list.get(9)); assertEquals(null, list.get(10)); assertEquals("@List{ValueColumn=-1}", list.get(11)); assertEquals("?8", list.get(12)); assertEquals(13, list.size()); // No.2 @List{DataRowFrom=2,DataRowTo=5} tagCell = sheet.getRow(6).getCell(0); list.clear(); list = listParser.parse(sheet, tagCell, data); assertEquals("?3", list.get(0)); assertEquals("?4", list.get(1)); assertEquals("?5", list.get(2)); assertEquals(3, list.size()); // No.3 @List{DataRowFrom=2,DataRowTo=3,ValueColumn=1} tagCell = sheet.getRow(14).getCell(0); list.clear(); list = listParser.parse(sheet, tagCell, data); assertEquals("?6", list.get(0)); assertEquals("?7", list.get(1)); assertEquals(2, list.size()); // No.4 @List{ValueColumn=-1}(1??????) tagCell = sheet.getRow(24).getCell(0); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(24, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.4:" + pe); } // No.5 @List{DataRowFrom=-1}(1?????) tagCell = sheet.getRow(0).getCell(4); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(4, cell.getColumnIndex()); System.out.println("No.5:" + pe); } // No.6 @List{DataRowFrom=1}(???????) tagCell = sheet.getRow(25).getCell(4); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(25, cell.getRow().getRowNum()); assertEquals(4, cell.getColumnIndex()); System.out.println("No.6:" + pe); } // No.7 @List{DataRowTo=-1}(1?????) tagCell = sheet.getRow(0).getCell(7); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(7, cell.getColumnIndex()); System.out.println("No.7:" + pe); } // No.8 @List{DataRowTo=1}(???????) tagCell = sheet.getRow(25).getCell(7); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(25, cell.getRow().getRowNum()); assertEquals(7, cell.getColumnIndex()); System.out.println("No.8:" + pe); } // No.9 @List{ValueColumn=1}(??????) tagCell = sheet.getRow(2).getCell(10); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(2, cell.getRow().getRowNum()); assertEquals(10, cell.getColumnIndex()); System.out.println("No.9:" + pe); } // sheet = wk.getSheetAt(1); // No.10 @List{DataRowFrom=3,DataRowTo=1}(DataRowFrom > DataRowTo ??) tagCell = sheet.getRow(0).getCell(0); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.10:" + pe); } // No.11 @List{DataRowFrom=-1,DataRowTo=-3}(?) tagCell = sheet.getRow(13).getCell(0); list.clear(); list = listParser.parse(sheet, tagCell, data); assertEquals("?2-4", list.get(0)); assertEquals("?2-5", list.get(1)); assertEquals("?2-6", list.get(2)); assertEquals(3, list.size()); // No.12 @List{ValueColumn=-1}(?) tagCell = sheet.getRow(29).getCell(1); list.clear(); list = listParser.parse(sheet, tagCell, data); assertEquals("?2-7", list.get(0)); assertEquals("?2-8", list.get(1)); assertEquals("?2-9", list.get(2)); assertEquals(3, list.size()); // No.13 @List{DataRowFrom=1}(DataRowFrom??) tagCell = sheet.getRow(27).getCell(4); list.clear(); list = listParser.parse(sheet, tagCell, data); assertEquals("?2-10", list.get(0)); assertEquals("?2-11", list.get(1)); assertEquals("?2-12", list.get(2)); assertEquals(null, list.get(3)); assertEquals("?2-13", list.get(4)); assertEquals(5, list.size()); // No.14 @List{DataRowTo=2}(DataRowTo??) tagCell = sheet.getRow(27).getCell(8); list.clear(); list = listParser.parse(sheet, tagCell, data); assertEquals("?2-14", list.get(0)); assertEquals("?2-15", list.get(1)); assertEquals(2, list.size()); // No.15 @List{DataRowFrom=}(DataRowFrom) tagCell = sheet.getRow(0).getCell(4); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(4, cell.getColumnIndex()); System.out.println("No.15:" + pe); } // No.16 @List{DataRowTo=}(DataRowTo) tagCell = sheet.getRow(9).getCell(4); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(9, cell.getRow().getRowNum()); assertEquals(4, cell.getColumnIndex()); System.out.println("No.16:" + pe); } // No.17 @List{ValueColumn=}(ValueColumn) tagCell = sheet.getRow(18).getCell(4); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(4, cell.getColumnIndex()); System.out.println("No.17:" + pe); } // No.18 @List{DataRowFrom=a}(DataRowFrom) tagCell = sheet.getRow(0).getCell(7); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(7, cell.getColumnIndex()); System.out.println("No.18:" + pe); } // No.19 @List{DataRowTo=a}(DataRowTo) tagCell = sheet.getRow(9).getCell(7); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(9, cell.getRow().getRowNum()); assertEquals(7, cell.getColumnIndex()); System.out.println("No.19:" + pe); } // No.20 @List{ValueColumn=a}(ValueColumn) tagCell = sheet.getRow(18).getCell(7); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(7, cell.getColumnIndex()); System.out.println("No.20:" + pe); } // sheet = wk.getSheetAt(1); // No.21 @List(???) tagCell = sheet.getRow(0).getCell(0); list.clear(); try { list = listParser.parse(sheet, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.21:" + pe); } }
From source file:org.bbreak.excella.core.tag.excel2java.MapParserTest.java
License:Open Source License
@Test public final void testMapParser() throws ParseException { Workbook wk = getWorkbook();/*from ww w.j ava2 s . co m*/ Sheet sheet1 = wk.getSheetAt(0); Sheet sheet2 = wk.getSheetAt(1); Sheet sheet3 = wk.getSheetAt(2); Sheet sheet4 = wk.getSheetAt(3); MapParser mapParser = new MapParser("@Map"); Cell tagCell = null; Object data = null; Map<?, ?> map = null; // No.1 ? tagCell = sheet1.getRow(3).getCell(0); map = mapParser.parse(sheet1, tagCell, data); Set<?> keySet = map.keySet(); assertEquals(25, keySet.size()); assertEquals("1", map.get("1")); assertEquals("2", map.get("2")); assertTrue(keySet.contains("@Map{DataRowFrom=2,DataRowTo=5}")); assertEquals(null, map.get("@Map{DataRowFrom=2,DataRowTo=5}")); assertEquals("3", map.get("3")); assertEquals("4", map.get("4")); assertEquals("5", map.get("5")); assertEquals("6", map.get("6")); assertTrue(keySet.contains("@Map{DataRowFrom=2,DataRowTo=3,Key=}")); assertEquals(null, map.get("@Map{DataRowFrom=2,DataRowTo=3,Key=}")); assertEquals("7", map.get("7")); assertEquals("8", map.get("8")); assertTrue(keySet.contains("@Map{DataRowFrom=2,DataRowTo=3,Value=}")); assertEquals(null, map.get("@Map{DataRowFrom=2,DataRowTo=3,Value=}")); assertEquals("9", map.get("9")); assertEquals("10", map.get("10")); assertTrue(keySet.contains("@Map{DataRowFrom=2,DataRowTo=3,KeyColumn=2}")); assertEquals(null, map.get("@Map{DataRowFrom=2,DataRowTo=3,KeyColumn=2}")); assertTrue(keySet.contains("@Map{DataRowFrom=2,DataRowTo=3,ValueColumn=2}")); assertEquals(null, map.get("@Map{DataRowFrom=2,DataRowTo=3,ValueColumn=2}")); assertEquals("", map.get("13")); assertEquals("", map.get("14")); assertTrue(keySet.contains("@Map{DataRowFrom=2,DataRowTo=4,KeyCell=2:2}")); assertEquals(null, map.get("@Map{DataRowFrom=2,DataRowTo=4,KeyCell=2:2}")); assertEquals("17", map.get("")); assertTrue(keySet.contains("@Map{DataRowFrom=2,DataRowTo=4,ValueCell=4:3}")); assertEquals(null, map.get("@Map{DataRowFrom=2,DataRowTo=4,ValueCell=4:3}")); assertEquals("", map.get("18")); assertEquals("", map.get("19")); assertEquals("", map.get("20")); // No.2 tagCell = sheet1.getRow(7).getCell(0); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(4, keySet.size()); assertEquals("3", map.get("3")); assertEquals("4", map.get("4")); assertEquals("5", map.get("5")); assertEquals("6", map.get("6")); // No.3 tagCell = sheet1.getRow(15).getCell(0); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(1, keySet.size()); assertEquals("8", map.get("")); // No.4 tagCell = sheet1.getRow(24).getCell(0); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(2, keySet.size()); assertEquals("", map.get("9")); assertEquals("", map.get("10")); // No.5 tagCell = sheet1.getRow(32).getCell(0); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(2, keySet.size()); assertEquals("11", map.get("11")); assertEquals("12", map.get("12")); // No.6 tagCell = sheet1.getRow(41).getCell(0); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(2, keySet.size()); assertEquals("13", map.get("13")); assertEquals("14", map.get("14")); // No.7 tagCell = sheet1.getRow(49).getCell(0); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(1, keySet.size()); assertEquals("17", map.get("15")); // No.8 tagCell = sheet1.getRow(58).getCell(0); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(3, keySet.size()); assertEquals("20", map.get("18")); assertEquals("20", map.get("19")); assertEquals("20", map.get("20")); // No.9 DataRowFrom > DataRowTo tagCell = sheet1.getRow(3).getCell(7); map.clear(); try { map = mapParser.parse(sheet1, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(3, cell.getRow().getRowNum()); assertEquals(7, cell.getColumnIndex()); System.out.println("No.9:" + pe); } // No.10 tagCell = sheet1.getRow(18).getCell(7); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(4, keySet.size()); assertEquals("5", map.get("5")); assertEquals("6", map.get("6")); assertEquals("7", map.get("7")); assertEquals("8", map.get("8")); // No.11 tagCell = sheet1.getRow(23).getCell(8); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(4, keySet.size()); assertEquals("9", map.get("9")); assertEquals("10", map.get("10")); assertEquals("11", map.get("11")); assertEquals("12", map.get("12")); // No.12 tagCell = sheet1.getRow(33).getCell(8); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(4, keySet.size()); assertEquals("13", map.get("13")); assertEquals("14", map.get("14")); assertEquals("15", map.get("15")); assertEquals("16", map.get("16")); // No.13 tagCell = sheet1.getRow(43).getCell(8); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(1, keySet.size()); assertEquals("20", map.get("")); // No.14 tagCell = sheet1.getRow(53).getCell(8); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(4, keySet.size()); assertEquals("", map.get("21")); assertEquals("", map.get("22")); assertEquals("", map.get("23")); assertEquals("", map.get("24")); // No.15 ?? tagCell = sheet1.getRow(63).getCell(7); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(2, keySet.size()); assertEquals("25", map.get("25")); assertEquals("26", map.get("26")); // No.16 ???? tagCell = sheet1.getRow(71).getCell(7); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(1, keySet.size()); assertEquals("@Map{DataRowFrom=0,DataRowTo=0,ValueColumn=0}", map.get("@Map{DataRowFrom=0,DataRowTo=0,ValueColumn=0}")); // No.17 ? tagCell = sheet1.getRow(76).getCell(7); map.clear(); map = mapParser.parse(sheet1, tagCell, data); keySet = map.keySet(); assertEquals(1, keySet.size()); assertEquals("@Map{DataRowFrom=0,DataRowTo=0,KeyCell=0:0,ValueCell=0:0}", map.get("@Map{DataRowFrom=0,DataRowTo=0,KeyCell=0:0,ValueCell=0:0}")); // No.18 ?null tagCell = sheet2.getRow(3).getCell(0); map.clear(); map = mapParser.parse(sheet2, tagCell, data); keySet = map.keySet(); assertEquals(3, keySet.size()); assertEquals("1", map.get("1")); assertTrue(keySet.contains(null)); assertEquals("2", map.get(null)); assertEquals("3", map.get("2")); // No.19 ?null tagCell = sheet2.getRow(11).getCell(0); map.clear(); map = mapParser.parse(sheet2, tagCell, data); keySet = map.keySet(); assertEquals(3, keySet.size()); assertEquals("4", map.get("3")); assertEquals(null, map.get("4")); assertEquals("5", map.get("5")); // No.20 ?null tagCell = sheet2.getRow(19).getCell(0); map.clear(); map = mapParser.parse(sheet2, tagCell, data); keySet = map.keySet(); assertEquals(2, keySet.size()); assertEquals("6", map.get("6")); assertEquals("7", map.get("7")); // No.21 ?null tagCell = sheet2.getRow(27).getCell(0); map.clear(); map = mapParser.parse(sheet2, tagCell, data); keySet = map.keySet(); assertEquals(3, keySet.size()); assertEquals("8", map.get("8")); assertEquals("9", map.get(null)); assertEquals("10", map.get("9")); // No.22 ??null tagCell = sheet2.getRow(35).getCell(0); map.clear(); map = mapParser.parse(sheet2, tagCell, data); keySet = map.keySet(); assertEquals(3, keySet.size()); assertEquals("11", map.get("10")); assertTrue(keySet.contains("11")); assertEquals(null, map.get("11")); assertEquals("12", map.get("12")); // No.23 ???null tagCell = sheet2.getRow(43).getCell(0); map.clear(); map = mapParser.parse(sheet2, tagCell, data); keySet = map.keySet(); assertEquals(3, keySet.size()); assertEquals("13", map.get("13")); assertTrue(keySet.contains(null)); assertEquals(null, map.get(null)); assertEquals("14", map.get("14")); // No.24 ??null tagCell = sheet2.getRow(51).getCell(0); map.clear(); map = mapParser.parse(sheet2, tagCell, data); keySet = map.keySet(); assertEquals(2, keySet.size()); assertEquals(null, map.get("15")); assertEquals(null, map.get("16")); // No.25 ?Key, KeyColumn, KeyCell tagCell = sheet3.getRow(4).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(4, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.25:" + pe); } // No.26 ?Key, KeyColumn tagCell = sheet3.getRow(8).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(8, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.26:" + pe); } // No.27 ?Key, KeyCell tagCell = sheet3.getRow(12).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(12, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.27:" + pe); } // No.28 ?KeyColumn, KeyCell tagCell = sheet3.getRow(16).getCell(0); map.clear(); try { map = mapParser.parse(sheet1, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(16, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.28:" + pe); } // No.29 ?Value, ValueColumn, ValueCell tagCell = sheet3.getRow(20).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(20, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.29:" + pe); } // No.30 ?Value, ValueColumn tagCell = sheet3.getRow(24).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(24, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.30:" + pe); } // No.31 ?Value, ValueCell tagCell = sheet3.getRow(28).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(28, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.31:" + pe); } // No.32 ?ValueColumn, ValueCell tagCell = sheet3.getRow(32).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(32, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.32:" + pe); } // No.33 ? tagCell = sheet3.getRow(38).getCell(1); map.clear(); map = mapParser.parse(sheet3, tagCell, data); // No.34 DataRowFrom?? tagCell = sheet3.getRow(41).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(41, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.33:" + pe); } // No.35 DataRowTo?? tagCell = sheet3.getRow(44).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(44, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.35:" + pe); } // No.36 Key?? tagCell = sheet3.getRow(47).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(47, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.36:" + pe); } // No.37 Value?? tagCell = sheet3.getRow(50).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(50, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.37:" + pe); } // No.38 KeyColumn?? tagCell = sheet3.getRow(53).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(53, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.38:" + pe); } // No.39 ValueColumn?? tagCell = sheet3.getRow(56).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(56, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.39:" + pe); } // No.40 KeyCell?? tagCell = sheet3.getRow(59).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(59, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.40:" + pe); } // No.41 ValueCell?? tagCell = sheet3.getRow(62).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(62, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.41:" + pe); } // No.42 DataRowFrom?? tagCell = sheet3.getRow(65).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(65, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.42:" + pe); } // No.43 DataRowTo?? tagCell = sheet3.getRow(68).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(68, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.43:" + pe); } // No.44 KeyColumen?? tagCell = sheet3.getRow(71).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(71, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.44:" + pe); } // No.45 ValueColumn?? tagCell = sheet3.getRow(74).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(74, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.45:" + pe); } // No.46 KeyCell?? tagCell = sheet3.getRow(77).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(77, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.46:" + pe); } // No.47 ValueCell?? tagCell = sheet3.getRow(80).getCell(0); map.clear(); try { map = mapParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(80, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.47:" + pe); } // No.48 KeyColumn?A?? tagCell = sheet4.getRow(2).getCell(0); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(2, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.48:" + pe); } // No.49 ValueColumn?A?? tagCell = sheet4.getRow(11).getCell(0); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(11, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.49:" + pe); } // No.50 KeyCell?A?? tagCell = sheet4.getRow(20).getCell(0); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(20, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.50:" + pe); } // No.51 ValueCell?A?? tagCell = sheet4.getRow(29).getCell(0); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(29, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.51:" + pe); } // No.52 DataRowFrom?1?? tagCell = sheet4.getRow(0).getCell(3); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(3, cell.getColumnIndex()); System.out.println("No.52:" + pe); } // No.53 DataRowTo?1?? tagCell = sheet4.getRow(0).getCell(6); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(6, cell.getColumnIndex()); System.out.println("No.53:" + pe); } // No.54 KeyCell?1?? tagCell = sheet4.getRow(0).getCell(9); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(9, cell.getColumnIndex()); System.out.println("No.54:" + pe); } // No.55 ValueCell?1?? tagCell = sheet4.getRow(0).getCell(12); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(12, cell.getColumnIndex()); System.out.println("No.55:" + pe); } // No.56 KeyColumn??? tagCell = sheet4.getRow(3).getCell(16); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(3, cell.getRow().getRowNum()); assertEquals(16, cell.getColumnIndex()); System.out.println("No.56:" + pe); } // No.57 ValueColumn??? tagCell = sheet4.getRow(12).getCell(16); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(12, cell.getRow().getRowNum()); assertEquals(16, cell.getColumnIndex()); System.out.println("No.57:" + pe); } // No.58 KeyCell??? tagCell = sheet4.getRow(21).getCell(16); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(21, cell.getRow().getRowNum()); assertEquals(16, cell.getColumnIndex()); System.out.println("No.58:" + pe); } // No.59 ValueCell??? tagCell = sheet4.getRow(30).getCell(16); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(30, cell.getRow().getRowNum()); assertEquals(16, cell.getColumnIndex()); System.out.println("No.59:" + pe); } // No.60 DataRowFrom??? tagCell = sheet4.getRow(34).getCell(3); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(34, cell.getRow().getRowNum()); assertEquals(3, cell.getColumnIndex()); System.out.println("No.60:" + pe); } // No.61 DataRowTo??? tagCell = sheet4.getRow(34).getCell(6); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(34, cell.getRow().getRowNum()); assertEquals(6, cell.getColumnIndex()); System.out.println("No.61:" + pe); } // No.62 KeyCell??? tagCell = sheet4.getRow(34).getCell(9); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(34, cell.getRow().getRowNum()); assertEquals(9, cell.getColumnIndex()); System.out.println("No.62:" + pe); } // No.63 ValueCell??? tagCell = sheet4.getRow(34).getCell(12); map.clear(); try { map = mapParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(34, cell.getRow().getRowNum()); assertEquals(12, cell.getColumnIndex()); System.out.println("No.63:" + pe); } }
From source file:org.bbreak.excella.core.tag.excel2java.MapsParserTest.java
License:Open Source License
@Test public final void testMapsParser() throws ParseException { Workbook wk = getWorkbook();/* ww w . java2 s . com*/ Sheet sheet1 = wk.getSheetAt(0); Sheet sheet2 = wk.getSheetAt(1); Sheet sheet3 = wk.getSheetAt(2); Sheet sheet4 = wk.getSheetAt(3); Sheet sheet5 = wk.getSheetAt(4); MapsParser mapsParser = new MapsParser("@Maps"); Cell tagCell = null; Object data = null; List<Map<?, ?>> maps = null; // No.1 ? tagCell = sheet1.getRow(5).getCell(0); maps = mapsParser.parse(sheet1, tagCell, data); assertEquals("value1-1", maps.get(0).get("key1")); assertEquals("value2-1", maps.get(0).get("key2")); assertEquals(2, maps.get(0).keySet().size()); assertEquals("value1-2", maps.get(1).get("key1")); assertEquals("value2-2", maps.get(1).get("key2")); assertEquals(2, maps.get(1).keySet().size()); assertEquals("value1-3", maps.get(2).get("key1")); assertEquals("value2-3", maps.get(2).get("key2")); assertEquals(2, maps.get(2).keySet().size()); assertEquals(3, maps.size()); // No.2 ? tagCell = sheet2.getRow(5).getCell(0); maps.clear(); maps = mapsParser.parse(sheet2, tagCell, data); assertEquals(0, maps.size()); // No.3 tagCell = sheet3.getRow(5).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value1-1", maps.get(0).get("key1")); assertEquals("value2-1", maps.get(0).get("key2")); assertEquals(2, maps.get(0).keySet().size()); assertEquals("value1-2", maps.get(1).get("key1")); assertEquals("value2-2", maps.get(1).get("key2")); assertEquals(2, maps.get(1).keySet().size()); assertEquals(2, maps.size()); // No.4 ?? tagCell = sheet3.getRow(13).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value3-1", maps.get(0).get("key3")); assertEquals("value4-1", maps.get(0).get("key4")); assertEquals(2, maps.get(0).keySet().size()); assertEquals("value3-2", maps.get(1).get("key3")); assertEquals("value4-2", maps.get(1).get("key4")); assertEquals(2, maps.get(1).keySet().size()); assertEquals(2, maps.size()); // No.5 tagCell = sheet3.getRow(23).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value5-1", maps.get(0).get("key5")); assertEquals("value6-1", maps.get(0).get("key6")); assertEquals(null, maps.get(2).get("key7")); assertEquals("value8-1", maps.get(0).get("key8")); assertEquals(3, maps.get(0).keySet().size()); assertEquals("value5-2", maps.get(1).get("key5")); assertEquals("value6-2", maps.get(1).get("key6")); assertEquals(null, maps.get(2).get("key7")); assertEquals("value8-2", maps.get(1).get("key8")); assertEquals(3, maps.get(1).keySet().size()); assertEquals("value5-3", maps.get(2).get("key5")); assertEquals("value6-3", maps.get(2).get("key6")); assertEquals(null, maps.get(2).get("key7")); assertEquals("value8-3", maps.get(2).get("key8")); assertEquals(3, maps.get(2).keySet().size()); assertEquals(3, maps.size()); // No.6 ?null tagCell = sheet3.getRow(31).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals(0, maps.size()); // No.7 ?null tagCell = sheet3.getRow(39).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value9-1", maps.get(0).get("key9")); assertEquals("value10-1", maps.get(0).get("key10")); assertEquals(2, maps.get(0).keySet().size()); assertEquals("value9-2", maps.get(1).get("key9")); assertEquals("value10-2", maps.get(1).get("key10")); assertEquals(2, maps.get(1).keySet().size()); assertEquals("value9-3", maps.get(2).get("key9")); assertEquals("value10-3", maps.get(2).get("key10")); assertEquals(2, maps.get(2).keySet().size()); assertEquals(3, maps.size()); // No.8 ?null tagCell = sheet3.getRow(47).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value11-1", maps.get(0).get("key11")); assertEquals("value12-1", maps.get(0).get("key12")); assertEquals(2, maps.get(0).keySet().size()); assertEquals("value11-2", maps.get(1).get("key11")); assertEquals("value12-2", maps.get(1).get("key12")); assertEquals(2, maps.get(1).keySet().size()); assertEquals("value11-3", maps.get(2).get("key11")); assertEquals("value12-3", maps.get(2).get("key12")); assertEquals(2, maps.get(2).keySet().size()); assertEquals(3, maps.size()); // No.9 ?null tagCell = sheet3.getRow(55).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value13-1", maps.get(0).get("key13")); assertEquals("value14-1", maps.get(0).get("key14")); assertEquals(2, maps.get(0).keySet().size()); assertEquals("value13-2", maps.get(1).get("key13")); assertEquals("value14-2", maps.get(1).get("key14")); assertEquals(2, maps.get(1).keySet().size()); assertEquals(2, maps.size()); // No.10 ?null tagCell = sheet3.getRow(63).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value15-1", maps.get(0).get("key15")); assertEquals("value16-1", maps.get(0).get("key16")); assertEquals(2, maps.get(0).keySet().size()); assertEquals(null, maps.get(1).get("key15")); assertEquals(null, maps.get(1).get("key16")); assertEquals(2, maps.get(1).keySet().size()); assertEquals("value15-2", maps.get(2).get("key15")); assertEquals("value16-2", maps.get(2).get("key16")); assertEquals(2, maps.get(2).keySet().size()); assertEquals(3, maps.size()); // No.11 ?null tagCell = sheet3.getRow(71).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value17-1", maps.get(0).get("key17")); assertEquals("value18-1", maps.get(0).get("key18")); assertEquals(2, maps.get(0).keySet().size()); assertEquals(null, maps.get(1).get("key17")); assertEquals(null, maps.get(1).get("key18")); assertEquals(2, maps.get(1).keySet().size()); assertEquals("value17-2", maps.get(2).get("key17")); assertEquals("value18-2", maps.get(2).get("key18")); assertEquals(2, maps.get(2).keySet().size()); assertEquals(3, maps.size()); // No.12 ? tagCell = sheet3.getRow(79).getCell(0); maps.clear(); maps = mapsParser.parse(sheet3, tagCell, data); assertEquals("value19-4", maps.get(0).get("key19")); assertEquals(1, maps.get(0).keySet().size()); assertEquals(null, maps.get(1).get("key19")); assertEquals(1, maps.get(1).keySet().size()); assertEquals("value19-5", maps.get(2).get("key19")); assertEquals(1, maps.get(2).keySet().size()); assertEquals(3, maps.size()); // No.13 tagCell = sheet4.getRow(7).getCell(0); maps.clear(); maps = mapsParser.parse(sheet4, tagCell, data); assertEquals("value1-1", maps.get(0).get("key1")); assertEquals("value2-1", maps.get(0).get("key2")); assertEquals(2, maps.get(0).keySet().size()); assertEquals("value1-2", maps.get(1).get("key1")); assertEquals("value2-2", maps.get(1).get("key2")); assertEquals(2, maps.get(1).keySet().size()); assertEquals("value1-3", maps.get(2).get("key1")); assertEquals("value2-3", maps.get(2).get("key2")); assertEquals(2, maps.get(2).keySet().size()); assertEquals("value1-4", maps.get(3).get("key1")); assertEquals("value2-4", maps.get(3).get("key2")); assertEquals(2, maps.get(3).keySet().size()); assertEquals(4, maps.size()); // No.14 ? tagCell = sheet4.getRow(12).getCell(0); maps.clear(); maps = mapsParser.parse(sheet4, tagCell, data); assertEquals("1", maps.get(0).get("1")); assertEquals("2", maps.get(0).get("2")); assertEquals(2, maps.get(0).keySet().size()); assertEquals(1, maps.size()); // No.15 DataRowFrom > DataRowTo tagCell = sheet4.getRow(21).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(21, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.15:" + pe); } // No.16 KeyRow?? tagCell = sheet4.getRow(27).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(27, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.16:" + pe); } // No.17 DataRowFrom?? tagCell = sheet4.getRow(30).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(30, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.17:" + pe); } // No.18 DataRowTo?? tagCell = sheet4.getRow(33).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(33, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.18:" + pe); } // No.19 KeyRow?? tagCell = sheet4.getRow(36).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(36, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.19:" + pe); } // No.20 DataRowFrom?? tagCell = sheet4.getRow(39).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(39, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.20:" + pe); } // No.21 DataRowFrom?? tagCell = sheet4.getRow(42).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet4, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(42, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.21:" + pe); } // No.22 KeyRow?1?? tagCell = sheet5.getRow(0).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.22:" + pe); } // No.23 DataRowFrom?1?? tagCell = sheet5.getRow(0).getCell(3); maps.clear(); try { maps = mapsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(3, cell.getColumnIndex()); System.out.println("No.23:" + pe); } // No.24 DataRowTo?1?? tagCell = sheet5.getRow(0).getCell(6); maps.clear(); try { maps = mapsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(6, cell.getColumnIndex()); System.out.println("No.24:" + pe); } // No.25 KeyRow??? tagCell = sheet5.getRow(18).getCell(0); maps.clear(); try { maps = mapsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.25:" + pe); } // No.26 DataRowFrom??? tagCell = sheet5.getRow(18).getCell(3); maps.clear(); try { maps = mapsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(3, cell.getColumnIndex()); System.out.println("No.26:" + pe); } // No.27 DataRowTo??? tagCell = sheet5.getRow(18).getCell(6); maps.clear(); try { maps = mapsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(6, cell.getColumnIndex()); System.out.println("No.27:" + pe); } }
From source file:org.bbreak.excella.core.tag.excel2java.ObjectsParserTest.java
License:Open Source License
@Test public final void testObjectsParser() throws ParseException, java.text.ParseException { Workbook wk = getWorkbook();//from w ww .ja va 2 s . co m Sheet sheet1 = wk.getSheetAt(0); Sheet sheet2 = wk.getSheetAt(1); Sheet sheet3 = wk.getSheetAt(2); Sheet sheet4 = wk.getSheetAt(3); Sheet sheet5 = wk.getSheetAt(4); ObjectsParser objectsParser = new ObjectsParser("@Objects"); Cell tagCell = null; Object data = null; List<Object> list = null; // No.1 ? tagCell = sheet1.getRow(5).getCell(0); try { list = objectsParser.parse(sheet1, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(5, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.1:" + pe); } // No.2 tagCell = sheet1.getRow(13).getCell(0); list = objectsParser.parse(sheet1, tagCell, data); TargetEntity targetEntity = (TargetEntity) list.get(0); assertEquals(new Integer("1"), targetEntity.getNumberInteger()); assertEquals(2, targetEntity.getNumberInt()); assertEquals(new Long("3"), targetEntity.getNumberLong()); assertEquals(4, targetEntity.getNumberlong()); assertEquals(new Float("5.5"), targetEntity.getNumberFloat()); assertEquals("6.6", String.valueOf(targetEntity.getNumberfloat())); assertEquals(new Double("8.8"), targetEntity.getNumberDouble()); assertEquals("9.9", String.valueOf(targetEntity.getNumberdouble())); assertEquals(new BigDecimal(10.1), targetEntity.getNumberDecimal()); assertEquals(new Byte("11"), targetEntity.getNumberByte()); assertEquals(12, targetEntity.getNumberbyte()); assertEquals(Boolean.TRUE, targetEntity.getValueBoolean()); assertEquals(Boolean.FALSE, targetEntity.isValueboolean()); assertEquals(DateFormat.getDateInstance().parse("2009/4/13"), targetEntity.getDate()); assertEquals("", targetEntity.getString()); assertEquals(1, list.size()); // No.3 ?? tagCell = sheet2.getRow(4).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Integer("1"), targetEntity.getNumberInteger()); assertEquals(3, targetEntity.getNumberInt()); targetEntity = (TargetEntity) list.get(1); assertEquals(new Integer("2"), targetEntity.getNumberInteger()); assertEquals(4, targetEntity.getNumberInt()); assertEquals(2, list.size()); // No.4 tagCell = sheet2.getRow(13).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Integer("5"), targetEntity.getNumberInteger()); assertEquals(9, targetEntity.getNumberInt()); targetEntity = (TargetEntity) list.get(1); assertEquals(new Integer("6"), targetEntity.getNumberInteger()); assertEquals(10, targetEntity.getNumberInt()); assertEquals(2, list.size()); // No.5 ?null tagCell = sheet2.getRow(20).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); assertEquals(0, list.size()); // No.6 ?null tagCell = sheet2.getRow(28).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(20000000, targetEntity.getNumberlong()); assertEquals(new Long("26000000"), targetEntity.getNumberLong()); targetEntity = (TargetEntity) list.get(1); assertEquals(21000000, targetEntity.getNumberlong()); assertEquals(new Long("27000000"), targetEntity.getNumberLong()); targetEntity = (TargetEntity) list.get(2); assertEquals(22000000, targetEntity.getNumberlong()); assertEquals(new Long("28000000"), targetEntity.getNumberLong()); assertEquals(3, list.size()); // No.7 ?null tagCell = sheet2.getRow(36).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(29000000, targetEntity.getNumberlong()); assertEquals(new Long("35000000"), targetEntity.getNumberLong()); targetEntity = (TargetEntity) list.get(1); assertEquals(30000000, targetEntity.getNumberlong()); assertEquals(new Long("36000000"), targetEntity.getNumberLong()); targetEntity = (TargetEntity) list.get(2); assertEquals(31000000, targetEntity.getNumberlong()); assertEquals(new Long("37000000"), targetEntity.getNumberLong()); assertEquals(3, list.size()); // No.8 ?null tagCell = sheet2.getRow(44).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Float("38000000"), targetEntity.getNumberFloat()); assertEquals(40000000, targetEntity.getNumberfloat(), 0.01); targetEntity = (TargetEntity) list.get(1); assertEquals(new Float("39000000"), targetEntity.getNumberFloat()); assertEquals(41000000, targetEntity.getNumberfloat(), 0.01); assertEquals(2, list.size()); // No.9 ?null tagCell = sheet2.getRow(52).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Float("42000000"), targetEntity.getNumberFloat()); assertEquals(new Double("44000000"), targetEntity.getNumberDouble()); targetEntity = (TargetEntity) list.get(1); assertEquals(null, targetEntity.getNumberFloat()); assertEquals(null, targetEntity.getNumberDouble()); targetEntity = (TargetEntity) list.get(2); assertEquals(new Float("43000000"), targetEntity.getNumberFloat()); assertEquals(new Double("45000000"), targetEntity.getNumberDouble()); assertEquals(3, list.size()); // No.10 ?null tagCell = sheet2.getRow(60).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Float("46000000"), targetEntity.getNumberFloat()); assertEquals(new Double("48000000"), targetEntity.getNumberDouble()); targetEntity = (TargetEntity) list.get(1); assertEquals(null, targetEntity.getNumberFloat()); assertEquals(null, targetEntity.getNumberDouble()); targetEntity = (TargetEntity) list.get(2); assertEquals(new Float("47000000"), targetEntity.getNumberFloat()); assertEquals(new Double("49000000"), targetEntity.getNumberDouble()); assertEquals(3, list.size()); // No.11 ? tagCell = sheet2.getRow(68).getCell(0); list.clear(); list = objectsParser.parse(sheet2, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Double("8.8888888"), targetEntity.getNumberDouble()); targetEntity = (TargetEntity) list.get(1); assertEquals(null, targetEntity.getNumberDouble()); targetEntity = (TargetEntity) list.get(2); assertEquals(new Double("9.9999999"), targetEntity.getNumberDouble()); assertEquals(3, list.size()); // No.12 tagCell = sheet3.getRow(7).getCell(0); list.clear(); list = objectsParser.parse(sheet3, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(Boolean.TRUE, targetEntity.getValueBoolean()); assertEquals("1", targetEntity.getString()); targetEntity = (TargetEntity) list.get(1); assertEquals(Boolean.TRUE, targetEntity.getValueBoolean()); assertEquals("2", targetEntity.getString()); targetEntity = (TargetEntity) list.get(2); assertEquals(Boolean.FALSE, targetEntity.getValueBoolean()); assertEquals("3", targetEntity.getString()); targetEntity = (TargetEntity) list.get(3); assertEquals(Boolean.FALSE, targetEntity.getValueBoolean()); assertEquals("4", targetEntity.getString()); assertEquals(4, list.size()); // No.13 ???? tagCell = sheet3.getRow(12).getCell(0); list.clear(); list = objectsParser.parse(sheet3, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals("string", targetEntity.getString()); assertEquals(1, list.size()); // No.14 DataRowFrom > DataRowTo tagCell = sheet3.getRow(21).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(21, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.14:" + pe); } // No.15 PropertyRow?? tagCell = sheet3.getRow(27).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(27, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.15:" + pe); } // No.16 DataRowFrom?? tagCell = sheet3.getRow(30).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(30, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.16:" + pe); } // No.17 DataRowTo?? tagCell = sheet3.getRow(33).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(33, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.17:" + pe); } // No.18 PropertyRow?? tagCell = sheet3.getRow(36).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(36, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.18:" + pe); } // No.19 DataRowFrom?? tagCell = sheet3.getRow(39).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(39, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.19:" + pe); } // No.20 DataRowTo?? tagCell = sheet3.getRow(42).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(42, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.20:" + pe); } // No.21 Class???? tagCell = sheet3.getRow(46).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(46, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.21:" + pe); } // No.22 ??? tagCell = sheet3.getRow(50).getCell(0); list.clear(); list = objectsParser.parse(sheet3, tagCell, data); assertEquals(0, list.size()); // No.23 ? tagCell = sheet3.getRow(55).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(57, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.23:" + pe); } // No.24 ? tagCell = sheet3.getRow(61).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(62, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.24:" + pe); } // No.25 ??private tagCell = sheet3.getRow(67).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(68, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.25:" + pe); } // No.26 ?? tagCell = sheet3.getRow(73).getCell(0); list.clear(); try { list = objectsParser.parse(sheet3, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(74, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.26:" + pe); } // No.27 tagCell = sheet4.getRow(1).getCell(0); ChildNameParser childNameParser = new ChildNameParser(""); childNameParser.setTag("@childName"); assertEquals("@childName", childNameParser.getTag()); assertEquals(Boolean.FALSE, childNameParser.isParse(sheet4, null)); objectsParser.addPropertyParser(childNameParser); list.clear(); list = objectsParser.parse(sheet4, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals("childName1", targetEntity.getChildEntity().getChildName()); targetEntity = (TargetEntity) list.get(1); assertEquals("childName2", targetEntity.getChildEntity().getChildName()); assertEquals(2, list.size()); // No.28 ? tagCell = sheet4.getRow(8).getCell(0); list.clear(); objectsParser.removePropertyParser(childNameParser); list = objectsParser.parse(sheet4, tagCell, data); assertEquals(0, list.size()); // No.29 ? tagCell = sheet4.getRow(15).getCell(0); list.clear(); ChildNoParser childNoParser = new ChildNoParser("@childNo"); objectsParser.addPropertyParser(childNameParser); objectsParser.addPropertyParser(childNoParser); list = objectsParser.parse(sheet4, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Integer("55"), targetEntity.getNumberInteger()); assertEquals("childName5", targetEntity.getChildEntity().getChildName()); assertEquals(5, targetEntity.getChildEntity().getChildNo()); targetEntity = (TargetEntity) list.get(1); assertEquals(new Integer("66"), targetEntity.getNumberInteger()); assertEquals("childName6", targetEntity.getChildEntity().getChildName()); assertEquals(6, targetEntity.getChildEntity().getChildNo()); assertEquals(2, list.size()); // No.30 tagCell = sheet4.getRow(22).getCell(0); list.clear(); objectsParser.clearPropertyParsers(); list = objectsParser.parse(sheet4, tagCell, data); targetEntity = (TargetEntity) list.get(0); assertEquals(new Integer("77"), targetEntity.getNumberInteger()); assertEquals(null, targetEntity.getChildEntity()); targetEntity = (TargetEntity) list.get(1); assertEquals(new Integer("88"), targetEntity.getNumberInteger()); assertEquals(null, targetEntity.getChildEntity()); assertEquals(2, list.size()); // No.31 PropertyRow?1?? tagCell = sheet5.getRow(0).getCell(0); list.clear(); try { list = objectsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.31:" + pe); } // No.32 DataRowFrom?1?? tagCell = sheet5.getRow(0).getCell(8); list.clear(); try { list = objectsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(8, cell.getColumnIndex()); System.out.println("No.32:" + pe); } // No.33 DataRowTo?1?? tagCell = sheet5.getRow(0).getCell(16); list.clear(); try { list = objectsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(0, cell.getRow().getRowNum()); assertEquals(16, cell.getColumnIndex()); System.out.println("No.33:" + pe); } // No.34 PropertyRow??? tagCell = sheet5.getRow(18).getCell(0); list.clear(); try { list = objectsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(0, cell.getColumnIndex()); System.out.println("No.34:" + pe); } // No.35 DataRowFrom??? tagCell = sheet5.getRow(18).getCell(8); list.clear(); try { list = objectsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(8, cell.getColumnIndex()); System.out.println("No.35:" + pe); } // No.36 DataRowTo??? tagCell = sheet5.getRow(18).getCell(16); list.clear(); try { list = objectsParser.parse(sheet5, tagCell, data); fail(); } catch (ParseException pe) { Cell cell = pe.getCell(); assertEquals(18, cell.getRow().getRowNum()); assertEquals(16, cell.getColumnIndex()); System.out.println("No.36:" + pe); } }
From source file:org.bbreak.excella.core.test.util.TestUtil.java
License:Open Source License
public static void checkCell(Cell expected, Cell actual) throws CheckException { List<CheckMessage> errors = new ArrayList<CheckMessage>(); // ---------------------- // ????//from w ww .ja v a 2s .c om // ---------------------- if (expected == null && actual == null) { return; } if (expected == null) { errors.add(new CheckMessage("(" + actual.getRowIndex() + "," + actual.getColumnIndex() + ")", null, actual.toString())); throw new CheckException(errors); } if (actual == null) { errors.add(new CheckMessage("(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")", expected.toString(), null)); throw new CheckException(errors); } // if (expected.getCellTypeEnum() != actual.getCellTypeEnum()) { errors.add(new CheckMessage( "[" + "(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")" + "]", String.valueOf(expected.getCellTypeEnum()), String.valueOf(actual.getCellTypeEnum()))); throw new CheckException(errors); } try { checkCellStyle(expected.getRow().getSheet().getWorkbook(), expected.getCellStyle(), actual.getRow().getSheet().getWorkbook(), actual.getCellStyle()); } catch (CheckException e) { CheckMessage checkMessage = e.getCheckMessages().iterator().next(); checkMessage.setMessage("(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")" + checkMessage.getMessage()); errors.add(checkMessage); throw new CheckException(errors); } // log.error("(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")"); if (!getCellValue(expected).equals(getCellValue(actual))) { log.error(getCellValue(expected) + " / " + getCellValue(actual)); errors.add(new CheckMessage( "[" + "(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")" + "]", String.valueOf(getCellValue(actual)), String.valueOf(getCellValue(expected)))); throw new CheckException(errors); } }
From source file:org.bbreak.excella.core.util.PoiUtil.java
License:Open Source License
/** * ???/*www .j av a 2s .c om*/ * * @param cell * @param type * @param address ? * @see org.apache.poi.common.usermodel.Hyperlink */ public static void setHyperlink(Cell cell, HyperlinkType hyperlinkType, String address) { Workbook wb = cell.getRow().getSheet().getWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Hyperlink link = createHelper.createHyperlink(hyperlinkType); if (link instanceof HSSFHyperlink) { ((HSSFHyperlink) link).setTextMark(address); } else if (link instanceof XSSFHyperlink) { ((XSSFHyperlink) link).setAddress(address); } cell.setHyperlink(link); }
From source file:org.bbreak.excella.reports.ReportsTestUtil.java
License:Open Source License
/** * // w w w . j a v a2 s .c om * * @param expected * @param actual * @throws ReportsCheckException */ public static void checkCell(Cell expected, Cell actual) throws ReportsCheckException { List<CheckMessage> errors = new ArrayList<CheckMessage>(); // ---------------------- // ???? // ---------------------- if (expected == null && actual == null) { return; } if (expected == null) { // if(actual.getCellStyle() != null || actual.getCellType() != Cell.CELL_TYPE_BLANK){ errors.add(new CheckMessage("(" + actual.getRowIndex() + "," + actual.getColumnIndex() + ")", null, actual.toString())); throw new ReportsCheckException(errors); // } } if (actual == null) { errors.add(new CheckMessage("(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")", expected.toString(), null)); throw new ReportsCheckException(errors); } // if (expected.getCellTypeEnum() != actual.getCellTypeEnum()) { errors.add(new CheckMessage( "[" + "(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")" + "]", getCellTypeString(expected.getCellTypeEnum()), getCellTypeString(actual.getCellTypeEnum()))); throw new ReportsCheckException(errors); } try { checkCellStyle(expected.getRow().getSheet().getWorkbook(), expected.getCellStyle(), actual.getRow().getSheet().getWorkbook(), actual.getCellStyle()); } catch (ReportsCheckException e) { CheckMessage checkMessage = e.getCheckMessages().iterator().next(); checkMessage.setMessage("(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")" + checkMessage.getMessage()); errors.add(checkMessage); throw new ReportsCheckException(errors); } // if (!getCellValue(expected).equals(getCellValue(actual))) { log.error(getCellValue(expected) + " / " + getCellValue(actual)); errors.add(new CheckMessage( "[" + "(" + expected.getRowIndex() + "," + expected.getColumnIndex() + ")" + "]", String.valueOf(getCellValue(expected)), String.valueOf(getCellValue(actual)))); throw new ReportsCheckException(errors); } }
From source file:org.bbreak.excella.reports.tag.BlockColRepeatParamParser.java
License:Open Source License
@Override public ParsedReportInfo parse(Sheet sheet, Cell tagCell, Object data) throws ParseException { try {/*from w w w. j a v a2 s . c o m*/ // ?? Map<String, String> paramDef = TagUtil.getParams(tagCell.getStringCellValue()); // ? checkParam(paramDef, tagCell); ReportsParserInfo info = (ReportsParserInfo) data; ParamInfo paramInfo = info.getParamInfo(); // ParsedReportInfo parsedReportInfo = new ParsedReportInfo(); List<Object> resultList = new ArrayList<Object>(); // BC????? String bcTagname = paramDef.get(PARAM_VALUE); if (log.isDebugEnabled()) { log.debug("BC?? : " + bcTagname); } // ????? Object[] paramInfos = getParamData(paramInfo, bcTagname); if (paramInfos == null) { return parsedReportInfo; } // ???? List<SingleParamParser> singleParsers = getSingleReplaceParsers(info); // POJOParamInfo??? List<ParamInfo> paramInfoList = new ArrayList<ParamInfo>(); for (Object obj : paramInfos) { if (obj instanceof ParamInfo) { paramInfoList.add((ParamInfo) obj); continue; } ParamInfo childParamInfo = new ParamInfo(); Map<String, Object> map = PropertyUtils.describe(obj); for (Map.Entry<String, Object> entry : map.entrySet()) { for (ReportsTagParser<?> parser : singleParsers) { childParamInfo.addParam(parser.getTag(), entry.getKey(), entry.getValue()); } } paramInfoList.add(childParamInfo); } // ?? if (paramDef.containsKey(PARAM_MIN_REPEAT_NUM)) { Integer minRepeatNum = Integer.valueOf(paramDef.get(PARAM_MIN_REPEAT_NUM)); if (minRepeatNum > paramInfoList.size()) { int addEmptyRowNum = minRepeatNum - paramInfoList.size(); for (int num = 0; num < addEmptyRowNum; num++) { ParamInfo childParamInfo = new ParamInfo(); paramInfoList.add(childParamInfo); } } } paramInfos = paramInfoList.toArray(new ParamInfo[paramInfoList.size()]); // ? Integer repeatNum = paramInfos.length; if (paramDef.containsKey(PARAM_REPEAT)) { if (Integer.valueOf(paramDef.get(PARAM_REPEAT)) < repeatNum) { repeatNum = Integer.valueOf(paramDef.get(PARAM_REPEAT)); } } // ? // TODO ? /* * Integer turnNum = null; if (paramDef.containsKey( PARAM_TURN)) { turnNum = Integer.valueOf( paramDef.get( PARAM_TURN)); } */ // ?????????? Map<String, Object> beforeBlockSingleDataMap = new HashMap<String, Object>(); // ??? if (paramDef.containsKey(PARAM_DUPLICATE)) { String[] tmp = paramDef.get(PARAM_DUPLICATE).split(";"); // single??? for (String str : tmp) { for (ReportsTagParser<?> parser : singleParsers) { str = parser.getTag() + TAG_PARAM_PREFIX + str + TAG_PARAM_SUFFIX; // ??key??? beforeBlockSingleDataMap.put(str, ""); } } } // removeTag boolean removeTag = false; if (paramDef.containsKey(PARAM_REMOVE_TAG)) { removeTag = Boolean.valueOf(paramDef.get(PARAM_REMOVE_TAG)); } // fromCell int[] fromCellPosition = ReportsUtil.getCellIndex(paramDef.get(PARAM_FROM), PARAM_FROM); int defaultFromCellRowIndex = tagCell.getRow().getRowNum() + fromCellPosition[0]; int defaultFromCellColIndex = tagCell.getColumnIndex() + fromCellPosition[1]; // toCell int[] toCellIndex = ReportsUtil.getCellIndex(paramDef.get(PARAM_TO), PARAM_TO); int defaultToCellRowIndex = tagCell.getRow().getRowNum() + toCellIndex[0]; int defaultToCellColIndex = tagCell.getColumnIndex() + toCellIndex[1]; // ?(??) int blockEndRowIndex = defaultToCellRowIndex; int blockEndColIndex = defaultToCellColIndex; int blockStartRowIndex = defaultFromCellRowIndex; int blockStartColIndex = defaultFromCellColIndex; // BC??Cell[row][col] Object[][] blockCellsValue = ReportsUtil.getBlockCellValue(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); CellStyle[][] blockCellsStyle = ReportsUtil.getBlockCellStyle(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); CellType[][] blockCellTypes = ReportsUtil.getBlockCellType(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); // ????? int[] columnWidths = ReportsUtil.getColumnWidth(sheet, defaultFromCellColIndex, defaultToCellColIndex); // ? int rowlen = defaultToCellRowIndex - defaultFromCellRowIndex + 1; int collen = defaultToCellColIndex - defaultFromCellColIndex + 1; // ??? CellRangeAddress[] margedCells = ReportsUtil.getMargedCells(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); // ???? int turnCount = 0; int maxblockEndRowIndex = blockEndRowIndex; TagParser<?> parser = null; ParsedReportInfo result = null; // for (int repeatCount = 0; repeatCount < repeatNum; repeatCount++) { collen = defaultToCellColIndex - defaultFromCellColIndex + 1; // ??????blockStartRowIndex??blockEndColIndex? // TODO ? /* * if (turnNum != null && turnNum <= turnCount) { blockStartRowIndex = blockEndRowIndex + 1; blockEndColIndex = 0; turnCount = 0; } */ // if (turnCount > 0) { blockStartColIndex = blockEndColIndex + 1; blockEndColIndex = blockStartColIndex + collen - 1; } else { // ??????? 2009/11/16 // blockStartColIndex = tagCell.getColumnIndex(); } turnCount++; // ???BC if (repeatCount > 0) { CellRangeAddress rangeAddress = new CellRangeAddress(blockStartRowIndex, sheet.getLastRowNum(), blockStartColIndex, blockStartColIndex + collen - 1); PoiUtil.insertRangeRight(sheet, rangeAddress); if (log.isDebugEnabled()) { log.debug(""); log.debug(blockStartRowIndex + ":" + sheet.getLastRowNum() + ":" + blockStartColIndex + ":" + (blockStartColIndex + collen - 1)); } // ??? // ??????????? // ?????? int targetColNum = blockEndColIndex - defaultToCellColIndex; for (CellRangeAddress address : margedCells) { // ???(BC????????) // ???(BC????????) // ??? + BC?? - BC? // ??? + BC?? - BC? int firstRowNum = address.getFirstRow(); int lastRowNum = address.getLastRow(); int firstColumnNum = address.getFirstColumn() + targetColNum; int lastColumnNum = address.getLastColumn() + targetColNum; CellRangeAddress copyAddress = new CellRangeAddress(firstRowNum, lastRowNum, firstColumnNum, lastColumnNum); sheet.addMergedRegion(copyAddress); } } // ? if (log.isDebugEnabled()) { log.debug("?????? =" + repeatCount); } for (int rowIdx = 0; rowIdx < blockCellsValue.length; rowIdx++) { // ? // int copyToRowIndex = blockStartRowIndex + rowIdx; Row row = sheet.getRow(copyToRowIndex); // ??null??????????????? if (row == null && !ReportsUtil.isEmptyRow(blockCellTypes[rowIdx], blockCellsValue[rowIdx], blockCellsStyle[rowIdx])) { // ???? // ? // (??)?????????? // ??null???(RowCreate?)??????????? row = sheet.createRow(copyToRowIndex); } if (row != null) { // ? for (int colIdx = 0; colIdx < blockCellsValue[rowIdx].length; colIdx++) { // int copyToColIndex = blockStartColIndex + colIdx; // ? sheet.setColumnWidth(copyToColIndex, columnWidths[colIdx]); // ? Cell cell = row.getCell(copyToColIndex); // ?? CellType cellType = blockCellTypes[rowIdx][colIdx]; // ?? Object cellValue = blockCellsValue[rowIdx][colIdx]; // ?? CellStyle cellStyle = blockCellsStyle[rowIdx][colIdx]; // ????????????????? if (cell == null && !ReportsUtil.isEmptyCell(cellType, cellValue, cellStyle)) { cell = row.createCell(copyToColIndex); } // if (cell != null) { // ? cell.setCellType(cellType); // ?? PoiUtil.setCellValue(cell, cellValue); // ?? if (cellStyle != null) { cell.setCellStyle(cellStyle); } if (log.isDebugEnabled()) { log.debug("row=" + (copyToRowIndex) + " col" + (copyToColIndex) + ">>>>>>" + blockCellsValue[rowIdx][colIdx]); } } } } } // ????????? int plusRowNum = 0; // ????????? int plusColNum = 0; collen = defaultToCellColIndex - defaultFromCellColIndex + 1; // for (int targetRow = blockStartRowIndex; targetRow < blockStartRowIndex + rowlen + plusRowNum; targetRow++) { if (sheet.getRow(targetRow) == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " : row is not available. continued..."); } continue; } // ? Cell chgTargetCell = null; // for (int targetCol = blockStartColIndex; targetCol <= blockStartColIndex + collen + plusColNum - 1; targetCol++) { // ???? chgTargetCell = sheet.getRow(targetRow).getCell(targetCol); if (chgTargetCell == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " col=" + targetCol + " : cell is not available. continued..."); } continue; } parser = info.getMatchTagParser(sheet, chgTargetCell); if (parser == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " col=" + targetCol + " parser is not available. continued..."); } continue; } String chgTargetCellString = chgTargetCell.getStringCellValue(); if (log.isDebugEnabled()) { log.debug("########## row=" + targetRow + " col=" + targetCol + " =" + chgTargetCellString + " ##########"); } // ? result = (ParsedReportInfo) parser.parse(sheet, chgTargetCell, info.createChildParserInfo((ParamInfo) paramInfos[repeatCount])); // ??? plusRowNum += result.getRowIndex() - result.getDefaultRowIndex(); // ??? plusColNum += result.getColumnIndex() - result.getDefaultColumnIndex(); // ?single??????????? // ??????????? if (parser instanceof SingleParamParser && beforeBlockSingleDataMap.containsKey(chgTargetCellString)) { if (beforeBlockSingleDataMap.get(chgTargetCellString) .equals(result.getParsedObject())) { // PoiUtil.setCellValue(chgTargetCell, ""); } else { // ???? beforeBlockSingleDataMap.put(chgTargetCellString, result.getParsedObject()); } } // ?????????????? if (blockStartColIndex != result.getDefaultColumnIndex() && maxblockEndRowIndex <= blockEndRowIndex && result.getRowIndex() > result.getDefaultRowIndex()) { CellRangeAddress preRangeAddress = new CellRangeAddress(blockEndRowIndex + 1, blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex()), blockStartColIndex, targetCol - 1); PoiUtil.insertRangeDown(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("1 : " + (blockEndRowIndex + 1) + ":" + (blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex())) + ":" + blockStartColIndex + ":" + (targetCol - 1)); } } // R?????? if (parser instanceof RowRepeatParamParser && maxblockEndRowIndex <= blockEndRowIndex && result.getRowIndex() > result.getDefaultRowIndex()) { CellRangeAddress rearRangeAddress = new CellRangeAddress(blockEndRowIndex + 1, blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex()), result.getDefaultColumnIndex() + 1, blockEndColIndex); PoiUtil.insertRangeDown(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("2 : " + (blockEndRowIndex + 1) + ":" + (blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex())) + ":" + (result.getDefaultColumnIndex() + 1) + ":" + blockEndColIndex); } } blockEndRowIndex = defaultToCellRowIndex + plusRowNum; resultList.add(result.getParsedObject()); if (parser instanceof BlockColRepeatParamParser || parser instanceof BlockRowRepeatParamParser) { collen += result.getColumnIndex() - result.getDefaultColumnIndex(); plusColNum -= result.getColumnIndex() - result.getDefaultColumnIndex(); } // ???????? if (blockStartColIndex + collen + plusColNum - 1 > blockEndColIndex) { int beforeLastColIndex = blockEndColIndex; blockEndColIndex = blockStartColIndex + collen + plusColNum - 1; // ??????????? CellRangeAddress preRangeAddress = new CellRangeAddress(tagCell.getRowIndex(), targetRow - 1, beforeLastColIndex + 1, blockEndColIndex); PoiUtil.insertRangeRight(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("1 : " + tagCell.getRowIndex() + ":" + (targetRow - 1) + ":" + (beforeLastColIndex + 1) + ":" + blockEndColIndex); } // ?????? int lastRowNum = sheet.getLastRowNum(); if ((blockEndRowIndex + 1) <= lastRowNum && (beforeLastColIndex + 1) <= blockEndColIndex) { CellRangeAddress rangeAddress = new CellRangeAddress(blockEndRowIndex + 1, lastRowNum, beforeLastColIndex + 1, blockEndColIndex); PoiUtil.insertRangeRight(sheet, rangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("3 : " + (blockEndRowIndex + 1) + ":" + lastRowNum + ":" + (beforeLastColIndex + 1) + ":" + blockEndColIndex); } } } // ? } // ?????? if (blockStartColIndex + collen + plusColNum - 1 < blockEndColIndex) { CellRangeAddress rearRangeAddress = new CellRangeAddress(targetRow, targetRow, blockStartColIndex + collen + plusColNum, blockEndColIndex); PoiUtil.insertRangeRight(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("2 : " + targetRow + ":" + targetRow + ":" + (blockStartColIndex + collen + plusColNum) + ":" + blockEndColIndex); } } plusColNum = 0; // ? } // ??????? if (maxblockEndRowIndex < blockEndRowIndex) { if (log.isDebugEnabled()) { log.debug("******"); } if (repeatCount != 0) { CellRangeAddress preRangeAddress = new CellRangeAddress(maxblockEndRowIndex + 1, blockEndRowIndex, defaultFromCellColIndex, blockStartColIndex - 1); PoiUtil.insertRangeDown(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("1 : " + (maxblockEndRowIndex + 1) + ":" + blockEndRowIndex + ":" + defaultFromCellColIndex + ":" + (blockStartColIndex - 1)); } } // ??????? CellRangeAddress rearRangeAddress = new CellRangeAddress(maxblockEndRowIndex + 1, blockEndRowIndex, blockEndColIndex + 1, PoiUtil.getLastColNum(sheet)); PoiUtil.insertRangeDown(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("2 : " + (maxblockEndRowIndex + 1) + ":" + blockEndRowIndex + ":" + (blockEndColIndex + 1) + ":" + PoiUtil.getLastColNum(sheet)); } maxblockEndRowIndex = blockEndRowIndex; } } // if (removeTag) { tagCell.setCellType(CellType.BLANK); } // parsedReportInfo.setDefaultRowIndex(defaultToCellRowIndex); parsedReportInfo.setDefaultColumnIndex(defaultToCellColIndex); parsedReportInfo.setColumnIndex(blockEndColIndex); parsedReportInfo.setParsedObject(resultList); parsedReportInfo.setRowIndex(maxblockEndRowIndex); if (log.isDebugEnabled()) { log.debug("finalBlockRowIndex= " + maxblockEndRowIndex); log.debug("finalBlockColIndex=" + blockEndColIndex); } return parsedReportInfo; } catch (Exception e) { throw new ParseException(tagCell, e); } }