Changeset 20457

Show
Ignore:
Timestamp:
02/23/10 13:56:46 (5 months ago)
Author:
tincholiguori
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/propertyExporter/src/net/project/poi/Import.java

    r18721 r20457  
    1515import java.util.Properties; 
    1616 
     17import org.apache.commons.lang.StringUtils; 
    1718import org.apache.poi.hssf.usermodel.HSSFCell; 
     19import org.apache.poi.hssf.usermodel.HSSFRichTextString; 
    1820import org.apache.poi.hssf.usermodel.HSSFRow; 
    1921import org.apache.poi.hssf.usermodel.HSSFSheet; 
     
    6062                        try { 
    6163                                fileSystem = new POIFSFileSystem(inputStream); 
    62  
     64// 
    6365                                HSSFWorkbook workBook = new HSSFWorkbook(fileSystem); 
    6466                                HSSFSheet sheet = workBook.getSheetAt(0); 
     
    7577                                                        // set property value, property_value_clob 
    7678                                                        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)) { 
    7885                                                                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                                                                } 
    80102                                                                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                                                                 } 
    90103                                                        } 
    91104                                                         
     
    122135                                                        cell = row.getCell(2); 
    123136                                                        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); 
    125148                                                                ps.setCharacterStream(4, null, 0); 
    126149                                                        } else { 
    127150                                                                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()); 
    130153                                                                        ps.setCharacterStream(4, reader, cell.getRichStringCellValue().toString().length()); 
    131154                                                                } else { 
     
    142165                                                         
    143166                                                        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 ); 
    145180                                                        ps.execute(); 
    146181                                                        if (rowNumber >= displayCount) { 
     
    150185                                                        rowNumber++; 
    151186                                                } 
    152                                                 ps.close(); 
    153187                                        } catch (Exception e) { 
     188                                                System.err.println("Error at line: " + rowNumber); 
    154189                                                e.printStackTrace(); 
     190                                        } finally { 
     191                                                if ( ps != null) { 
     192                                                        ps.close(); 
     193                                                } 
    155194                                        } 
    156195                                } 
     
    176215                                e.printStackTrace(); 
    177216                        } 
    178  
    179217                } 
    180218        } 
    181  
    182219}