/**
* 根据合并输出内容,处理合并单元格事情
* @param formatAsString
*/
private void handerMergedString(String formatAsString) {
String[] strArr = formatAsString.split(
":"
);
int startCol = strArr[0].charAt(0) - 65;
int startRol = Integer.valueOf(strArr[0].substring(1));
int endCol = strArr[1].charAt(0) - 65;
int endRol = Integer.valueOf(strArr[1].substring(1));
mergedCache.put(startRol +
"_"
+ startCol,
new
Integer[] { endRol - startRol + 1,
endCol - startCol + 1 });
for
(int i = startRol; i <= endRol; i++) {
for
(int j = startCol; j <= endCol; j++) {
notNeedCread.add(i +
"_"
+ j);
}
}
notNeedCread.remove(startRol +
"_"
+ startCol);
}
把整个sheet的合并单元格,存放起来,然后便利的时候判断下,给td写写 rowspan和colsopan 就可以了,相对比较简单
2.CSS的设置
private void styleContents(CellStyle style) {
if
(style.getAlignment() != 2) {
styleOut(
"text-align"
, style.getAlignment(), ALIGN);
styleOut(
"vertical-align"
, style.getAlignment(), VERTICAL_ALIGN);
}
helper.colorStyles(style, out);
}
private void fontStyle(Font font) {
if
(font.getBoldweight() >= Font.BOLDWEIGHT_BOLD)
out.format(
" font-weight: bold;%n"
);
if
(font.getItalic())
out.format(
" font-style: italic;%n"
);
out.format(
" font-family: %s;%n"
, font.getFontName());
int fontheight = font.getFontHeightInPoints();
if
(fontheight == 9) {
fontheight = 10;
}
out.format(
" font-size: %dpt;%n"
, fontheight);
helper.styleColor(out,
"color"
, getColor(font));
}
public String getHtmlValue(Cell cell) {
if
(Cell.CELL_TYPE_BOOLEAN == cell.getCellType()
|| Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
cell.setCellType(Cell.CELL_TYPE_STRING);
return
cell.getStringCellValue();
}
else
if
(Cell.CELL_TYPE_STRING == cell.getCellType()) {
if
(cell.getRichStringCellValue().numFormattingRuns() == 0) {
return
XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue());
}
else
if
(is07) {
return
getXSSFRichString((XSSFRichTextString) cell.getRichStringCellValue());
}
else
{
return
getHSSFRichString((HSSFRichTextString) cell.getRichStringCellValue());
}
}
return
""
;
}
/**
* Excel 变成界面
* @author JueYue
* @date 2015年5月10日 上午11:51:48
*/
public final class ExcelToHtmlUtil {
private ExcelToHtmlUtil() {
}
/**
* 转换成为Table
* @param wb Excel
* @return
*/
public static String toTableHtml(Workbook wb) {
return
new
ExcelToHtmlServer(wb,
false
, 0).printPage();
}
/**
* 转换成为Table
* @param wb Excel
* @param sheetNum sheetNum
* @return
*/
public static String toTableHtml(Workbook wb, int sheetNum) {
return
new
ExcelToHtmlServer(wb,
false
, sheetNum).printPage();
}
/**
* 转换成为完整界面
* @param wb Excel
* @param sheetNum sheetNum
* @return
*/
public static String toAllHtml(Workbook wb) {
return
new
ExcelToHtmlServer(wb,
true
, 0).printPage();
}
/**
* 转换成为完整界面
* @param wb Excel
* @param sheetNum sheetNum
* @return
*/
public static String toAllHtml(Workbook wb, int sheetNum) {
return
new
ExcelToHtmlServer(wb,
true
, sheetNum).printPage();
}
}
源码地址EasyPoi
原文地址:http://blog.csdn.net/qjueyue/article/details/45620931