⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readsheetbydisa.java

📁 是mysql数据库数据导入程序是从excel中提取数据导入到mysql数据库中
💻 JAVA
字号:
package excel.read;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import com.mysql.*;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

/**
 * ReadSheetByDisa.java
 * @author 凯凯sdwp
 * 主要是读取不同的工作表
 */
public class ReadSheetByDisa {

	/**
	 * 读取不相同的Sheet方法
	 */	
	public void readSheetByDisa(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++)
			{
				String str1 = sheet-1+"_"+i;
				find(path,str1,sheet,i);//调用find()方法
			}
			
		} catch (Exception e){
			e.printStackTrace();
		}
	}

	/**
	 * 
	 * @param path
	 * @param str1
	 * @param sheet
	 * @param Row
	 */
	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(cell3.getContents().trim().toString()!="")
				{
					if(cell1.getContents().equals(str1))
					{
						//a.substring(a.indexOf("_")+1)
						int m =Integer.parseInt(cell1.getContents().substring(cell1.getContents().indexOf("_")+1));
						int n =Integer.parseInt(cell3.getContents().substring(cell3.getContents().indexOf("_")+1));
						getDate(path,sheet,m,1,cell2.getContents().trim(),"绝对量");//获取第2列的数据
						getDate(path,sheet,n,1,cell2.getContents().trim(),"增长速度");//获取第2列的数据
					}
					if(cell3.getContents().equals(str1))
					{
						int m =Integer.parseInt(cell1.getContents().substring(cell1.getContents().indexOf("_")+1));
						int n =Integer.parseInt(cell3.getContents().substring(cell3.getContents().indexOf("_")+1));
						getDate(path,sheet,m,2,cell2.getContents().trim(),"绝对量");//获取第3列的数据
						getDate(path,sheet,n,2,cell2.getContents().trim(),"增长速度");//获取第3列的数据
					}
				}
			}
			wb.close();//关闭工作薄
			is.close();//关闭输入流
		}
		catch (Exception e) {
			System.out.println(e+"22222222222");
		}
	}
	/**
	 * 找与管理表相匹配的指标
	 * @param path
	 * @param sheet
	 * @param rsCol
	 * @param rsRow
	 * @param Row
	 */
	public void getDate(String path,int sheet,int rsCol,int rsRow,String Row,String type)
	{
		try {
			
			InputStream is = new FileInputStream(path);//写入到FileInputStream
			Workbook wb = Workbook.getWorkbook(is); //得到工作薄
			Sheet st = wb.getSheet(sheet);//得到要导入的工作表

			Cell cell1 = st.getCell(rsRow,rsCol-1);//获得第四列的值
			String str1 = cell1.getContents();//获去列的数据
			//System.out.println(type+"  "+str1+"  所在的行为  "+Row+" ddddd "+cell1.getContents());
			Domysql d=new Domysql();
			String a="_C";
			String b="_D";
			if(type.equals("绝对量")){
				if(Row!=null&&Row!=""&&str1!=null&&str1!="")
				d.insert(str1.trim(),Row, a);
			}
			if(type.equals("增长速度")){
				if(Row!=null&&Row!=""&&str1!=null&&str1!="")
				d.insert(str1.trim(),Row, b);
			}
			wb.close();//关闭工作薄
			is.close();//关闭输入流
			
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -