[jxcell]使用jxcell导入excel中重命名的单元格内容

引用jxcell.jar包

import java.util.HashMap;
import java.util.Iterator;
import com.jxcell.*;

public class excelImport {
@SuppressWarnings("unchecked")
public static void main(String args[])
{
try{
int colNum = 0;
int rowNum = 0;
String[] str1;
View tempView = new View();
//读取excel
tempView.read(".//44.xls");
//取出该excel中重命名单元格的个数
int numAll = tempView.getDefinedNameCount();
HashMap mapInfo = new HashMap();

//暂存单元格名称
String strName;
//暂存单元格位置字符串:如Sheet1!$B$1
String strLocal;
//暂存单元格中内容
String strValue;
String strA = "A";
//如果表格范围超过26列 将字母列数转化为整数
char[] colChar;
char charA = 'A';
for(int i = 1;i <= numAll;i++)
{
strName = tempView.getDefinedName(i);
strLocal = tempView.getDefinedName(strName);
//分割取出行列值
str1 = strLocal.split("//u0024");
//表格列范围小于26列
if(str1[1].length() == 1){
colNum = (int)str1[1].charAt(0) - (int)strA.charAt(0);
}
//表格列范围大于26列
else if(str1[1].length() == 2){
colChar = str1[1].toCharArray();
colNum = 26 * (colChar[0] - charA + 1) + (colChar[1] - charA);
}
rowNum = Integer.parseInt(str1[2]) - 1;
strValue = tempView.getText(rowNum,colNum);
mapInfo.put(strName, strValue);
}
//使用迭代器遍历哈希map的key值
for (Iterator i=mapInfo.keySet().iterator(); i.hasNext(); ){
System.out.println(i.next());
}
System.out.print("123");
}
catch (CellException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
}
}

你可能感兴趣的:([jxcell]使用jxcell导入excel中重命名的单元格内容)