public static ListStudent parseExcel(){
創(chuàng)新互聯(lián)公司是一家專業(yè)的成都網(wǎng)站建設(shè)公司,我們專注網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、網(wǎng)絡(luò)營銷、企業(yè)網(wǎng)站建設(shè),買鏈接,1元廣告為企業(yè)客戶提供一站式建站解決方案,能帶給客戶新的互聯(lián)網(wǎng)理念。從網(wǎng)站結(jié)構(gòu)的規(guī)劃UI設(shè)計(jì)到用戶體驗(yàn)提高,創(chuàng)新互聯(lián)力求做到盡善盡美。
//解析excel文件 獲取數(shù)據(jù)
//將每行數(shù)據(jù)當(dāng)作一個(gè)Student對(duì)象放入list集合
ListStudent list = new ArryListStudent();
...
return list;
}
public static void updateDataBase(Student stu){
//更新數(shù)據(jù)庫 將Student對(duì)象插入數(shù)據(jù)庫
...
}
public void main(String[] args){
ListStudent list = parseExcel();//讀取excel
for(Student stu:list){//遍歷集合向數(shù)據(jù)庫插入數(shù)據(jù)
updateDataBase(stu);
}
}
大致的寫了下 具體實(shí)現(xiàn)應(yīng)該沒問題吧?
daysTable.setCellSelectionEnabled(true);
daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
daysTable.setDefaultRenderer(daysTable.getColumnClass(0), new TableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
String text = (value == null) ? "" : value.toString();
JLabel cell = new JLabel(text);
cell.setOpaque(true);
if (row == 0) {
cell.setForeground(headerForeground);
cell.setBackground(headerBackground);
} else {
if (isSelected) {
cell.setForeground(selectedForeground);
cell.setBackground(selectedBackground);
} else {
cell.setForeground(foreground);
cell.setBackground(background);
}
}
return cell;
}
一個(gè)例子,方法和這一樣
如果用java實(shí)現(xiàn)的話,那就需要用到j(luò)xl.jar包中提供的類方法來完成了,你可以先查看一下jxl的資料再來做。
還有一種簡單的方法就是用javascript腳本生成,例如:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title無標(biāo)題文檔/title
script language="javascript"
function tableToExcel(tname) {
if(confirm('是否要導(dǎo)出到excel?')!=0)
{
window.clipboardData.setData("Text",document.all(tname).outerHTML);
try
{
ExApp = new ActiveXObject("Excel.Application")
var ExWBk = ExApp.workbooks.add()
var ExWSh = ExWBk.worksheets(1)
ExApp.DisplayAlerts = false
ExApp.visible = true
}
catch(e)
{
alert("導(dǎo)出沒有成功!1.您的電腦沒有安裝Microsoft Excel軟件!2.請(qǐng)?jiān)O(shè)置Internet選項(xiàng)自定義級(jí)別,對(duì)沒有標(biāo)記安全級(jí)別的 ActiveX控件進(jìn)行提示。")
return false
}
ExWBk.worksheets(1).Paste;
}else
{
return;
}
}
/script
/head
body
table id="baba"
tr
tdafdsfsd/td
tdfdfsdfds/td
tdfdfsadfsa/td
tdfdsfsadfds/td
tdfdsfasd/td
tdfdsfsad/td
/tr
tr
tdafdsfsd/td
tdfdfsdfds/td
tdfdfsadfsa/td
tdfdsfsadfds/td
tdfdsfasd/td
tdfdsfsad/td
/tr
tr
tdafdsfsd/td
tdfdfsdfds/td
tdfdfsadfsa/td
tdfdsfsadfds/td
tdfdsfasd/td
tdfdsfsad/td
/tr
/table
input type="button" name="anniu" onclick="tableToExcel('baba')" /
/body
/html