本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFSheet.setDefaultColumnWidth方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFSheet.setDefaultColumnWidth方法的具体用法?Java HSSFSheet.setDefaultColumnWidth怎么用?Java HSSFSheet.setDefaultColumnWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.setDefaultColumnWidth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get data model which is passed by the Spring container
List<RatingCountBean> listOfRating = (List<RatingCountBean>) model.get("listOfRatingCount");
// create a new Excel sheet
HSSFSheet sheet = workbook.createSheet("Feedback Report");
sheet.setDefaultColumnWidth(30);
// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);
// create header row
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Question Number");
header.getCell(0).setCellStyle(style);
header.createCell(1).setCellValue("Question");
header.getCell(1).setCellStyle(style);
header.createCell(2).setCellValue("Very Poor");
header.getCell(2).setCellStyle(style);
header.createCell(3).setCellValue("Poor");
header.getCell(3).setCellStyle(style);
header.createCell(4).setCellValue("Good");
header.getCell(4).setCellStyle(style);
header.createCell(5).setCellValue("Best");
header.getCell(5).setCellStyle(style);
header.createCell(6).setCellValue("Excellent");
header.getCell(6).setCellStyle(style);
// create data rows
int rowCount = 1;
for (RatingCountBean rating : listOfRating) {
HSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(rating.getQuestionId());
aRow.createCell(1).setCellValue(rating.getQuestionText());
aRow.createCell(2).setCellValue(rating.getRating_one_total_count());
aRow.createCell(3).setCellValue(rating.getRating_two_total_count());
aRow.createCell(4).setCellValue(rating.getRating_three_total_count());
aRow.createCell(5).setCellValue(rating.getRating_four_total_count());
aRow.createCell(6).setCellValue(rating.getRating_five_total_count());
}
}
示例2: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get data model which is passed by the Spring container
@SuppressWarnings("unchecked")
List<HrmsLogin> users = (List<HrmsLogin>) model.get("allUsers");
// create a new Excel sheet
HSSFSheet sheet = workbook.createSheet("User List");
sheet.setDefaultColumnWidth(30);
// create style for header cells
CellStyle style = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("Arial");
style.setFillForegroundColor(HSSFColor.BLUE.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setColor(HSSFColor.WHITE.index);
style.setFont(font);
// create header row
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Employee ID");
header.getCell(0).setCellStyle(style);
header.createCell(1).setCellValue("Username");
header.getCell(1).setCellStyle(style);
header.createCell(2).setCellValue("Password");
header.getCell(2).setCellStyle(style);
header.createCell(3).setCellValue("Role");
header.getCell(3).setCellStyle(style);
// create data rows
int rowCount = 1;
for (HrmsLogin account : users) {
HSSFRow aRow = sheet.createRow(rowCount++);
aRow.createCell(0).setCellValue(account.getHrmsEmployeeDetails().getEmpId());
aRow.createCell(1).setCellValue(account.getUsername());
aRow.createCell(2).setCellValue(account.getPassword());
aRow.createCell(3).setCellValue(account.getRole());
}
}
示例3: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 엑셀파일을 설정하고 생성한다.
*
* @param model
* @param wb
* @param request
* @param response
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook wb, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String fileName = "CommonCode.xls";
fileName = new String(fileName.getBytes("euc-kr"), "8859_1");
response.setHeader("Content-Disposition", "attachment; fileName=\"" + fileName + "\";");
response.setHeader("Content-Transfer-Encoding", "binary");
HSSFCell cell = null;
HSSFSheet sheet = wb.createSheet("Codes List");
sheet.setDefaultColumnWidth(12);
// set header information
setText(getCell(sheet, 0, 0), "No.");
setText(getCell(sheet, 0, 1), "코드ID");
setText(getCell(sheet, 0, 2), "코드ID명");
setText(getCell(sheet, 0, 3), "코드");
setText(getCell(sheet, 0, 4), "코드명");
setText(getCell(sheet, 0, 5), "사용여부");
List<EgovMap> resultList = (List<EgovMap>) model.get("resultList");
for (int i = 0; i < resultList.size(); i++) {
EgovMap result = resultList.get(i);
cell = getCell(sheet, 1 + i, 0);
setText(cell, Integer.toString(i + 1));
cell = getCell(sheet, 1 + i, 1);
setText(cell, (String)result.get("codeId"));
cell = getCell(sheet, 1 + i, 2);
setText(cell, (String)result.get("codeIdNm"));
cell = getCell(sheet, 1 + i, 3);
setText(cell, (String)result.get("code"));
cell = getCell(sheet, 1 + i, 4);
setText(cell, (String)result.get("codeNm"));
cell = getCell(sheet, 1 + i, 5);
setText(cell, (String)result.get("useAt"));
}
}
示例4: buildExcelDocument
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
/**
* 엑셀파일을 설정하고 생성한다.
*
* @param model
* @param wb
* @param request
* @param response
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Override
protected void buildExcelDocument(Map<String, Object> model,
HSSFWorkbook wb, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String fileName = "메뉴.xls";
fileName = new String(fileName.getBytes("euc-kr"), "8859_1");
response.setHeader("Content-Disposition", "attachment; fileName=\"" + fileName + "\";");
response.setHeader("Content-Transfer-Encoding", "binary");
HSSFCell cell = null;
HSSFSheet sheet = wb.createSheet("메뉴 List");
sheet.setDefaultColumnWidth(20);
// set header information
setText(getCell(sheet, 0, 0), "매뉴번호");
setText(getCell(sheet, 0, 1), "메뉴명");
setText(getCell(sheet, 0, 2), "프로그램명");
setText(getCell(sheet, 0, 3), "메뉴설명");
setText(getCell(sheet, 0, 4), "사용여부");
setText(getCell(sheet, 0, 5), "관리자여부");
setText(getCell(sheet, 0, 6), "바로가기url");
setText(getCell(sheet, 0, 7), "톱메뉴여부");
setText(getCell(sheet, 0, 8), "메뉴별명");
List<EgovMap> resultList = (List<EgovMap>) model.get("resultList");
for (int i = 0; i < resultList.size(); i++) {
EgovMap result = resultList.get(i);
cell = getCell(sheet, 1 + i, 0);
setText(cell, String.valueOf(result.get("menuNo")));
cell = getCell(sheet, 1 + i, 1);
setText(cell, (String)result.get("menuNm"));
cell = getCell(sheet, 1 + i, 2);
setText(cell, (String)result.get("progrmFileNm"));
cell = getCell(sheet, 1 + i, 3);
setText(cell, (String)result.get("menuDc"));
cell = getCell(sheet, 1 + i, 4);
setText(cell, (String)result.get("useAt"));
cell = getCell(sheet, 1 + i, 5);
setText(cell, (String)result.get("mgrAt"));
cell = getCell(sheet, 1 + i, 6);
setText(cell, (String)result.get("directUrl"));
cell = getCell(sheet, 1 + i, 7);
setText(cell, (String)result.get("topMenuAt"));
cell = getCell(sheet, 1 + i, 8);
setText(cell, (String)result.get("menuAlias"));
}
}
示例5: publishResults
import org.apache.poi.hssf.usermodel.HSSFSheet; //导入方法依赖的package包/类
private void publishResults(String filename) {
// System.out.println("DEBUG - starting generation of the excel file.");
try {
HSSFWorkbook workbook = new HSSFWorkbook();
int rowCounter;
int cellCounter;
boolean generateHead;
/* generating one sheet for each log */
for( String miningAlgorithmName : measures.keySet() ) {
generateHead = true;
rowCounter = 0;
HSSFSheet sheet = workbook.createSheet(miningAlgorithmName);
sheet.setDefaultColumnWidth(12);
HSSFRow rowhead = sheet.createRow((short) rowCounter);
rowCounter++;
for( String logName : measures.get(miningAlgorithmName).keySet() ) {
/* creating the row for this mining algorithm */
HSSFRow row = sheet.createRow((short) rowCounter);
rowCounter++;
cellCounter = 0;
if( generateHead ) rowhead.createCell(cellCounter).setCellValue("Log");
row.createCell(cellCounter).setCellValue(logName);
cellCounter++;
ArrayList<String> metrics = new ArrayList<>(measures.get(miningAlgorithmName).get(logName).keySet());
Collections.sort(metrics);
for( int i = 0; i < metrics.size(); i++ ) {
String metricName = metrics.get(i);
if( generateHead ) rowhead.createCell(cellCounter).setCellValue(metricName);
row.createCell(cellCounter).setCellValue(measures.get(miningAlgorithmName).get(logName).get(metricName));
cellCounter++;
}
generateHead = false;
}
}
FileOutputStream fileOut = new FileOutputStream(filename);
workbook.write(fileOut);
fileOut.close();
System.out.println("DEBUG - results exported to: " + filename);
} catch ( Exception e ) {
System.out.println("ERROR - something went wrong while writing the excel sheet: " + e.getMessage());
e.printStackTrace();
}
}