1 36 37 package com.bluecubs.xinco.index.filetypes; 38 39 import java.io.File ; 40 import java.io.FileInputStream ; 41 import java.io.InputStream ; 42 import java.io.Reader ; 43 import org.apache.poi.hssf.usermodel.HSSFCell; 44 import org.apache.poi.hssf.usermodel.HSSFRow; 45 import org.apache.poi.hssf.usermodel.HSSFSheet; 46 import org.apache.poi.hssf.usermodel.HSSFWorkbook; 47 import org.apache.poi.poifs.filesystem.POIFSFileSystem; 48 49 public class XincoIndexMicrosoftExcel implements XincoIndexFileType { 50 51 public XincoIndexMicrosoftExcel() { 52 super(); 53 } 54 55 public Reader getFileContentReader(File f) { 56 return null; 57 } 58 59 public String getFileContentString(File f) { 60 int i,j,j2,k; 61 short k2; 62 HSSFWorkbook wb = null; 63 HSSFSheet sheet = null; 64 HSSFRow row = null; 65 HSSFCell cell = null; 66 InputStream is = null; 67 String cell_string = ""; 68 try { 69 is = new FileInputStream (f); 70 POIFSFileSystem fs = new POIFSFileSystem(is); 71 wb = new HSSFWorkbook(fs); 72 for (i=0;i<wb.getNumberOfSheets();i++) { 73 sheet = wb.getSheetAt(i); 74 j2 = 0; 75 for (j=0;j<sheet.getPhysicalNumberOfRows();j++) { 76 while ((row = sheet.getRow(j2)) == null) { 77 j2++; 78 } 79 j2++; 80 k2 = 0; 81 for (k=0;k<row.getPhysicalNumberOfCells();k++) { 82 while ((cell = row.getCell(k2)) == null) { 83 k2++; 84 } 85 k2++; 86 switch (cell.getCellType()) { 87 case HSSFCell.CELL_TYPE_FORMULA : 88 break; 89 case HSSFCell.CELL_TYPE_NUMERIC : 90 cell_string = cell_string + cell.getNumericCellValue() + "\t"; 91 break; 92 case HSSFCell.CELL_TYPE_STRING : 93 cell_string = cell_string + cell.getStringCellValue() + "\t"; 94 break; 95 default : 96 } 97 98 } 99 cell_string = cell_string + "\n"; 100 } 101 cell_string = cell_string + "\n\n\n"; 102 } 103 is.close(); 104 } catch (Exception fe) { 105 cell_string = null; 106 if (is != null) { 107 try { 108 is.close(); 109 } catch (Exception ise) {} 110 } 111 } 112 return cell_string; 113 } 114 115 } 116 | Popular Tags |