日期:2014-05-16 浏览次数:20608 次
| 编号 | 文件格式 |
| 1 | XML |
| 2 | Excel |
| 3 | Access |
| 4 | DBF |
| 5 | MDB |


File f = new File("E:\\data\\test.xml");
Document doc=sax.build(f);//解析file的xml文件
Element root=doc.getRootElement();//获取根节点
List<Element> eles= root.getChildren();//获取根节点下面子节点的集合
// System.out.println(eles.size());
List<XmlEntity> xmls=new ArrayList<XmlEntity>();
for(Element e:eles){
String ui=e.getChildText("ui");
String ti=e.getChildText("ti");
String ta=e.getChildText("ta");
String dp=e.getChildText("dp");
String vi=e.getChildText("vi");
String ip=e.getChildText("ip");
String pg=e.getChildText("pg");
String mh=e.getChildText("mh");
xmls.add(new XmlEntity(ui, ti, ta, dp, vi, ip, pg, mh));
// System.out.println(e.getChildText("ui"));
// System.out.println(e.getChildText("ti"));
// System.out.println(e.getChildText("ta"));
// System.out.println(e.getChildText("dp"));
// System.out.println(e.getChildText("vi"));
// System.out.println(e.getChildText("ip"));
// System.out.println(e.getChildText("pg"));
// System.out.println(e.getChildText("mh"));
// System.out.println("=================================");
}
DAO.add(xmls);//持久化到数据库中
System.out.println("添加成功!");
// System.out.println("获取根节点的名字 :"+root.getName());

/**
* 判断单元格格式
* **/
private static String getCellValue(HSSFCell cell) {
String cellValue = "";
DecimalFormat df = new DecimalFormat("#");
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getRichStringCellValue().getString().trim();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellValue = df.format(cell.getNumericCellValue()).toString();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue()).trim();
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellValue = cell.g