01: package com.technoetic.xplanner.importer.spreadsheet;
02:
03: import org.apache.poi.hssf.usermodel.*;
04: import org.apache.commons.lang.StringUtils;
05:
06: /**
07: * Created by IntelliJ IDEA.
08: * User: tkmower
09: * Date: Mar 31, 2005
10: * Time: 11:54:54 PM
11: */
12: public class SpreadsheetHeaderReader {
13: private HSSFSheet sheet;
14:
15: public void setWorksheet(HSSFSheet worksheet) {
16: sheet = worksheet;
17: }
18:
19: public int getColumnIndex(String headerText) {
20: HSSFRow row = sheet.getRow(0);
21:
22: for (short i = row.getFirstCellNum(); i < row.getLastCellNum(); ++i) {
23: String stringCellValue = getTextForCell(row, i);
24: if ((stringCellValue != null)
25: && !StringUtils.isEmpty(headerText)
26: && (headerText.equalsIgnoreCase(stringCellValue
27: .trim()))) {
28: return i;
29: }
30: }
31: return -1;
32: }
33:
34: private String getTextForCell(HSSFRow row, short i) {
35: HSSFCell cell = row.getCell(i);
36: if (cell == null) {
37: return null;
38: }
39: return cell.getStringCellValue();
40: }
41: }
|