Applet 與 Excel |
尚未結案
|
jichang
一般會員 ![]() ![]() 發表:9 回覆:12 積分:4 註冊:2004-02-11 發送簡訊給我 |
Dear 大大: 小弟最近想嘗試由Client讀取Excel,透過Signed Applet已可讀到Client的檔案,但是無法將Excel的內容讀出,我是使用jxl.jar去讀檔的,若將jxl.jar使用於application是沒問題的,但用於applet就無法使用,不曉得是小弟的設定有問題?或是程式有問題?煩請各位大大幫忙解惑: applet程式碼如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
import jxl.*; public class ExcelView extends JApplet{
private JLabel label;
public void init(){
try{
javax.swing.SwingUtilities.invokeAndWait(new Runnable(){
public void run(){
createApp();
}
});
} catch(Exception e){
System.err.println("Read File Fail!!!");
}
}
public void createApp(){
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem openItem = new JMenuItem("Open");
menu.add(openItem);
openItem.addActionListener(new FileOpenListener());
JMenuItem exitItem = new JMenuItem("Exit");
menu.add(exitItem);
exitItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
System.exit(0);
}
});
label = new JLabel();
Container contentPane = getContentPane();
contentPane.add(label);
}
public class FileOpenListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){
public boolean accept(File f){
return f.getName().toLowerCase().endsWith(".xls")
|| f.isDirectory();
}
public String getDescription(){
return "Excel";
}
});
int r = chooser.showOpenDialog(ExcelView.this);
if (r == JFileChooser.APPROVE_OPTION){
String name = chooser.getSelectedFile().getPath();
try {
InputStream is = new FileInputStream(name);
label.setText(name + "Successful One");
jxl.Workbook rwb = Workbook.getWorkbook(is);
label.setText("Successful Two");
Sheet rs = rwb.getSheet(0);
int rscol = rs.getColumns();
int rsrow = rs.getRows();
int col=0,row=0;
while (col < rscol) {
row = 0;
while (row < rsrow) {
Cell cl = rs.getCell(col,row);
String str = cl.getContents();
label.setText(col + "," + row + ":" + str);
row++;
}
col++;
}
rwb.close();
} catch (Exception e) {
System.err.println(e);
label.setText(e.toString());
}
}
}
}
} HTML程式碼如下(兩個都試過):
<html>
<applet codebase="." code="ExcelView" archive="lib/ExcelView.jar, lib/jxl.jar" width=800 height=300>
</applet>
</html> <html>
<applet codebase="." code="ExcelView" archive="lib/ExcelView.jar" width=800 height=300>
</applet>
</html> 程式位置如下:
applet.htm → C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\jichang\Bar ExcelView.jar、jxl.jar → C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\jichang\Bar\lib 也曾將 ExcelView.jar、jxl.jar 放於 C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\wintech\WEB-INF\lib 程式跑到 label.setText(name "Successful One"); 就停了,請各位大大幫忙看一下,不勝感激~~~
|
neoart
版主 ![]() ![]() ![]() ![]() ![]() 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
老句話
1.用[ code ] ... [ / code ] (發言表上的"#"按鈕)把你的code夾好
沒有排縮,看的很累
2.你的applet在我這裡看到的錯誤是:
載入︰找不到類別 ExcelView。 java.lang.ClassNotFoundException: ExcelView at sun.applet.AppletClassLoader.findClass(Unknown Source) at sun.plugin.security.PluginClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.applet.AppletClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.applet.AppletClassLoader.loadCode(Unknown Source) at sun.applet.AppletPanel.createApplet(Unknown Source) at sun.plugin.AppletViewer.createApplet(Unknown Source) at sun.applet.AppletPanel.runLoader(Unknown Source) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.io.IOException: open HTTP connection failed. at sun.applet.AppletClassLoader.getBytes(Unknown Source) at sun.applet.AppletClassLoader.access$100(Unknown Source) at sun.applet.AppletClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method)你要不要放在可以連外的地方? |
jichang
一般會員 ![]() ![]() 發表:9 回覆:12 積分:4 註冊:2004-02-11 發送簡訊給我 |
Sorry,我再貼一次我的程式: Applet →
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.io.*; import jxl.*; public class ExcelView extends JApplet{ private JLabel label; public void init(){ try{ javax.swing.SwingUtilities.invokeAndWait(new Runnable(){ public void run(){ createApp(); } }); } catch(Exception e){ System.err.println("Read File Fail!!!"); } } public void createApp(){ JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem openItem = new JMenuItem("Open"); menu.add(openItem); openItem.addActionListener(new FileOpenListener()); JMenuItem exitItem = new JMenuItem("Exit"); menu.add(exitItem); exitItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event){ System.exit(0); } }); label = new JLabel(); Container contentPane = getContentPane(); contentPane.add(label); } public class FileOpenListener implements ActionListener{ public void actionPerformed(ActionEvent evt){ JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); chooser.setFileFilter(new javax.swing.filechooser.FileFilter(){ public boolean accept(File f){ return f.getName().toLowerCase().endsWith(".xls") || f.isDirectory(); } public String getDescription(){ return "Excel"; } }); int r = chooser.showOpenDialog(ExcelView.this); if (r == JFileChooser.APPROVE_OPTION){ String name = chooser.getSelectedFile().getPath(); try { InputStream is = new FileInputStream(name); label.setText(name "Successful One"); jxl.Workbook rwb = Workbook.getWorkbook(is); label.setText("Successful Two"); Sheet rs = rwb.getSheet(0); int rscol = rs.getColumns(); int rsrow = rs.getRows(); int col=0,row=0; while (col < rscol) { row = 0; while (row < rsrow) { Cell cl = rs.getCell(col,row); String str = cl.getContents(); label.setText(col "," row ":" str); row ; } col ; } rwb.close(); } catch (Exception e) { System.err.println(e); label.setText(e.toString()); } } } } }html → <applet codebase="." code="ExcelView" archive="lib/ExcelView.jar, lib/jxl.jar" width=800 height=300> </applet> <applet codebase="." code="ExcelView" archive="lib/ExcelView.jar" width=800 height=300> </applet>由於我這邊是內部網路,所以無法連外,因此請多多見諒~~~ 發表人 - jichang 於 2005/05/30 18:27:16 |
neoart
版主 ![]() ![]() ![]() ![]() ![]() 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
jichang
一般會員 ![]() ![]() 發表:9 回覆:12 積分:4 註冊:2004-02-11 發送簡訊給我 |
|
neoart
版主 ![]() ![]() ![]() ![]() ![]() 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
jichang
一般會員 ![]() ![]() 發表:9 回覆:12 積分:4 註冊:2004-02-11 發送簡訊給我 |
嗯嗯,了解,主控台訊息如下,麻煩大大幫忙看一下:
Java Plug-in 1.5.0_02 使用 JRE 版本 1.5.0_02 Java HotSpot(TM) Client VM 使用者主目錄 = C:\Documents and Settings\wendellc ---------------------------------------------------- c: 清除主控台視窗 f: 終結在結束佇列上的物件 g: 資源回收 h: 顯示此說明訊息 l: 傾印類別載入器清單 m: 列印記憶體用量 o: 觸發記錄 p: 重新載入 Proxy 配置 q: 隱藏主控台 r: 重新載入策略配置 s: 傾印系統和部署屬性 t: 傾印執行緒清單 v: 傾印執行緒堆疊 x: 清除類別載入器快取記憶體 0-5: 將追蹤層次設定成 |
neoart
版主 ![]() ![]() ![]() ![]() ![]() 發表:22 回覆:582 積分:425 註冊:2003-05-09 發送簡訊給我 |
|
jichang
一般會員 ![]() ![]() 發表:9 回覆:12 積分:4 註冊:2004-02-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |