日期:2014-05-20 浏览次数:20811 次
package com.djk.design.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
/**
* 客户端测试方法
* @author djk
*
*/
public class OperatorExeclTest
{
public static void main(String[] args) throws Exception
{
OperatorExecl operatorExecl = new DjkOperatorExecl();
Map<String,Set<String>> map= operatorExecl.getResult("E:/my.xls");
System.out.println(map);
}
}
/**
* 操作execle文件
* @author djk
*
*/
interface OperatorExecl
{
Map<String,Set<String>> getResult(String path) throws Exception ;
}
/**
* 实现类
* @author djk
*
*/
class DjkOperatorExecl implements OperatorExecl
{
@Override
public Map<String, Set<String>> getResult(String path) throws Exception
{
Set<String> list = null;
Map<String,Set<String>> map = new HashMap<String, Set<String>>();
Workbook book = Workbook.getWorkbook(new File(path));
// 获得第一个工作表对象
Sheet sheet = book.getSheet(0);
//获得行数
int rows = sheet.getRows();
//获得列数数
int columns = sheet.getColumns();
String resultkey = null;
String resultvalue = null;
for(int i = 1;i<rows;i++)
{
for(int j = 0;j<columns;j++)
{
Cell cell1 = sheet.getCell(j, i);
if(MyConstant.TWOCOLUMN.getValue() ==j)
{
resultkey = cell1.getContents();