java apache poi 匯出excel

來源:互聯網
上載者:User

標籤:

不說廢話,帖代碼

引入架包:poi-3.12-20150511.jar   poi-ooxml-3.12-20150511.jar

管網可以下載

try{         FLogicDataset<FDataInfoDeviceBrowserUnit> unitlist = _deviceBrowserConsole.select(logicContext);         //建立新的Excel工作薄          HSSFWorkbook workbook = new HSSFWorkbook();         HSSFSheet sheet = workbook.createSheet("sheet1");         //在索引0的位置建立行(最頂端的行)           String[] headers = new String[]{"頭資訊", "裝置資訊"};         HSSFRow headerRow = sheet.createRow(0);         HSSFCell cell = headerRow.createCell(0);         cell.setCellType(XSSFCell.CELL_TYPE_STRING);         cell.setCellValue(headers[0]);         HSSFCell cell0 = headerRow.createCell(1);         cell0.setCellType(XSSFCell.CELL_TYPE_STRING);         cell0.setCellValue(headers[1]);         int index = 0;         for(FDataInfoDeviceBrowserUnit unit : unitlist){            index++;            HSSFRow row = sheet.createRow(index);            HSSFCell cell1 = row.createCell(0);            //定義儲存格為字串類型              cell1.setCellType(XSSFCell.CELL_TYPE_STRING);            //在儲存格中輸入一些內容              cell1.setCellValue(unit.agentCode());            HSSFCell cell2 = row.createCell(1);            //定義儲存格為字串類型              cell2.setCellType(XSSFCell.CELL_TYPE_STRING);            //在儲存格中輸入一些內容              cell2.setCellValue(unit.content());         }         String filePath = "d:/deviceList_" + RDateTime.currentDateTime() + ".xls";         //建立檔案輸出資料流           FileOutputStream fOut = new FileOutputStream(filePath);         //將資料寫入Excel           workbook.write(fOut);         fOut.close();         basePage.ajax(1, filePath);         _logger.debug(this, "Expend", "Expend succeed. (path={1})", filePath);      }catch(Exception e){         e.printStackTrace();         basePage.ajax(0, e.getMessage());         _logger.debug(this, "Expend", "Expend fail. (message={1})", e);      }


java apache poi 匯出excel

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.