Excel导入java.io.FileNotFoundException: test.xls (The system cannot find the file specified求指导 5
很急!!以下是action部分代码求打大神们指教privateStringfilePath;publicStringgetFilePath(){returnfilePat...
很急!!以下是action部分代码求 打大神们指教
private String filePath;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public ActionForward ImpDataBaseFromExcel(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException {
String filePath = new String(request.getParameter("path").getBytes("8859_1"), "gb2312");
String tablename = new String(request.getParameter("tablename").getBytes("8859_1"), "gb2312");
String tablevalue = new String(request.getParameter("tablevalue").getBytes("8859_1"), "gb2312");
String allCol = new String(request.getParameter("col").getBytes("8859_1"), "gb2312");
String user = new String(request.getParameter("user").getBytes("8859_1"), "gb2312");
String password = new String(request.getParameter("password").getBytes("8859_1"), "gb2312");
String databasename = new String(request.getParameter("databasename").getBytes("8859_1"),"gb2312");
String databaseaddress = new String(request.getParameter(
"databaseaddress").getBytes("8859_1"), "gb2312");
String url = "jdbc:oracle:thin:@" + databaseaddress + ":1521:"
+ databasename;
String id = null;
// 拆分表字段
String[] singleTableValueList = tablevalue.split(",");
List<String> tablevalueList = new ArrayList<String>();// 声明表字段列表
for (int tablevalueNum = 0; tablevalueNum < singleTableValueList.length; tablevalueNum++) {
tablevalueList.add(singleTableValueList[tablevalueNum]);
}
// 拆分列
String[] singleList = allCol.split(",");
List<String> colList = new ArrayList<String>();// 声明列数列表
for (int colNum = 0; colNum < singleList.length; colNum++) {
colList.add(singleList[colNum]);
}
String SQL = null;
System.out.println(new java.io.File(filePath).getAbsolutePath());
try {
filePath=new java.io.File(filePath).getAbsolutePath();
Workbook workbook = Workbook.getWorkbook(new File(filePath));
Sheet sheet = workbook.getSheet(0);
int col = sheet.getColumns();
int row = sheet.getRows();
String result[][] = new String[col][row];
Cell cell;
// i列 j行
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
try {
cell = sheet.getCell(i, j);
result[i][j] = cell.getContents();
} catch (Exception e) {
e.printStackTrace();
}}}
} 展开
private String filePath;
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public ActionForward ImpDataBaseFromExcel(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException {
String filePath = new String(request.getParameter("path").getBytes("8859_1"), "gb2312");
String tablename = new String(request.getParameter("tablename").getBytes("8859_1"), "gb2312");
String tablevalue = new String(request.getParameter("tablevalue").getBytes("8859_1"), "gb2312");
String allCol = new String(request.getParameter("col").getBytes("8859_1"), "gb2312");
String user = new String(request.getParameter("user").getBytes("8859_1"), "gb2312");
String password = new String(request.getParameter("password").getBytes("8859_1"), "gb2312");
String databasename = new String(request.getParameter("databasename").getBytes("8859_1"),"gb2312");
String databaseaddress = new String(request.getParameter(
"databaseaddress").getBytes("8859_1"), "gb2312");
String url = "jdbc:oracle:thin:@" + databaseaddress + ":1521:"
+ databasename;
String id = null;
// 拆分表字段
String[] singleTableValueList = tablevalue.split(",");
List<String> tablevalueList = new ArrayList<String>();// 声明表字段列表
for (int tablevalueNum = 0; tablevalueNum < singleTableValueList.length; tablevalueNum++) {
tablevalueList.add(singleTableValueList[tablevalueNum]);
}
// 拆分列
String[] singleList = allCol.split(",");
List<String> colList = new ArrayList<String>();// 声明列数列表
for (int colNum = 0; colNum < singleList.length; colNum++) {
colList.add(singleList[colNum]);
}
String SQL = null;
System.out.println(new java.io.File(filePath).getAbsolutePath());
try {
filePath=new java.io.File(filePath).getAbsolutePath();
Workbook workbook = Workbook.getWorkbook(new File(filePath));
Sheet sheet = workbook.getSheet(0);
int col = sheet.getColumns();
int row = sheet.getRows();
String result[][] = new String[col][row];
Cell cell;
// i列 j行
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
try {
cell = sheet.getCell(i, j);
result[i][j] = cell.getContents();
} catch (Exception e) {
e.printStackTrace();
}}}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询