1 2 17 18 19 20 package org.apache.poi.hssf.contrib.view; 21 22 import java.util.Iterator ; 23 import javax.swing.table.*; 24 25 import org.apache.poi.hssf.usermodel.HSSFRow; 26 import org.apache.poi.hssf.usermodel.HSSFSheet; 27 import org.apache.poi.hssf.usermodel.HSSFCell; 28 29 33 34 public class SVTableModel extends AbstractTableModel { 35 private HSSFSheet st = null; 36 int maxcol = 0; 37 38 public SVTableModel(HSSFSheet st, int maxcol) { 39 this.st = st; 40 this.maxcol=maxcol; 41 } 42 43 public SVTableModel(HSSFSheet st) { 44 this.st = st; 45 Iterator i = st.rowIterator(); 46 47 while (i.hasNext()) { 48 HSSFRow row = (HSSFRow)i.next(); 49 if (maxcol < (row.getLastCellNum()+1)) { 50 this.maxcol = row.getLastCellNum(); 51 } 52 } 53 } 54 55 56 public int getColumnCount() { 57 return this.maxcol+1; 58 } 59 public Object getValueAt(int row, int col) { 60 HSSFRow r = st.getRow(row); 61 HSSFCell c = null; 62 if (r != null) { 63 c = r.getCell((short)col); 64 } 65 return c; 66 } 67 public int getRowCount() { 68 return st.getLastRowNum() + 1; 69 } 70 71 public Class getColumnClass(int c) { 72 return HSSFCell.class; 73 } 74 75 public boolean isCellEditable(int rowIndex, int columnIndex) { 76 return true; 77 } 78 79 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 80 if (aValue != null) 81 System.out.println("SVTableModel.setValueAt. value type = "+aValue.getClass().getName()); 82 else System.out.println("SVTableModel.setValueAt. value type = null"); 83 } 84 85 86 } 87 | Popular Tags |