<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    EXCEL轉JAVA BEAN

    pom.xml回入以下包:
            <dependency>
                <groupId>net.sf.jxls</groupId>
                <artifactId>jxls-core</artifactId>
            </dependency>
            <dependency>
                <groupId>net.sf.jxls</groupId>
                <artifactId>jxls-reader</artifactId>
            </dependency>
            <dependency>
                <groupId>net.sf.jxls</groupId>
                <artifactId>jxls-examples</artifactId>
            </dependency>


    轉換的配置文件:
    <workbook>
      <worksheet name="Sheet1">
        <section startRow="0" endRow="0" />
        <loop startRow="1" endRow="1" items="result" var="app" varType="n.app.valueobject.App">
          <section startRow="1" endRow="1">
            <mapping row="1" col="0">app.title</mapping>
            <mapping row="1" col="1">app.categoryId</mapping>
            <mapping row="1" col="2">app.updateContent</mapping>
            <mapping row="1" col="3">app.rank</mapping>
            <mapping row="1" col="4">app.installedQty</mapping>
            <mapping row="1" col="5">app.installedType</mapping>
            <mapping row="1" col="6">app.discuss</mapping>
            <mapping row="1" col="7">app.summary</mapping>
            <mapping row="1" col="8">app.deviceTypes</mapping>
            <mapping row="1" col="9">app.description</mapping>
            <mapping row="1" col="10">app.newFeatures</mapping>
            <mapping row="1" col="11">app.shortRecommend</mapping>
            <mapping row="1" col="12">app.appUrl</mapping>
          </section>
          <loopbreakcondition>
            <rowcheck offset="0">
              <cellcheck offset="0" />
            </rowcheck>
          </loopbreakcondition>
        </loop>
      </worksheet>
    </workbook>



    JAVA代碼:
    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import net.sf.jxls.reader.ReaderBuilder;
    import net.sf.jxls.reader.XLSReader;

    import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.xml.sax.SAXException;

    import application.app.valueobject.App;

    public class ExcelUtil<T> {
        
        private static Logger logger = LoggerFactory.getLogger(ExcelUtil.class);
        
        public List<T> parseExcelFileToBeans(InputStream xlsFileInputStream, InputStream jxlsConfigInputStream) throws IOException, SAXException, InvalidFormatException  {
            
            
            List<T> result = new ArrayList<T>();
            Map<String, Object> beans = new HashMap<String, Object>();
            beans.put("result", result);
            InputStream inputStream = null;
            try {
                XLSReader xlsReader = ReaderBuilder.buildFromXML(jxlsConfigInputStream);
                inputStream = new BufferedInputStream(xlsFileInputStream);
                xlsReader.read(inputStream, beans);
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
                throw e;
            } catch (SAXException e) {
                logger.error(e.getMessage(), e);
                throw e;
            } catch (InvalidFormatException e) {
                logger.error(e.getMessage(), e);
                throw e;
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e) {
                    }
                }
            }
            return result;
        }
        
        public static void main(String[] args) throws Exception {
            
            String path = "D:/DATA/TESTING-FILE/EXCEL";
            
            path = System.getProperty("user.home");
            
            ExcelUtil<App> util = new ExcelUtil<App>();
            String excelFilePath = path + File.separator + "appData.xls";
            
            InputStream configInputStream = 
                    ExcelUtil.class.getResourceAsStream("/excel/template/config/app_config.xml");
            InputStream xlsFileInputStream = new FileInputStream(excelFilePath);
            
            List<App> appList = util.parseExcelFileToBeans(xlsFileInputStream, configInputStream);

            for (App app : appList) {
                System.out.println(app.toString());
            }
            
            /*String [] args2 = {""};
            GroupingSample.main(args2);
    */

        }

    }


    http://www.yihaomen.com/article/java/530.htm

    posted on 2014-10-29 17:25 paulwong 閱讀(1099) 評論(0)  編輯  收藏 所屬分類: J2SE

    主站蜘蛛池模板: 一进一出60分钟免费视频| 亚洲黄片毛片在线观看| 永久免费av无码网站yy| 亚洲国产欧美国产综合一区 | 97无码免费人妻超级碰碰夜夜| 男女一边摸一边做爽的免费视频| 亚洲欧美综合精品成人导航| 亚洲第一页在线视频| 亚洲国产精品特色大片观看完整版 | 亚洲免费在线播放| 中文字幕免费人成乱码中国| 国产精品亚洲av色欲三区| 亚洲娇小性色xxxx| 亚洲一级免费毛片| 亚洲高清日韩精品第一区| 久久久久久a亚洲欧洲aⅴ| 亚洲午夜无码片在线观看影院猛| 国产乱子伦精品免费女| 精品免费国产一区二区三区| 一个人看的www在线观看免费| 91av免费观看| 亚洲免费一级视频| 久久免费看黄a级毛片| 1000部拍拍拍18勿入免费视频下载 | 91久久成人免费| 麻豆高清免费国产一区| 99久久免费观看| 麻豆视频免费播放| 免费v片在线观看视频网站| 日韩在线播放全免费| 无码国产精品一区二区免费式直播 | 久久经典免费视频| 欧美三级在线电影免费| 大地资源在线观看免费高清 | 亚洲国产成人综合精品| 久久亚洲欧美国产精品| 男性gay黄免费网站| 免费人成大片在线观看播放电影| 色婷婷综合缴情综免费观看| 一级毛片a女人刺激视频免费| 永久免费观看黄网站|