Changeset 20457
- Timestamp:
- 02/23/10 13:56:46 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tools/propertyExporter/src/net/project/poi/Import.java
r18721 r20457 15 15 import java.util.Properties; 16 16 17 import org.apache.commons.lang.StringUtils; 17 18 import org.apache.poi.hssf.usermodel.HSSFCell; 19 import org.apache.poi.hssf.usermodel.HSSFRichTextString; 18 20 import org.apache.poi.hssf.usermodel.HSSFRow; 19 21 import org.apache.poi.hssf.usermodel.HSSFSheet; … … 60 62 try { 61 63 fileSystem = new POIFSFileSystem(inputStream); 62 64 // 63 65 HSSFWorkbook workBook = new HSSFWorkbook(fileSystem); 64 66 HSSFSheet sheet = workBook.getSheetAt(0); … … 75 77 // set property value, property_value_clob 76 78 HSSFCell cell = row.getCell(1); 77 if ("text".equals(cell.getRichStringCellValue().toString())){ 79 HSSFRichTextString cellRich = cell.getRichStringCellValue(); 80 String type = StringUtils.EMPTY; 81 if (cellRich != null) { 82 type = cellRich.toString(); 83 } 84 if ("text".equals(type) || "largetext".equals(type)) { 78 85 cell = row.getCell(2); 79 ps.setString(1, cell.getRichStringCellValue().toString()); 86 87 if (cell != null && cell.getRichStringCellValue() != null && cell.getRichStringCellValue().length() > 0) { 88 StringReader reader = new StringReader(cell.getRichStringCellValue().toString()); 89 ps.setCharacterStream(2, reader, cell.getRichStringCellValue().toString().length()); 90 ps.setString(1, cell.getRichStringCellValue().toString()); 91 } else { 92 ps.setString(1, null); 93 ps.setCharacterStream(2, null, 0); 94 } 95 } else { 96 cell = row.getCell(2); 97 if (cell != null && cell.getRichStringCellValue() != null) { 98 ps.setString(1, cell.getRichStringCellValue().toString()); 99 } else { 100 ps.setString(1, null); 101 } 80 102 ps.setCharacterStream(2, null, 0); 81 }else{82 cell = row.getCell(2);83 ps.setString(1, null);84 StringReader reader = new StringReader(cell.getRichStringCellValue().toString());85 if (cell.getRichStringCellValue() != null && cell.getRichStringCellValue().length() > 0) {86 ps.setCharacterStream(2, reader, cell.getRichStringCellValue().toString().length());87 } else {88 ps.setCharacterStream(2, null, 0);89 }90 103 } 91 104 … … 122 135 cell = row.getCell(2); 123 136 if ("text".equals(propertyType)) { 124 ps.setString(3, cell.getRichStringCellValue().toString()); 137 String str = StringUtils.EMPTY; 138 try { 139 str = cell.getRichStringCellValue().toString(); 140 } catch (Exception ie) { 141 try { 142 str = String.valueOf(cell.getNumericCellValue()); 143 } catch (NullPointerException npe) { 144 str = StringUtils.EMPTY; 145 } 146 } 147 ps.setString(3, str); 125 148 ps.setCharacterStream(4, null, 0); 126 149 } else { 127 150 ps.setString(3, null); 128 StringReader reader = new StringReader(cell.getRichStringCellValue().toString());129 if (cell.getRichStringCellValue() != null && cell.getRichStringCellValue().length() > 0) {151 if (cell != null && cell.getRichStringCellValue() != null && cell.getRichStringCellValue().length() > 0) { 152 StringReader reader = new StringReader(cell.getRichStringCellValue().toString()); 130 153 ps.setCharacterStream(4, reader, cell.getRichStringCellValue().toString().length()); 131 154 } else { … … 142 165 143 166 cell = row.getCell(4); 144 ps.setInt(6, (int) cell.getNumericCellValue()); 167 String str = StringUtils.EMPTY; 168 try { 169 str = String.valueOf(cell.getNumericCellValue()); 170 } catch (IllegalStateException ie) { 171 str = cell.getRichStringCellValue().toString(); 172 } 173 int index = str.indexOf("."); 174 if (index != -1) { 175 str = str.substring(0, index); 176 } 177 178 int value = Integer.parseInt(str); 179 ps.setInt(6, value ); 145 180 ps.execute(); 146 181 if (rowNumber >= displayCount) { … … 150 185 rowNumber++; 151 186 } 152 ps.close();153 187 } catch (Exception e) { 188 System.err.println("Error at line: " + rowNumber); 154 189 e.printStackTrace(); 190 } finally { 191 if ( ps != null) { 192 ps.close(); 193 } 155 194 } 156 195 } … … 176 215 e.printStackTrace(); 177 216 } 178 179 217 } 180 218 } 181 182 219 }
