亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

將Oracle數(shù)據(jù)庫(kù)中的數(shù)據(jù)寫(xiě)入Excel

 更新時(shí)間:2016年12月23日 09:43:01   作者:一個(gè)弱者想變強(qiáng)  
本文主要分享了將Oracle數(shù)據(jù)庫(kù)中的數(shù)據(jù)寫(xiě)入Excel的關(guān)鍵代碼。具有很好的參考價(jià)值,需要的朋友一起來(lái)看下吧

1.準(zhǔn)備工作

Oracle數(shù)據(jù)庫(kù)“TBYZB_FIELD_PRESSURE”表中數(shù)據(jù)如圖:

Excel模板(201512.xls):

2.任務(wù)說(shuō)明

我們要完成的任務(wù)就是將表“TBYZB_FIELD_PRESSURE”中的數(shù)據(jù),按照Excel模板(201512.xls)的樣式導(dǎo)入到一個(gè)新的Excel中。即:Excel模板(201512.xls)不改變,生成一個(gè)和它一樣的Excel并且導(dǎo)入數(shù)據(jù)。

3.關(guān)鍵代碼

// 使用FieldPressEntity中的每一個(gè)entity,一個(gè)entity包含了所有屬性
 public void insertintoExcel(String yyyy, String mm) throws Exception {
  List<FieldPressEntity> result = tyFieldPressDao.search(yyyy, mm);
  // 讀取Excel的模板
  HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(
    "D:/201512.xls")));
  HSSFSheet sheet = null;
  // 讀取sheet的模板
  sheet = workbook.getSheetAt(0);
  // 定義行
  HSSFRow row;
  // 定義單元格
  HSSFCell cell;
  // for循環(huán),循環(huán)目標(biāo)為行循環(huán)
  for (int i = 0; i < result.size(); i++) {
   System.out.println(result.size());
   // 給e循環(huán)賦值
   FieldPressEntity e = result.get(i);
   // 循環(huán)行
   row = sheet.getRow(3 + i);
   // 給行內(nèi)的單元格賦值
   cell = row.getCell(1);
   cell.setCellValue(e.getH17());
   System.out.println(i + "i內(nèi)+" + e.getH17());
   cell = row.getCell(2);
   cell.setCellValue(e.getH18());
   System.out.println(i + "i內(nèi)+" + e.getH18());
   cell = row.getCell(3);
   cell.setCellValue(e.getH19());
   System.out.println(i + "i內(nèi)+" + e.getH19());
   cell = row.getCell(4);
   cell.setCellValue(e.getH20());
   System.out.println(i + "i內(nèi)+" + e.getH20());
   cell = row.getCell(5);
   cell.setCellValue(e.getH21());
   System.out.println(i + "i內(nèi)+" + e.getH21());
   cell = row.getCell(6);
   cell.setCellValue(e.getH22());
   System.out.println(i + "i內(nèi)+" + e.getH22());
   cell = row.getCell(7);
   cell.setCellValue(e.getH23());
   System.out.println(i + "i內(nèi)+" + e.getH23());
   cell = row.getCell(8);
   cell.setCellValue(e.getH00());
   System.out.println(i + "i內(nèi)+" + e.getH00());
   cell = row.getCell(9);
   cell.setCellValue(e.getH01());
   System.out.println(i + "i內(nèi)+" + e.getH01());
   cell = row.getCell(10);
   cell.setCellValue(e.getH02());
   System.out.println(i + "i內(nèi)+" + e.getH02());
   cell = row.getCell(11);
   cell.setCellValue(e.getH03());
   System.out.println(i + "i內(nèi)+" + e.getH03());
   cell = row.getCell(12);
   cell.setCellValue(e.getH04());
   System.out.println(i + "i內(nèi)+" + e.getH04());
   cell = row.getCell(13);
   cell.setCellValue(e.getH05());
   System.out.println(i + "i內(nèi)+" + e.getH05());
   cell = row.getCell(14);
   cell.setCellValue(e.getH06());
   System.out.println(i + "i內(nèi)+" + e.getH06());
   cell = row.getCell(15);
   cell.setCellValue(e.getH07());
   System.out.println(i + "i內(nèi)+" + e.getH07());
   cell = row.getCell(16);
   cell.setCellValue(e.getH08());
   System.out.println(i + "i內(nèi)+" + e.getH08());
   cell = row.getCell(17);
   cell.setCellValue(e.getH09());
   System.out.println(i + "i內(nèi)+" + e.getH09());
   cell = row.getCell(18);
   cell.setCellValue(e.getH10());
   System.out.println(i + "i內(nèi)+" + e.getH10());
   cell = row.getCell(19);
   cell.setCellValue(e.getH11());
   System.out.println(i + "i內(nèi)+" + e.getH11());
   cell = row.getCell(20);
   cell.setCellValue(e.getH12());
   System.out.println(i + "i內(nèi)+" + e.getH12());
   cell = row.getCell(21);
   cell.setCellValue(e.getH13());
   System.out.println(i + "i內(nèi)+" + e.getH13());
   cell = row.getCell(22);
   cell.setCellValue(e.getH14());
   System.out.println(i + "i內(nèi)+" + e.getH14());
   cell = row.getCell(23);
   cell.setCellValue(e.getH15());
   System.out.println(i + "i內(nèi)+" + e.getH15());
   cell = row.getCell(24);
   cell.setCellValue(e.getH16());
   System.out.println(i + "i內(nèi)+" + e.getH16());
   cell = row.getCell(25);
   cell.setCellValue(e.getDaily_sum());
   System.out.println(i + "i內(nèi)+" + e.getDaily_sum());
   cell = row.getCell(26);
   cell.setCellValue(e.getDaily_avg());
   System.out.println(i + "i內(nèi)+" + e.getDaily_avg());
   cell = row.getCell(27);
   cell.setCellValue(e.getDaily_max());
   System.out.println(i + "i內(nèi)+" + e.getDaily_max());
   cell = row.getCell(28);
   cell.setCellValue(e.getDaily_min());
   System.out.println(i + "i內(nèi)+" + e.getDaily_min());
  }
  // 寫(xiě)入一個(gè)新的Excel表內(nèi)
  FileOutputStream out = new FileOutputStream(new File("E:/"+yyyy+mm+".xls"));
  // Excel表寫(xiě)入完成
  workbook.write(out);
  // Excel表退出
  out.close();
 }

總結(jié):我們這個(gè)項(xiàng)目用的是ssh架構(gòu),如果想使用以上代碼,需要按照ssh的規(guī)范,定義dao action service entity四個(gè)包,如果需要頁(yè)面操作還需要js做頁(yè)面。

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論