国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

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

2024-08-29 13:59:34
字體:
供稿:網(wǎng)友

1.準(zhǔn)備工作

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

Oracle,Excel

Excel模板(201512.xls):

Oracle,Excel

2.任務(wù)說明

我們要完成的任務(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());    }    // 寫入一個(gè)新的Excel表內(nèi)    FileOutputStream out = new FileOutputStream(new File("E:/"+yyyy+mm+".xls"));    // Excel表寫入完成    workbook.write(out);    // Excel表退出    out.close();  }

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

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持VeVb武林網(wǎng)!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到oracle教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东乌珠穆沁旗| 铜梁县| 威海市| 荃湾区| 连江县| 米林县| 子洲县| 阿拉善盟| 灵台县| 阿拉尔市| 马尔康县| 涿州市| 米易县| 安宁市| 秦安县| 定州市| 淳化县| 犍为县| 孟津县| 南陵县| 凤山市| 平顶山市| 龙海市| 平江县| 偏关县| 会理县| 出国| 阿荣旗| 商河县| 容城县| 肥乡县| 庄河市| 固阳县| 墨玉县| 巍山| 灵台县| 关岭| 沙坪坝区| 皮山县| 克拉玛依市| 宁安市|