導航:首頁 > 編程語言 > javaexcelhtml格式

javaexcelhtml格式

發布時間:2022-06-27 15:08:21

① 您好,您11年提的問題:java 導出excel時,變成html格式了,比較急~~~ 請問這個您你怎麼解決的呢

另存為xlsx格式就好啦。

② java 復制excel內容 在html顯示

java用POI讀取和操作數據
然後用table輸出就可以了

③ JAVA導出Excel時不是xls文件,而是html格式的

在導出時.加上這句話
<%@page
contentType="application/vnd.ms-excel;charset=UTF-8"
%>
加在最前面就行了.

④ java 有關word,excel,pdf轉換成html 有幾種方式

java將Word/Excel/PDF文件轉換成HTML整理

項目開發過程中,需求涉及到了各種文檔轉換為HTML或者網頁易顯示格式,現在將實現方式整理如下:
一、使用Jacob轉換Word,Excel為HTML

「JACOB一個Java-COM中間件.通過這個組件你可以在Java應用程序中調用COM組件和Win32 libraries。」

首先下載Jacob包,JDK1.5以上需要使用Jacob1.9版本(JDK1.6尚未測試),與先前的Jacob1.7差別不大

1、將壓縮解壓後,Jacob.jar添加到Libraries中;

2、將Jacob.dll放至「WINDOWS\SYSTEM32」下面。

需要注意的是:
【使用IDE啟動Web伺服器時,系統讀取不到Jacob.dll,例如用MyEclipse啟動Tomcat,就需要將dll文件到MyEclipse安裝目錄的「jre\bin」下面。
一般系統沒有載入到Jacob.dll文件時,報錯信息為:「java.lang.UnsatisfiedLinkError: no jacob in java.library.path」】

新建類:
1public class JacobUtil
2{
3 public static final int WORD_HTML = 8;
4
5 public static final int WORD_TXT = 7;
6
7 public static final int EXCEL_HTML = 44;
8
9 /** *//**
10 * WORD轉HTML
11 * @param docfile WORD文件全路徑
12 * @param htmlfile 轉換後HTML存放路徑
13 */
14 public static void wordToHtml(String docfile, String htmlfile)
15 {
16 ActiveXComponent app = new ActiveXComponent("Word.Application"); // 啟動word
17 try
18 {
19 app.setProperty("Visible", new Variant(false));
20 Dispatch docs = app.getProperty("Documents").toDispatch();
21 Dispatch doc = Dispatch.invoke(
22 docs,
23 "Open",
24 Dispatch.Method,
25 new Object[] { docfile, new Variant(false),
26 new Variant(true) }, new int[1]).toDispatch();
27 Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {
28 htmlfile, new Variant(WORD_HTML) }, new int[1]);
29 Variant f = new Variant(false);
30 Dispatch.call(doc, "Close", f);
31 }
32 catch (Exception e)
33 {
34 e.printStackTrace();
35 }
36 finally
37 {
38 app.invoke("Quit", new Variant[] {});
39 }
40 }
41
42 /** *//**
43 * EXCEL轉HTML
44 * @param xlsfile EXCEL文件全路徑
45 * @param htmlfile 轉換後HTML存放路徑
46 */
47 public static void excelToHtml(String xlsfile, String htmlfile)
48 {
49 ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 啟動word
50 try
51 {
52 app.setProperty("Visible", new Variant(false));
53 Dispatch excels = app.getProperty("Workbooks").toDispatch();
54 Dispatch excel = Dispatch.invoke(
55 excels,
56 "Open",
57 Dispatch.Method,
58 new Object[] { xlsfile, new Variant(false),
59 new Variant(true) }, new int[1]).toDispatch();
60 Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {
61 htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
62 Variant f = new Variant(false);
63 Dispatch.call(excel, "Close", f);
64 }
65 catch (Exception e)
66 {
67 e.printStackTrace();
68 }
69 finally
70 {
71 app.invoke("Quit", new Variant[] {});
72 }
73 }
74
75}
76
當時我在找轉換控制項時,發現網易也轉載了一偏關於Jacob使用幫助,但其中出現了比較嚴重的錯誤:String htmlfile = "C:\\AA";
只指定到了文件夾一級,正確寫法是String htmlfile = "C:\\AA\\xxx.html";

到此WORD/EXCEL轉換HTML就已經差不多了,相信大家應該很清楚了:)

二、使用XPDF將PDF轉換為HTML

1、下載xpdf最新版本,地址:http://www.foolabs.com/xpdf/download.html
我下載的是xpdf-3.02pl2-win32.zip

2、下載中文支持包
我下載的是xpdf-chinese-simplified.tar.gz

3、下載pdftohtml支持包
地址:http://sourceforge.net/projects/pdftohtml/
我下載的是:pdftohtml-0.39-win32.tar.gz

4、解壓調試
1) 先將xpdf-3.02pl2-win32.zip解壓,解壓後的內容可根據需要進行刪減,如果只需要轉換為txt格式,其他的exe文件可以刪除,只保留pdftotext.exe,以此類推;
2) 然後將xpdf-chinese-simplified.tar.gz解壓到剛才xpdf-3.02pl2-win32.zip的解壓目錄;
3) 將pdftohtml-0.39-win32.tar.gz解壓,pdftohtml.exe解壓到xpdf-3.02pl2-win32.zip的解壓目錄;
4) 目錄結構:
+---[X:\xpdf]
|-------各種轉換用到的exe文件
|
|-------xpdfrc
|
+------[X:\xpdf\xpdf-chinese-simplified]
|
|
+-------很多轉換時需要用到的字元文件

xpdfrc:此文件是用來聲明轉換字元集對應路徑的文件

5) 修改xpdfrc文件(文件原名為sample-xpdfrc)
修改文件內容為:
Txt代碼

#----- begin Chinese Simplified support package
cidToUnicode Adobe-GB1 xpdf-chinese-simplified\Adobe-GB1.cidToUnicode
unicodeMap ISO-2022-CN xpdf-chinese-simplified\ISO-2022-CN.unicodeMap
unicodeMap EUC-CN xpdf-chinese-simplified\EUC-CN.unicodeMap
unicodeMap GBK xpdf-chinese-simplified\GBK.unicodeMap
cMapDir Adobe-GB1 xpdf-chinese-simplified\CMap
toUnicodeDir xpdf-chinese-simplified\CMap
fontDir C:\WINDOWS\Fonts
displayCIDFontTT Adobe-GB1 C:\WINDOWS\Fonts\simhei.ttf
#----- end Chinese Simplified support package

6) 創建bat文件pdftohtml.bat(放置的路徑不能包含空格)
內容為:
Txt代碼

@echo off
set folderPath=%1
set filePath=%2
cd /d %folderPath%
pdftohtml -enc GBK %filePath%
exit
7) 創建類

JAVA代碼

public class ConvertPdf
{
private static String INPUT_PATH;
private static String PROJECT_PATH;

public static void convertToHtml(String file, String project)
{
INPUT_PATH = file;
PROJECT_PATH = project;
if(checkContentType()==0)
{
toHtml();
}
}

private static int checkContentType()
{
String type = INPUT_PATH.substring(INPUT_PATH.lastIndexOf(".") + 1, INPUT_PATH.length())
.toLowerCase();
if (type.equals("pdf"))
return 0;
else
return 9;
}

private static void toHtml()
{
if(new File(INPUT_PATH).isFile())
{
try
{
String cmd = "cmd /c start X:\\pdftohtml.bat \"" + PROJECT_PATH + "\" \"" + INPUT_PATH + "\"";
Runtime.getRuntime().exec(cmd);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

}

⑤ java excel轉html多個sheet怎麼合並到一個excel里

poi在讀取excel的時候,是按每個sheet,row,cell讀取的,分別對應sheet頁,行,單元格,你順序讀取,全都讀取到內存里,然後再按照你的格式在前台顯示就完了。

⑥ java excel怎麼讀取到html

一般都是用jacob的,這里不能發地址,自己搜一下,要下1.9的版本
1、我們解開下載的jacob_1.9.zip,在文件夾中找到jacob.dll和jacob.jar兩個文件
2、將壓縮包解壓後,Jacob.jar添加到Libraries中;
3、將Jacob.dll放至「WINDOWS\SYSTEM32」下面。
需要注意的是:
【使用IDE啟動Web伺服器時,系統讀取不到Jacob.dll,例如用MyEclipse啟動Tomcat,就需要將dll文件到MyEclipse安裝目錄的「jre\bin」下面。
一般系統沒有載入到Jacob.dll文件時,報錯信息為:「java.lang.UnsatisfiedLinkError: no jacob in java.library.path」】

使用Jacob轉換Word,Excel為HTML

JAVA代碼:

Java代碼
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class TransformFiletoHtml
{
int WORD_HTML = 8;
int WORD_TXT = 7;
int EXCEL_HTML = 44;

/**
* WORD轉HTML
* @param docfile WORD文件全路徑
* @param htmlfile 轉換後HTML存放路徑
*/
public void wordToHtml(String docfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Word.Application"); // 啟動word
try
{
app.setProperty("Visible", new Variant(false));
Dispatch docs = app.getProperty("Documents").toDispatch();
Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(doc, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}

/**
* EXCEL轉HTML
* @param xlsfile EXCEL文件全路徑
* @param htmlfile 轉換後HTML存放路徑
*/
public void excelToHtml(String xlsfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 啟動excel
try
{
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.invoke(excels,"Open",Dispatch.Method,new Object[] { xlsfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}

/**
* /刪除指定文件夾
* @param folderPath 文件夾全路徑
* @param htmlfile 轉換後HTML存放路徑
*/
public void delFolder(String folderPath)
{
try
{
delAllFile(folderPath); //刪除完裡面所有內容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); //刪除空文件夾
} catch (Exception e) {e.printStackTrace();}
}

/**
* /刪除指定文件夾下所有文件
* @param path 文件全路徑
*/
public boolean delAllFile(String path)
{
boolean flag = false;
File file = new File(path);
if (!file.exists())
{
return flag;
}
if (!file.isDirectory())
{
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++)
{
if (path.endsWith(File.separator))
{
temp = new File(path + tempList[i]);
}
else
{
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile())
{
temp.delete();
}
if (temp.isDirectory())
{
delAllFile(path + "/" + tempList[i]);//先刪除文件夾裡面的文件
delFolder(path + "/" + tempList[i]);//再刪除空文件夾
flag = true;
}
}
return flag;
}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class TransformFiletoHtml
{
int WORD_HTML = 8;
int WORD_TXT = 7;
int EXCEL_HTML = 44;

/**
* WORD轉HTML
* @param docfile WORD文件全路徑
* @param htmlfile 轉換後HTML存放路徑
*/
public void wordToHtml(String docfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Word.Application"); // 啟動word
try
{
app.setProperty("Visible", new Variant(false));
Dispatch docs = app.getProperty("Documents").toDispatch();
Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(doc, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}

/**
* EXCEL轉HTML
* @param xlsfile EXCEL文件全路徑
* @param htmlfile 轉換後HTML存放路徑
*/
public void excelToHtml(String xlsfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 啟動excel
try
{
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.invoke(excels,"Open",Dispatch.Method,new Object[] { xlsfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}

/**
* /刪除指定文件夾
* @param folderPath 文件夾全路徑
* @param htmlfile 轉換後HTML存放路徑
*/
public void delFolder(String folderPath)
{
try
{
delAllFile(folderPath); //刪除完裡面所有內容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); //刪除空文件夾
} catch (Exception e) {e.printStackTrace();}
}

/**
* /刪除指定文件夾下所有文件
* @param path 文件全路徑
*/
public boolean delAllFile(String path)
{
boolean flag = false;
File file = new File(path);
if (!file.exists())
{
return flag;
}
if (!file.isDirectory())
{
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++)
{
if (path.endsWith(File.separator))
{
temp = new File(path + tempList[i]);
}
else
{
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile())
{
temp.delete();
}
if (temp.isDirectory())
{
delAllFile(path + "/" + tempList[i]);//先刪除文件夾裡面的文件
delFolder(path + "/" + tempList[i]);//再刪除空文件夾
flag = true;
}
}
return flag;
}
}調用JAVA代碼:

Java代碼
public class Test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TransformFiletoHtml trans = new TransformFiletoHtml();
trans.wordToHtml("D:\\sinye.doc", "D:\\sinye.html");
}

}

public class Test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TransformFiletoHtml trans = new TransformFiletoHtml();
trans.wordToHtml("D:\\sinye.doc", "D:\\sinye.html");
}

} 只寫了一個測試word轉html的,excel轉html的同理,在TransformFiletoHtml類中,寫了兩個方法,一個是刪除文件夾的方法(delFolder()),一個是刪除文件夾下所有文件的方法(delAllFile())。

⑦ java可以實現Excel另存為html格式的文件嗎

html是網頁,java可以讀取excel的數據展示到前台html頁面。之後如果你想獲取html文件,可以在前台html顯示後,右鍵查看網頁源代碼,復制。

⑧ java 導出excel時,變成html格式了,比較急~~~

加入"application/vnd.ms-excel「這個就好了,
不知道你用什麼方式導的,用struts還是直接用jsp的。
都是要加application/vnd.ms-excel,加的位置不同而已

⑨ java導出execl出現html格式

response.setContentType("application/vnd.ms-excel;charset=GBK");
response.setHeader("Content-disposition","attachment; filename="+fileName+".xls");

⑩ 如何用java來將excel文件轉化為html文件問題

可以導入spire.xls.jar(只需導入這一個jar即可),直接下載jar包,然後解壓將lib文件夾下的jar文件導入java程序;如果創建的是Maven程序的話,需要在pom.xml文件中配置maven路徑並指定Free Spire.XLS for Java的依賴,導入,如下配置:

<repositories>
<repository>
<id>com.e-iceblue</id>
<url>http://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId> e-iceblue </groupId>
<artifactId>spire.xls</artifactId>
<version>2.2.0</version>
</dependency></dependencies>

完成導入後,參考如下代碼將excel轉為html:

import com.spire.xls.*;

public class ExcelToHtml {
public static void main(String[] args) {
//載入Excel工作表
Workbook wb = new Workbook();
wb.loadFromFile("test.xlsx");

//獲取工作表
Worksheet sheet = wb.getWorksheets().get(0);

//調用方法將Excel保存為HTML
sheet.saveToHtml("ToHtml.html");
}
}

閱讀全文

與javaexcelhtml格式相關的資料

熱點內容
livecn伺服器地址 瀏覽:255
程序員這個工作真的很吃香嗎 瀏覽:842
程序員和數學分析師待遇 瀏覽:676
壓縮氣彈簧怎麼拆 瀏覽:319
華為公有雲伺服器添加虛擬ip 瀏覽:207
程序員和運營哪個累 瀏覽:22
抖音安卓信息提示音怎麼設置 瀏覽:454
光速虛擬機的共享文件夾 瀏覽:246
程序員培訓機構發的朋友圈真實性 瀏覽:742
天乾地支簡單演算法 瀏覽:299
下載個壓縮文件 瀏覽:298
普通人電腦關機vs程序員關機 瀏覽:628
米酷建站源碼 瀏覽:115
氫氣app怎麼搜搭配 瀏覽:619
pdf綠盟 瀏覽:505
固態硬碟編譯器重建 瀏覽:391
怎樣編輯硬碟文件夾 瀏覽:660
安卓系統如何打開電腦軟體 瀏覽:572
android監聽事件處理 瀏覽:750
h3c伺服器怎麼看功率 瀏覽:122