<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html><head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=FrontPage.Editor.Document>
<meta name=Generator content="Microsoft Excel 11">
<style type="text/CSS">
{
.showTD {color: #003366; }
.hiddenTD {display:none; }
.onFocue {color: #CC66FF;}
.offFocue {color:#003366;}
}
#floater {
LEFT: 445px; POSITION: absolute; TOP: 15px; VISIBILITY: visible; WIDTH: 125px; Z-INDEX: 10}
</STYLE>
</head>
<body><object classid="clsid:0002E559-0000-0000-C000-000000000046" id="Spreadsheet1" VIEWASTEXT>
<param name="HTMLURL" value="">
<param name="HTMLData" value="">
<param name="DataType" value="HTMLDATA">
<param name="AutoFit" value="0">
<param name="DisplayColHeaders" value="-1">
<param name="DisplayGridlines" value="-1">
<param name="DisplayHorizontalScrollBar" value="-1">
<param name="DisplayRowHeaders" value="-1">
<param name="DisplayTitleBar" value="0">
<param name="DisplayToolbar" value="0">
<param name="DisplayVerticalScrollBar" value="-1">
<param name="EnableAutoCalculate" value="-1">
<param name="EnableEvents" value="-1">
<param name="MoveAfterReturn" value="-1">
<param name="MoveAfterReturnDirection" value="0">
<param name="RightToLeft" value="0">
<param name="ViewableRange" value="1:65536">
</object>
<div class="hiddenTD" id="tablers">
<table width=95% align=center border=1 cellspacing=0 cellpadding=0>
<tr>
<td>客户名称A</td>
<td>客户名称B</td>
<td>客户名称C</td>
<td>客户名称D</td>
<tr>
<td>abc</td>
<td>def</td> <td>111</td> <td>222</td> <tr>
<td>ddd</td>
<td>dfdf</td>
<td>ddd</td>
<td>ddd</td>
</table>
</div>
<script language="javascript">
Spreadsheet1.HTMLData = tablers.innerHTML ;
</script>
</body>
</html>
<html><head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=FrontPage.Editor.Document>
<meta name=Generator content="Microsoft Excel 11">
<style type="text/CSS">
{
.showTD {color: #003366; }
.hiddenTD {display:none; }
.onFocue {color: #CC66FF;}
.offFocue {color:#003366;}
}
#floater {
LEFT: 445px; POSITION: absolute; TOP: 15px; VISIBILITY: visible; WIDTH: 125px; Z-INDEX: 10}
</STYLE>
</head>
<body><object classid="clsid:0002E559-0000-0000-C000-000000000046" id="Spreadsheet1" VIEWASTEXT>
<param name="HTMLURL" value="">
<param name="HTMLData" value="">
<param name="DataType" value="HTMLDATA">
<param name="AutoFit" value="0">
<param name="DisplayColHeaders" value="-1">
<param name="DisplayGridlines" value="-1">
<param name="DisplayHorizontalScrollBar" value="-1">
<param name="DisplayRowHeaders" value="-1">
<param name="DisplayTitleBar" value="0">
<param name="DisplayToolbar" value="0">
<param name="DisplayVerticalScrollBar" value="-1">
<param name="EnableAutoCalculate" value="-1">
<param name="EnableEvents" value="-1">
<param name="MoveAfterReturn" value="-1">
<param name="MoveAfterReturnDirection" value="0">
<param name="RightToLeft" value="0">
<param name="ViewableRange" value="1:65536">
</object>
<div class="hiddenTD" id="tablers">
<table width=95% align=center border=1 cellspacing=0 cellpadding=0>
<tr>
<td>客户名称A</td>
<td>客户名称B</td>
<td>客户名称C</td>
<td>客户名称D</td>
<tr>
<td>abc</td>
<td>def</td> <td>111</td> <td>222</td> <tr>
<td>ddd</td>
<td>dfdf</td>
<td>ddd</td>
<td>ddd</td>
</table>
</div>
<script language="javascript">
Spreadsheet1.HTMLData = tablers.innerHTML ;
</script>
</body>
</html>
至于增删改查,无外乎需要添加一点加减乘除的逻辑而已
然后取得excel的内容
public class ParseExcel { public static void main(String[] args) {
parseExcelToExcelPojo("d:/upload.xls");
}
//解析excel文件封装成List<ExcelPojo>
public static List parseExcelToExcelPojo(String filePath) {
Workbook workbook;//excel文件
Sheet sheet; //sheet
Cell cell;//元素
int rowCount = 0; //行数
int colCount = 0; //列数
InputStream inputStream = null;
int beginRow = 0;//开始行数
int beginCol = 0;//开始列数
List lst = new ArrayList();
try {
File file = new File(filePath);
inputStream = new FileInputStream(file);
workbook = Workbook.getWorkbook(inputStream);
sheet = workbook.getSheet(0);
rowCount = sheet.getRows();
colCount = sheet.getColumns();
//拿到开始行和列
for(int i = 0; i < rowCount; i++) {
for(int j = 0; j < colCount; j++) {
String content = sheet.getCell(j, i).getContents();
if(content != null && !"".equals(content)) {
if(content.equals("文件名")) {
beginRow = i+1;
beginCol = j;
i = rowCount;
j = colCount;
}
}
}
}
ExcelPojo excelpojo = null;
for(int i = beginRow; i < rowCount;i++) {
//每行第一个值
String content = sheet.getCell(beginCol, i).getContents();
if(content != null && !"".equals(content)) { //不为空表示本行有记录
excelpojo = new ExcelPojo();
excelpojo.setFileName(sheet.getCell(beginCol, i).getContents());//文件名
excelpojo.setGameName(sheet.getCell(beginCol+1, i).getContents());//游戏名称
excelpojo.setCpId(sheet.getCell(beginCol+2, i).getContents());//cp编号
excelpojo.setGameId(sheet.getCell(beginCol+3, i).getContents());//游戏编号
excelpojo.setGameSize(sheet.getCell(beginCol+4, i).getContents());//游戏大小
excelpojo.setGameType(sheet.getCell(beginCol+5, i).getContents());//游戏类型
excelpojo.setGameDesc(sheet.getCell(beginCol+6, i).getContents());//游戏介绍
excelpojo.setKeyWorks(sheet.getCell(beginCol+7, i).getContents());//关键字
excelpojo.setGameEvaluta(sheet.getCell(beginCol+8, i).getContents());//游戏测评
excelpojo.setFreeId(sheet.getCell(beginCol+9, i).getContents());//计费点编号
excelpojo.setFree(sheet.getCell(beginCol+10, i).getContents());//资费
excelpojo.setFreeDesc(sheet.getCell(beginCol+11, i).getContents());//计费说明
excelpojo.setFullPath(sheet.getCell(beginCol+12, i).getContents());//购买路径
excelpojo.setTriggerCondition(sheet.getCell(beginCol+13, i).getContents());//触发条件
excelpojo.setMatchType(sheet.getCell(beginCol+14, i).getContents());//机型适配
excelpojo.setFileFormat(sheet.getCell(beginCol+15, i).getContents());//文件格式
lst.add(excelpojo);
}
}
for(int i =0; i < lst.size();i++) {
ExcelPojo ep = (ExcelPojo)lst.get(i);
System.out.println("文件名:"+ep.getFileName() + " 游戏名称:"+ep.getGameName() + " cp编号:" + ep.getCpId() + " 游戏编号:" + ep.getGameId() + " 游戏大小:" + ep.getGameSize() + " 游戏类型:" + ep.getGameType() + " 游戏介绍:" + ep.getGameDesc() + " 关键字:"+ep.getKeyWorks()+" 游戏测评:"+ep.getGameEvaluta()+" 计费点编号:"+ep.getFreeId()+" 资费:"+ep.getFree()+" 计费点说明:"+ep.getFreeDesc()+" 计费点购买路径:"+ep.getFullPath()+" 触发条件:" + ep.getTriggerCondition()+" 适配机型:"+ep.getMatchType() + " 文件格式:" + ep.getFileFormat());
}
System.out.println(beginRow + " " + beginCol);
}catch(Exception e) {
}
return lst;
}
}
如果是相同的呢?也插?如果没有修改过的呢?等等问题..
最重要的一点就是否需要安装正版的Office,否则用做商业用途是否会产生经济纠纷.. 谢谢
上网找找,直接调用就可以了,还有好多例子
如果用户修改了。如何获得页面上的excel文件呢?
在线等啊....................
一定要传excel文件到服务器吗?
请问如何判断用户修改了哪些数据呢?
在页面上的数据希望显示成Excel表格样子,也可以对页面数据进行类似Excel的操作
点击保存之后,就提交变量部分的数据到数据库
这样理解对吗
用下面这个工具。
package com.java91.parser;import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hwpf.extractor.*;
import org.apache.poi.hwpf.HWPFDocument;import org.apache.poi.hwpf.usermodel.*;//import LuceneBook.ChineseAnalyzer;import java.io.FileInputStream;
import java.io.File;public class WordParserTest { public static String excelfile = "F:\\docs\\Book1.xls"; public static String wordfile = "F:\\docs\\Site Linkmap Table of Contents.doc"; public static void main(String argv[]) throws Exception { //getWordText(wordfile);
//getWordText(wordfile);
//getExcelText(excelfile); } public static void getWordText(String filename) throws Exception {
FileInputStream in = new FileInputStream(new File(filename)); HWPFDocument doc = new HWPFDocument(in);
Range range = doc.getRange();
String text = range.text(); for (int i = 0; i < range.numParagraphs(); i++) {
Paragraph p = range.getParagraph(i); // 取得每个段落
// 组合文字并添加换行
text = p.text();
text.trim();
// text = " <br> " ;
System.out.println(text);
}
} // 获取doc内纯文本信息
public static void getWordText2(String filename) throws Exception {
FileInputStream in = new FileInputStream(new File(filename)); WordExtractor extractor = new WordExtractor(in);
String text = extractor.getText();
System.out.println(text);
} // 获取Excel内纯文本信息
public static void getExcelText(String filename) throws Exception { HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filename));
HSSFSheet sheet = workbook.getSheetAt(0); // 创建对工作表的引用。 for (int i = 0; i < workbook.getNumberOfSheets(); i++) // 循环取表单对象
{
System.out.print("########## sheet:--" + i + " --########## ");
sheet = workbook.getSheetAt(i); // 查阅文档的Sheet属性
if (sheet != null) {
for (int m = 0; m < sheet.getLastRowNum(); m++) // 按行循环取行对象
{
HSSFRow row = sheet.getRow(m);
if (row == null) {
break;
}
System.out.println("");
if (row.getLastCellNum() <= 0)
break;
System.out.println("-----line:--" + m + " ---- ,col num:" + row.getLastCellNum());
for (int n = 0; n < row.getLastCellNum(); n++) // 按列循环取单元格对象
{
HSSFCell cell = row.getCell((short) n); if (cell == null) {
break;
}
int type = cell.getCellType();
switch (type) {
case 0:
System.out.print(cell.getNumericCellValue() + " , ");
break;
case 1:
System.out.print(cell.getStringCellValue() + " , ");
break;
case 2:
break;
case 3:
System.out.print(" , ");
break;
default:
System.out.print("未知的单元类型" + type + " , ");
}
}
}
}
System.out.println();
}
}}