poi 3 층 표두
// TODO Auto-generated method stub
FileOutputStream fileOut = null;
File file = new File("c:/1.xls");
String[] header = { " ", "IP ", " cache _ ", " cache _ ",
" _ ", " _ ", " _ ", " _ ", "session _ ",
"session _ ", " _ ", " _ ", " _ ", " _ ",
" _ ", " _ ", " _ _ ", " _ _ ",
" _ _ ", " _ _ ", " _ _ ", " _ _ ",
" _ _ ", " _ _ ", " _ _ ", " _ _ ",
" " };
try {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFFont fontinfo = wb.createFont();
fontinfo.setFontHeightInPoints((short) 8); //
HSSFFont fonthead = wb.createFont();
fonthead.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//
HSSFCellStyle cellStylename = wb.createCellStyle();//
cellStylename.setFont(fonthead);
HSSFCellStyle cellStyleinfo = wb.createCellStyle();//
cellStyleinfo.setAlignment(HSSFCellStyle.ALIGN_RIGHT);//
cellStyleinfo.setFont(fontinfo);
HSSFCellStyle cellStylehead = wb.createCellStyle();//
cellStylehead.setFont(fonthead);
cellStylehead.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStylehead.setBorderBottom(HSSFCellStyle.BORDER_THIN);//
cellStylehead.setBottomBorderColor(HSSFColor.BLACK.index);
cellStylehead.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellStylehead.setLeftBorderColor(HSSFColor.BLACK.index);
cellStylehead.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStylehead.setRightBorderColor(HSSFColor.BLACK.index);
cellStylehead.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellStylehead.setTopBorderColor(HSSFColor.BLACK.index);
cellStylehead.setFillForegroundColor(HSSFColor.ORANGE.index);
cellStylehead.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFCellStyle cellStyle = wb.createCellStyle();//
cellStyle.setWrapText(true);//
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellStyle.setBottomBorderColor(HSSFColor.BLACK.index);
cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellStyle.setLeftBorderColor(HSSFColor.BLACK.index);
cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellStyle.setRightBorderColor(HSSFColor.BLACK.index);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellStyle.setTopBorderColor(HSSFColor.BLACK.index);
int col = header.length;
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(cellStylename);
cell.setCellValue("oracle");//
sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 1));
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(cellStyleinfo);
cell.setCellValue("oracle"); //
sheet.addMergedRegion(new Region(0, (short) 2, 0, (short) col));
int rows_max = 0;
for (int i = 0; i < header.length; i++) {
String h = header[i];
if (h.split("_").length > rows_max) {
rows_max = h.split("_").length;
}
}
Map map = new HashMap();
for (int k = 0; k < rows_max; k++) {
row = sheet.createRow((short) k + 1);
if (k == 0) {
cell = row.createCell((short) (0));
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(cellStylehead);
cell.setCellValue(" ");
sheet.addMergedRegion(new Region(k + 1, (short) 0, k
+ rows_max, (short) 0));
}
for (int i = 0; i < header.length; i++) {
String headerTemp = header[i];
String[] s = headerTemp.split("_");
String sk = "";
int num = i + 1;
if (s.length == 1) {
cell = row.createCell((short) (num));
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(cellStylehead);
sheet.addMergedRegion(new Region(1, (short) (num),
rows_max, (short) (num)));
sk = headerTemp;
cell.setCellValue(sk);
} else {
System.out.println(sk);
cell = row.createCell((short) (num));
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(cellStylehead);
int cols = 0;
if (map.containsKey(headerTemp)) {
continue;
}
for (int d = 0; d <= k; d++) {
if (d != k) {
sk += s[d] + "_";
} else{
sk += s[d];
}
}
if(map.containsKey(sk)){
continue;
}
for (int j = 0; j < header.length; j++) {
if (header[j].indexOf(sk) != -1) {
cols++;
}
}
cell.setCellValue(s[k]);
sheet
.addMergedRegion(new Region(k + 1,
(short) num, k + 1,
(short) (num + cols-1)));
if (sk.equals(headerTemp)) {
sheet.addMergedRegion(new Region(k + 1,
(short) num, k + 1 + rows_max
- s.length, (short) num));
}
}
if (s.length > k) {
if (!map.containsKey(sk)) {
String key = "";
if (k > 0) {
key = sk;
} else {
key = s[k];
}
map.put(key, null);
}
}
}
}
fileOut = new FileOutputStream(file);
// modify by xywang(2007-11-19) end
wb.write(fileOut);
} catch (Exception e) {
e.printStackTrace();
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 작업 은 Clob 또는 NClob 데이터 형식의 저장 프로 세 스 인 스 턴 스 를 포함 합 니 다.텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.