📄 readsheet10.java
字号:
package excel.read;
import java.io.FileInputStream;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import com.mysql.Domysql;
/**
* @author 凯凯sdwp
*/
public class ReadSheet10
{
public void find(String path,int sheet)
{
try {
InputStream is = new FileInputStream(path);//写入到FileInputStream
Workbook wb = Workbook.getWorkbook(is); //得到工作薄
Sheet st = wb.getSheet(sheet);//得到要导入的工作表
int rsRows = st.getRows(); //得到excel的总行数
for(int i = 0;i<rsRows;i++)
{
Cell cell1 = st.getCell(0,i);//获得第一列的值
String str1 = sheet-1+"_"+cell1.getRow();
int rsRow = cell1.getRow();
String str2 = cell1.getContents();
find(path,str1,sheet,rsRow);//调用find()方法
}
} catch (Exception e) {
System.out.println(e+"333333333");
// TODO: handle exception
}
}
/**
* 读取管理表中的数据
* 参数path 得到excel文件的路径
* 参数str1 得到传过来的行数
* 参数str2 得到传过来的列的内容
*/
public void find(String path ,String str1,int sheet,int Row)
{
try {
InputStream is = new FileInputStream(path);//写入到FileInputStream
Workbook wb = Workbook.getWorkbook(is); //得到工作薄
Sheet st = wb.getSheet(0);//得到工作薄中的第一个工作表
int rsRows = st.getRows(); //得到excel的总行数
for(int j = 0;j<rsRows;j++)
{
Cell cell1 = st.getCell(3,j);//获得第四列的值
Cell cell2 = st.getCell(0,j);//获得第一列的值
Cell cell3 = st.getCell(4,j);//获得第四列的值
if(cell1.getContents().trim().toString()!="" && cell3.getContents().trim().toString()!="")
{
int m =Integer.parseInt(str1.substring(str1.indexOf("_")+1));
if(cell1.getContents().equals(str1) && m > 22)
{
getDate1(path,sheet,Row,1,cell2.getContents().trim());//获取第2列的数据
getDate1(path,sheet,Row,2,cell2.getContents().trim());//获取第3列的数据
}
// || cell3.getContents().equals(str1)
if(cell1.getContents().equals(str1) && m < 20)
{
getDate(path,sheet,Row,1,cell2.getContents().trim());//获取第2列的数据
getDate(path,sheet,Row,2,cell2.getContents().trim());//获取第3列的数据
}
if(cell3.getContents().equals(str1) && m < 20)
{
getDate2(path,sheet,Row,1,cell2.getContents().trim());//获取第2列的数据
getDate2(path,sheet,Row,2,cell2.getContents().trim());//获取第3列的数据
}
}
}
wb.close();//关闭工作薄
is.close();//关闭输入流
}
catch (Exception e) {
System.out.println(e+"22222222222");
}
}
/**
* 得到数据方法
* 参数sheet 第几个工作表
* 参数rsCol 第几列
* 参数rsRow 第几行
*/
public void getDate(String path,int sheet,int rsCol,int rsRow,String Row)
{
try {
InputStream is = new FileInputStream(path);//写入到FileInputStream
Workbook wb = Workbook.getWorkbook(is); //得到工作薄
int num = wb.getNumberOfSheets();//得到工作表的数量
String[] name = wb.getSheetNames();//读取工作表的名称
Sheet st = wb.getSheet(sheet);//得到要导入的工作表
Cell cell1 = st.getCell(rsRow,rsCol-1);//获得第四列的值
String str1 = cell1.getContents();//获去列的数据
Domysql d=new Domysql();
String a="_A";
String b="_C";
if(rsRow == 1)
{
//System.out.println("绝对量 "+str1+" 所在的行为 "+Row+" _A");
if(Row!=null&&Row!=""&&str1!=null&&str1!="")
d.insert(str1,Row, a);
}
if(rsRow == 2)
{
//System.out.println("增长速度 "+str1+" 所在的行为 "+Row+" _C");
if(Row!=null&&Row!=""&&str1!=null&&str1!="")
d.insert(str1,Row, b);
}
wb.close();//关闭工作薄
is.close();//关闭输入流
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
public void getDate1(String path,int sheet,int rsCol,int rsRow,String Row)
{
try {
InputStream is = new FileInputStream(path);//写入到FileInputStream
Workbook wb = Workbook.getWorkbook(is); //得到工作薄
int num = wb.getNumberOfSheets();//得到工作表的数量
String[] name = wb.getSheetNames();//读取工作表的名称
Sheet st = wb.getSheet(sheet);//得到要导入的工作表
Cell cell1 = st.getCell(rsRow,rsCol-1);//获得第四列的值
String str1 = cell1.getContents();//获去列的数据
Domysql d=new Domysql();
String a="_C";
String b="_D";
if(rsRow == 1)
{
//System.out.println("单独的5 "+str1+" 所在的行为 "+Row+" _C");
if(Row!=null&&Row!=""&&str1!=null&&str1!="")
d.insert(str1,Row, a);
}
if(rsRow == 2)
{
//System.out.println("增长速度 "+str1+" 所在的行为 "+Row+" _D");
if(Row!=null&&Row!=""&&str1!=null&&str1!="")
d.insert(str1,Row, b);
}
wb.close();//关闭工作薄
is.close();//关闭输入流
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
public void getDate2(String path,int sheet,int rsCol,int rsRow,String Row)
{
try {
InputStream is = new FileInputStream(path);//写入到FileInputStream
Workbook wb = Workbook.getWorkbook(is); //得到工作薄
int num = wb.getNumberOfSheets();//得到工作表的数量
String[] name = wb.getSheetNames();//读取工作表的名称
Sheet st = wb.getSheet(sheet);//得到要导入的工作表
Cell cell1 = st.getCell(rsRow,rsCol-1);//获得第四列的值
String str1 = cell1.getContents();//获去列的数据
Domysql d=new Domysql();
String a="_B";
String b="_D";
if(rsRow == 1)
{
//System.out.println("单独的5 "+str1+" 所在的行为 "+Row+" _B");
if(Row!=null&&Row!=""&&str1!=null&&str1!="")
d.insert(str1,Row, a);
}
if(rsRow == 2)
{
//System.out.println("增长速度 "+str1+" 所在的行为 "+Row+" _D");
if(Row!=null&&Row!=""&&str1!=null&&str1!="")
d.insert(str1,Row, b);
}
wb.close();//关闭工作薄
is.close();//关闭输入流
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -