java項目,excel文件如何直接在網頁里打開

建議你先轉換成pdf,在轉換成swf放到網上看.直接打開的話你的利用插件.比方說金格就是用來專門查看office辦公文檔的web插件

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

用POI解析Excel,解析好後轉成xml,在輸出到html就可以了
類似這樣,sheet是工作區,column是行,cell是單元格
不過這樣這樣的話merge過的單元格可能比較難表示
<sheet>
<column>
<cell />
<cell />
</column>
</sheet>

㈢ java 導出html 到 Excel 問題

最後調用一下 CollectGarbage();

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

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

㈤ java poi怎麼在html中展示excel

首先html不能讀取本地excel文件
其次就算是javascript 也是不允許的
這是為了安全考慮
如果前端腳本可以讀取本地文件 那很不安全

答題不易,互相理解,您的點贊是我前進的動力,
如果我的回答沒能幫助您,請繼續追問。
您也可以向我們團隊發出請求,會有更專業的人來為您解答!

㈥ java excel怎麼讀取到html

一般都是用jacob的,這里不能發地址,自己搜一下,要下.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 web 上傳的excel文件以html文件存儲怎麼做啊,求例子

這個你把他分解一下就很簡單了 你會文件上傳吧?會的話ok
先獲取上傳數據流 然後通過jxl解析他
獲取excel內容 然後拼寫html字元串 在寫到想存儲的地方

㈧ 在後台用java生成的excel怎麼實現在頁面上

頁面調用請求,請求生成excel文件流。文件流返回至頁面,頁面觸發下載任務就ok。

㈨ 為什麼java操作excel導出默認文件為html 怎麼改成.xls啊

適用各種文件類型的方法:

在返迴文件之前加上
String str_mime=new MimetypesFileTypeMap().getContentType(file);//取文件的mime類型
response.setContentType(str_mime);//設置http返回報文的ContentType