Excel 转成 Html Excel 预览_html/css_WEB-ITnose
基于Poi demo做的,效果还不错,这里给大家分享下,先看看效果
效果基本上一致,这里说下如何做的
1.合并单元格的处理
/**
* 根据合并输出内容,处理合并单元格事情
* @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
for (int j = startCol; 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));
}
从cellStyle 里面吧值获取出来,然后填写到css当中,已经font的css,这个理font和style要区分因为后面复杂的单元格要迭代设置的font,另外
03和07版本很多不同的东西,需要分开设置
3.值的获取--比较重要和复杂的
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 "" ;
}
判断cell类型,然后设置值,如果是String,需要判断是不是复杂的text,如果是,需要按照03,和07分别处理,迭代列类型列表然后输出
总的来说比自己想想的容易的多
使用方法---只能一个sheet一个sheet的输出
/**
* 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

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML、CSS和JavaScript在Web開發中的作用分別是:1.HTML定義網頁結構,2.CSS控製網頁樣式,3.JavaScript添加動態行為。它們共同構建了現代網站的框架、美觀和交互性。

HTML的未來趨勢是語義化和Web組件,CSS的未來趨勢是CSS-in-JS和CSSHoudini,JavaScript的未來趨勢是WebAssembly和Serverless。 1.HTML的語義化提高可訪問性和SEO效果,Web組件提升開發效率但需注意瀏覽器兼容性。 2.CSS-in-JS增強樣式管理靈活性但可能增大文件體積,CSSHoudini允許直接操作CSS渲染。 3.WebAssembly優化瀏覽器應用性能但學習曲線陡,Serverless簡化開發但需優化冷啟動問題。

HTML的未來充滿了無限可能。 1)新功能和標準將包括更多的語義化標籤和WebComponents的普及。 2)網頁設計趨勢將繼續向響應式和無障礙設計發展。 3)性能優化將通過響應式圖片加載和延遲加載技術提升用戶體驗。

HTML、CSS和JavaScript在網頁開發中的角色分別是:HTML負責內容結構,CSS負責樣式,JavaScript負責動態行為。 1.HTML通過標籤定義網頁結構和內容,確保語義化。 2.CSS通過選擇器和屬性控製網頁樣式,使其美觀易讀。 3.JavaScript通過腳本控製網頁行為,實現動態和交互功能。

HTML是構建網頁結構的基石。 1.HTML定義內容結構和語義,使用、、等標籤。 2.提供語義化標記,如、、等,提升SEO效果。 3.通過標籤實現用戶交互,需注意表單驗證。 4.使用、等高級元素結合JavaScript實現動態效果。 5.常見錯誤包括標籤未閉合和屬性值未加引號,需使用驗證工具。 6.優化策略包括減少HTTP請求、壓縮HTML、使用語義化標籤等。

HTML的作用是通過標籤和屬性定義網頁的結構和內容。 1.HTML通過到、等標籤組織內容,使其易於閱讀和理解。 2.使用語義化標籤如、等增強可訪問性和SEO。 3.優化HTML代碼可以提高網頁加載速度和用戶體驗。

HTMLISNOTAPROGRAMMENGUAGE; ITISAMARKUMARKUPLAGUAGE.1)htmlStructures andFormatSwebContentusingtags.2)itworkswithcsssforstylingandjavascript for Interactivity,增強WebevebDevelopment。
