Révision 3129
| tmp/org.txm.libs.msoffice/src/org/txm/libs/msoffice/ReadExcel.java (revision 3129) | ||
|---|---|---|
| 20 | 20 |
import org.apache.poi.ss.usermodel.Sheet; |
| 21 | 21 |
import org.apache.poi.ss.usermodel.Workbook; |
| 22 | 22 |
import org.apache.poi.ss.usermodel.WorkbookFactory; |
| 23 |
import org.apache.poi.xssf.usermodel.XSSFCell; |
|
| 23 | 24 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| 24 | 25 |
|
| 25 | 26 |
public class ReadExcel {
|
| ... | ... | |
| 651 | 652 |
* @return always a String starting with '#' if an error occurs |
| 652 | 653 |
*/ |
| 653 | 654 |
public static String cellToString(Cell cell) {
|
| 654 |
if (cell == null) return ""; |
|
| 655 | 655 |
|
| 656 |
|
|
| 656 | 657 |
switch (cell.getCellType()) {
|
| 657 | 658 |
case FORMULA: |
| 658 |
return "#formulla";
|
|
| 659 |
return cell.getCellFormula();
|
|
| 659 | 660 |
case NUMERIC: |
| 660 | 661 |
if (DateUtil.isCellDateFormatted(cell)) {
|
| 661 |
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
|
| 662 |
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM");
|
|
| 662 | 663 |
return dateFormat.format(cell.getDateCellValue()); |
| 663 | 664 |
} |
| 664 | 665 |
else {
|
| 666 |
XSSFCell xssfCell = (XSSFCell)cell; |
|
| 667 |
String raw = xssfCell.getRawValue(); |
|
| 665 | 668 |
Double value = cell.getNumericCellValue(); |
| 666 |
return value.toString(); |
|
| 669 |
Integer i = null; |
|
| 670 |
try {i = Integer.parseInt(raw);} catch(Exception e) {}
|
|
| 671 |
|
|
| 672 |
if (i == null) {
|
|
| 673 |
return value.toString(); |
|
| 674 |
} else {
|
|
| 675 |
return i.toString(); |
|
| 676 |
} |
|
| 677 |
|
|
| 667 | 678 |
} |
| 668 | 679 |
case STRING: |
| 669 |
return cell.getStringCellValue();
|
|
| 680 |
return cell.getRichStringCellValue().toString();
|
|
| 670 | 681 |
case BLANK: |
| 671 | 682 |
return ""; |
| 672 | 683 |
case BOOLEAN: |
| 673 |
return "" + cell.getBooleanCellValue();
|
|
| 684 |
return cell.getBooleanCellValue() ? "TRUE" : "FALSE";
|
|
| 674 | 685 |
case ERROR: |
| 675 | 686 |
return "#error"; |
| 676 | 687 |
default: |
| 677 |
return "#typeerror";
|
|
| 688 |
return "#typeerror: "+cell.getCellType();
|
|
| 678 | 689 |
} |
| 679 | 690 |
} |
| 680 | 691 |
|
Formats disponibles : Unified diff