You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SVTableModel.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.view;
  16. import java.util.Iterator;
  17. import javax.swing.table.*;
  18. import org.apache.poi.hssf.usermodel.HSSFRow;
  19. import org.apache.poi.hssf.usermodel.HSSFSheet;
  20. import org.apache.poi.hssf.usermodel.HSSFCell;
  21. /**
  22. * Sheet Viewer Table Model - The model for the Sheet Viewer just overrides things.
  23. * @author Andrew C. Oliver
  24. */
  25. public class SVTableModel extends AbstractTableModel {
  26. private HSSFSheet st = null;
  27. int maxcol = 0;
  28. public SVTableModel(HSSFSheet st, int maxcol) {
  29. this.st = st;
  30. this.maxcol=maxcol;
  31. }
  32. public SVTableModel(HSSFSheet st) {
  33. this.st = st;
  34. Iterator i = st.rowIterator();
  35. while (i.hasNext()) {
  36. HSSFRow row = (HSSFRow)i.next();
  37. if (maxcol < (row.getLastCellNum()+1)) {
  38. this.maxcol = row.getLastCellNum();
  39. }
  40. }
  41. }
  42. public int getColumnCount() {
  43. return this.maxcol+1;
  44. }
  45. public Object getValueAt(int row, int col) {
  46. HSSFRow r = st.getRow(row);
  47. HSSFCell c = null;
  48. if (r != null) {
  49. c = r.getCell(col);
  50. }
  51. return c;
  52. }
  53. public int getRowCount() {
  54. return st.getLastRowNum() + 1;
  55. }
  56. public Class getColumnClass(int c) {
  57. return HSSFCell.class;
  58. }
  59. public boolean isCellEditable(int rowIndex, int columnIndex) {
  60. return true;
  61. }
  62. public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
  63. if (aValue != null)
  64. System.out.println("SVTableModel.setValueAt. value type = "+aValue.getClass().getName());
  65. else System.out.println("SVTableModel.setValueAt. value type = null");
  66. }
  67. }