採用apache 【POI】 架構產生excel檔案

來源:互聯網
上載者:User

標籤:excel

public static void CreateBugFile(String fileName, String bussinessNo, String projectPath) throws Exception {

File bugFile = new File(fileName + ".xls");

File file = new File(projectPath);

String[] titles = { "代碼變更說明", "所屬子系統", "代碼路徑", "修改人", "業務單號", "備忘" };

HSSFWorkbook workbook = new HSSFWorkbook();

HSSFSheet sheet = workbook.createSheet("代碼匯入");

HSSFCellStyle hssfCellStyle = workbook.createCellStyle();

hssfCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);

hssfCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);

hssfCellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);

hssfCellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);

hssfCellStyle.setVerticalAlignment(HSSFCellStyle.ALIGN_LEFT);

//hssfCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

// hssfCellStyle.setRightBorderColor(HSSFCellStyle.BORDER_THIN);

// hssfCellStyle.setLeftBorderColor(HSSFCellStyle.BORDER_THIN);

HSSFRow hssfRow = sheet.createRow(0);

for (int i = 0, j = titles.length; i < j; i++) {

HSSFCell hssfCell = hssfRow.createCell(i);

if (i == 2) {

sheet.setColumnWidth(i, 10000);

} else {

sheet.setColumnWidth(i, 5000);

}

hssfCell.setCellValue(titles[i].trim());

hssfCell.setCellStyle(hssfCellStyle);

}

for (int i = 0; i < list.size(); i++) {

HSSFRow hssfRow2 = sheet.createRow(i + 1);

for (int m = 0; m < 6; m++) {

HSSFCell hssfCell = hssfRow2.createCell(m);

if (m == 0) {

sheet.setColumnWidth(m, 5000);

hssfCell.setCellValue(codeChangeDesc.trim());

} else if (m == 1) {

sheet.setColumnWidth(m, 5000);

hssfCell.setCellValue(childSys.trim());

} else if (m == 2) {

sheet.setColumnWidth(m, 10000);

hssfCell.setCellValue(list.get(i).toString().trim());

} else if (m == 3) {

sheet.setColumnWidth(m, 5000);

hssfCell.setCellValue(updater.trim());

} else if (m == 4) {

sheet.setColumnWidth(m, 5000);

hssfCell.setCellValue(bussinessNo.trim());

} else if (m == 5) {

sheet.setColumnWidth(m, 5000);

hssfCell.setCellValue(remark.trim());

}

// sheet.setColumnWidth(m, 5000);

hssfCell.setCellStyle(hssfCellStyle);

}

}

FileOutputStream fileOutputStream = new FileOutputStream(bugFile);

workbook.write(fileOutputStream);

fileOutputStream.close();

}


本文出自 “一代宗師” 部落格,請務必保留此出處http://765682.blog.51cto.com/755682/1899573

採用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.