parent
1220f1cad4
commit
4ca1131e85
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: javax.mail:mail:1.4.7">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/javax/mail/mail/1.4.7/mail-1.4.7.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/javax/mail/mail/1.4.7/mail-1.4.7-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/javax/mail/mail/1.4.7/mail-1.4.7-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: net.sourceforge.jexcelapi:jxl:2.6.12">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/net/sourceforge/jexcelapi/jxl/2.6.12/jxl-2.6.12-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.jsoup:jsoup:1.10.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.10.1/jsoup-1.10.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.10.1/jsoup-1.10.1-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.10.1/jsoup-1.10.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -1,13 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.jsoup:jsoup:1.12.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.12.1/jsoup-1.12.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.12.1/jsoup-1.12.1-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jsoup/jsoup/1.12.1/jsoup-1.12.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="aspose-cells-8.5.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/aspose-cells-8.5.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,171 @@
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import jxl.Cell;
|
||||
import jxl.Range;
|
||||
import jxl.Sheet;
|
||||
import jxl.Workbook;
|
||||
import jxl.format.Alignment;
|
||||
import jxl.format.CellFormat;
|
||||
import jxl.format.Colour;
|
||||
import jxl.format.VerticalAlignment;
|
||||
|
||||
public class ExcelTransformHtml {
|
||||
public static String getExcelInfo(File sourcefile) throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
InputStream is = new FileInputStream(sourcefile);
|
||||
Workbook rwb = Workbook.getWorkbook(is);
|
||||
Sheet sheet = rwb.getSheet(0);
|
||||
int colnum = sheet.getColumns();
|
||||
int rownum = sheet.getRows();
|
||||
Map<String, String> map[] = getRowSpanColSpanMap(sheet);
|
||||
sb.append("<table border='1' cellspacing='0'>");
|
||||
for (int row = 0; row < rownum; row++) {
|
||||
sb.append("<tr>");
|
||||
for (int col = 0; col < colnum; col++) {
|
||||
Cell cell = sheet.getCell(col, row);
|
||||
String content = cell.getContents();
|
||||
CellFormat cellFormat = cell.getCellFormat();
|
||||
if (map[0].containsKey(row + "," + col)) {
|
||||
String pointString = map[0].get(row + "," + col);
|
||||
map[0].remove(row + "," + col);
|
||||
int bottomeRow = Integer.valueOf(pointString.split(",")[0]);
|
||||
int bottomeCol = Integer.valueOf(pointString.split(",")[1]);
|
||||
int rowSpan = bottomeRow - row + 1;
|
||||
int colSpan = bottomeCol - col + 1;
|
||||
sb.append("<td rowspan= '" + rowSpan + "' colspan= '" + colSpan + "' ");
|
||||
} else if (map[1].containsKey(row + "," + col)) {
|
||||
map[1].remove(row + "," + col);
|
||||
continue;
|
||||
} else {
|
||||
sb.append("<td ");
|
||||
}
|
||||
if (cellFormat != null) {
|
||||
Alignment alignment = cellFormat.getAlignment();
|
||||
sb.append("align='" + convertToHtmlGrammer(alignment) + "' ");
|
||||
VerticalAlignment verticalAlignment = cellFormat.getVerticalAlignment();
|
||||
sb.append("valign='" + convertToHtmlGrammer(verticalAlignment) + "' ");
|
||||
// sb.append("style='color:" + convertToHtmlGrammer(cellFormat.getFont().getColour()) + ";"); //
|
||||
Colour bgcolour = cellFormat.getBackgroundColour();
|
||||
// sb.append("background-color:" + convertToHtmlGrammer(bgcolour) + ";"); //
|
||||
// Colour bottomColour = cellFormat.getBorderColour(Border.BOTTOM); //
|
||||
// Colour leftColour = cellFormat.getBorderColour(Border.LEFT);
|
||||
// Colour rightColour = cellFormat.getBorderColour(Border.RIGHT);
|
||||
// Colour topColour = cellFormat.getBorderColour(Border.TOP);
|
||||
|
||||
// System.out.print("bottomColour:" +
|
||||
// bottomColour.getDescription());
|
||||
// System.out.print(" leftColour:" +
|
||||
// leftColour.getDescription());
|
||||
// System.out.print(" rightColour:" +
|
||||
// rightColour.getDescription());
|
||||
// System.out.println(" topColour:" +
|
||||
// topColour.getDescription());
|
||||
|
||||
// sb.append("border-color:" + convertToHtmlGrammer(bottomColour) + ";"); //
|
||||
sb.append("' ");
|
||||
}
|
||||
sb.append(">");
|
||||
if (content == null || "".equals(content.trim())) {
|
||||
sb.append(" ");
|
||||
} else {
|
||||
sb.append(content);
|
||||
}
|
||||
sb.append("</td>");
|
||||
}
|
||||
sb.append("</tr>");
|
||||
}
|
||||
sb.append("</table>");
|
||||
rwb.close();
|
||||
is.close();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, String>[] getRowSpanColSpanMap(Sheet sheet) {
|
||||
Map<String, String> map0 = new HashMap<String, String>();
|
||||
Map<String, String> map1 = new HashMap<String, String>();
|
||||
Range[] range = sheet.getMergedCells();
|
||||
for (int i = 0; i < range.length; i++) {
|
||||
Cell topCell = range[i].getTopLeft();
|
||||
Cell bottomCell = range[i].getBottomRight();
|
||||
int topRow = topCell.getRow();
|
||||
int topCol = topCell.getColumn();
|
||||
int bottomRow = bottomCell.getRow();
|
||||
int bottomCol = bottomCell.getColumn();
|
||||
map0.put(topRow + "," + topCol, bottomRow + "," + bottomCol);
|
||||
int tempRow = topRow;
|
||||
while (tempRow <= bottomRow) {
|
||||
int tempCol = topCol;
|
||||
while (tempCol <= bottomCol) {
|
||||
map1.put(tempRow + "," + tempCol, "");
|
||||
tempCol++;
|
||||
}
|
||||
tempRow++;
|
||||
}
|
||||
map1.remove(topRow + "," + topCol);
|
||||
}
|
||||
Map[] map = { map0, map1 };
|
||||
return map;
|
||||
}
|
||||
|
||||
private static String convertToHtmlGrammer(Alignment alignment) {
|
||||
String align = "left";
|
||||
switch (alignment.getValue()) {
|
||||
case 1:
|
||||
align = "left";
|
||||
break;
|
||||
case 2:
|
||||
align = "center";
|
||||
break;
|
||||
case 3:
|
||||
align = "right";
|
||||
break;
|
||||
case 5:
|
||||
align = "justify";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return align;
|
||||
}
|
||||
|
||||
private static String convertToHtmlGrammer(VerticalAlignment verticalAlignment) {
|
||||
String valign = "middle";
|
||||
switch (verticalAlignment.getValue()) {
|
||||
case 1:
|
||||
valign = "middle";
|
||||
break;
|
||||
case 2:
|
||||
valign = "bottom";
|
||||
break;
|
||||
case 3:
|
||||
valign = "top";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return valign;
|
||||
}
|
||||
|
||||
/*private static String convertToHtmlGrammer(Colour colour) {
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
if (colour != null && !"default background".equalsIgnoreCase(colour.getDescription())) {
|
||||
sb.append("#");
|
||||
sb.append(fillWithZero(Integer.toHexString(colour.getDefaultRGB().getRed())));
|
||||
sb.append(fillWithZero(Integer.toHexString(colour.getDefaultRGB().getGreen())));
|
||||
sb.append(fillWithZero(Integer.toHexString(colour.getDefaultRGB().getBlue())));
|
||||
}
|
||||
return sb.toString();
|
||||
}*/
|
||||
|
||||
private static String fillWithZero(String str) {
|
||||
if (str != null && str.length() < 2) {
|
||||
return "0" + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import java.io.*;
|
||||
import java.util.Enumeration;
|
||||
|
||||
|
||||
public class Mht2HtmlUtil {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
mht2html("C:\\Users\\Administrator\\Desktop\\028初中阶段校数、班数.mht", "d:\\test.htm");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将 mht文件转换成 html文件
|
||||
*
|
||||
* @param srcMht // mht 文件的位置
|
||||
* @param descHtml // 转换后输出的HTML的位置
|
||||
*/
|
||||
public static void mht2html(String srcMht, String descHtml) {
|
||||
try {
|
||||
InputStream fis = new FileInputStream(srcMht);
|
||||
Session mailSession = Session.getDefaultInstance(
|
||||
System.getProperties(), null);
|
||||
MimeMessage msg = new MimeMessage(mailSession, fis);
|
||||
Object content = msg.getContent();
|
||||
if (content instanceof Multipart) {
|
||||
MimeMultipart mp = (MimeMultipart) content;
|
||||
MimeBodyPart bp1 = (MimeBodyPart) mp.getBodyPart(0);
|
||||
|
||||
// 获取mht文件内容代码的编码
|
||||
String strEncodng = getEncoding(bp1);
|
||||
|
||||
// 获取mht文件的内容
|
||||
String strText = getHtmlText(bp1, strEncodng);
|
||||
if (strText == null)
|
||||
return;
|
||||
// 最后保存HTML文件
|
||||
SaveHtml(strText, descHtml);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将提取出来的html内容写入保存的路径中。
|
||||
*
|
||||
* @param s_HtmlTxt
|
||||
* @param s_HtmlPath
|
||||
*/
|
||||
public static boolean SaveHtml(String s_HtmlTxt, String s_HtmlPath) {
|
||||
try {
|
||||
Writer out = null;
|
||||
out = new OutputStreamWriter(
|
||||
new FileOutputStream(s_HtmlPath, false), "utf-8");
|
||||
out.write(s_HtmlTxt);
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取mht文件中的内容代码
|
||||
*
|
||||
* @param bp
|
||||
* @param strEncoding 该mht文件的编码
|
||||
* @return
|
||||
*/
|
||||
private static String getHtmlText(MimeBodyPart bp, String strEncoding) {
|
||||
InputStream textStream = null;
|
||||
BufferedInputStream buff = null;
|
||||
BufferedReader br = null;
|
||||
Reader r = null;
|
||||
try {
|
||||
textStream = bp.getInputStream();
|
||||
buff = new BufferedInputStream(textStream);
|
||||
r = new InputStreamReader(buff, strEncoding);
|
||||
br = new BufferedReader(r);
|
||||
StringBuffer strHtml = new StringBuffer("");
|
||||
String strLine = null;
|
||||
while ((strLine = br.readLine()) != null) {
|
||||
System.out.println(strLine);
|
||||
strHtml.append(strLine + "\r\n");
|
||||
}
|
||||
br.close();
|
||||
r.close();
|
||||
textStream.close();
|
||||
return strHtml.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (br != null)
|
||||
br.close();
|
||||
if (buff != null)
|
||||
buff.close();
|
||||
if (textStream != null)
|
||||
textStream.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取mht网页文件中内容代码的编码
|
||||
*
|
||||
* @param bp
|
||||
* @return
|
||||
*/
|
||||
private static String getEncoding(MimeBodyPart bp) {
|
||||
if (bp == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Enumeration list = bp.getAllHeaders();
|
||||
while (list.hasMoreElements()) {
|
||||
javax.mail.Header head = (javax.mail.Header) list.nextElement();
|
||||
if (head.getName().equalsIgnoreCase("Content-Type")) {
|
||||
String strType = head.getValue();
|
||||
int pos = strType.indexOf("charset=");
|
||||
if (pos >= 0) {
|
||||
String strEncoding = strType.substring(pos + 8,
|
||||
strType.length());
|
||||
if (strEncoding.startsWith("\"")
|
||||
|| strEncoding.startsWith("\'")) {
|
||||
strEncoding = strEncoding.substring(1,
|
||||
strEncoding.length());
|
||||
}
|
||||
if (strEncoding.endsWith("\"")
|
||||
|| strEncoding.endsWith("\'")) {
|
||||
strEncoding = strEncoding.substring(0,
|
||||
strEncoding.length() - 1);
|
||||
}
|
||||
if (strEncoding.toLowerCase().compareTo("gb2312") == 0) {
|
||||
strEncoding = "gbk";
|
||||
}
|
||||
return strEncoding;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue