1
2
3
4
5
6 package org.weda.report.excel;
7
8 import java.util.HashMap;
9 import java.util.Map;
10 import org.apache.poi.hssf.usermodel.HSSFCell;
11 import org.apache.poi.hssf.usermodel.HSSFRow;
12 import org.apache.poi.hssf.usermodel.HSSFSheet;
13
14 /**
15 *
16 * @author Mikhail Titov
17 */
18 public class CellMarkersManager {
19 private Map<HSSFSheet, Map<String
20 sheetMarkers;
21
22 public void analyze(HSSFSheet sheet){
23 if (sheetMarkers==null)
24 sheetMarkers = new HashMap<HSSFSheet, Map<String, CellPosition>>();
25 if (!sheetMarkers.containsKey(sheet)){
26 Map<String, CellPosition> markers =
27 new HashMap<String, CellPosition>();
28 sheetMarkers.put(sheet, markers);
29
30 for (int r=0; r<=sheet.getLastRowNum(); ++r){
31 HSSFRow row = sheet.getRow(r);
32 if (row==null)
33 continue;
34 for (short c=0; c<=row.getLastCellNum(); ++c){
35 HSSFCell cell = row.getCell(c);
36 if ( cell!=null
37 && cell.getCellType()==HSSFCell.CELL_TYPE_STRING)
38 {
39 String cellValue = cell.getStringCellValue();
40 if ( cellValue.startsWith("#{")
41 && cellValue.endsWith("}"))
42 {
43 String marker =
44 cellValue.substring(
45 2, cellValue.length()-1);
46 markers.put(marker, new CellPosition(r, c));
47 }
48 }
49 }
50 }
51 }
52 }
53
54 public CellPosition getMarkedCellPosition(
55 HSSFSheet sheet, String tableModelName, int col)
56 {
57 String marker = tableModelName+"."+col;
58 Map<String, CellPosition> markers = sheetMarkers.get(sheet);
59 return markers==null? null : markers.get(marker);
60 }
61
62 }