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

📄 fromexcel.java

📁 java编写的database录入软件 支持exl格式
💻 JAVA
字号:
package input;
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.Vector;

import jxl.Cell; 
import jxl.CellType;
import jxl.LabelCell;
import jxl.Sheet; 
import jxl.Workbook; 
import jxl.read.biff.BiffException; 



public class Fromexcel 
{ 
	private String path;
	private String name;
	private String stringtemp;
	private int row;
	private int col;
	private String inttemp;
	private Vector <Vector> list = new Vector<Vector>();
	private StringBuffer creat = new StringBuffer();
	private Vector<String> element = new Vector<String>();
	private String creatstring;
	private Cell temp;
	private String datetemp;
	
	public Fromexcel()
	{
		
	}
	public Vector<String> getElement()
	{
		return this.element;
	}
	public Vector<Vector> getData()
	{
		return this.list;
	}
	public String getCreat()
	{
		return this.creatstring;
	}
	public int getrow()
	{
		return this.row;
	}
	public int getcol()
	{
		return this.col;
	}
	public void setPath(String path)
	{
		this.path = path;
	}
	public String getPath()
	{
		return this.path;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public String getName()
	{
		return this.name;
	}
	@SuppressWarnings({ "unchecked"})
	public void input()
	{
		try 
		{ 
			InputStream is = new FileInputStream(path); 
			Workbook wb = Workbook.getWorkbook(is); 
			Sheet st = wb.getSheet(0); 
			row = st.getRows();
			col = st.getColumns();

// System.out.println("读取表格内容:"); 
			creat.append("creat table ");
			creat.append(name);
			creat.append("(");
			for (int j = 0; j < row; j++) 
			{
				creat.append(st.getCell(j,0).toString());
				element.add(st.getCell(j,0).toString());
				creat.append("  ");
				temp = st.getCell(j,1); 
				if(temp.getType()==CellType.LABEL) 
				{ 
					Vector <String> templist = new Vector<String>();
					list.add(templist);
					creat.append("char(20),");
				} 
				if(temp.getType()==CellType.NUMBER) 
				{ 
					Vector<String> templist = new Vector<String>();
					list.add(templist);
					creat.append("int,");
				} 
				if(temp.getType()==CellType.DATE) 
				{ 
					Vector<String> templist = new Vector<String>();
				    list.add(templist); 
				    creat.append("date,");
				} 
			}
			creat.append(")");
			creatstring = creat.toString(); 
			for (int j = 0; j < row; j++) 
			{ 
				for (int i = 1; i < col; i++) 
				{ 
					temp = st.getCell(j,i); 
					if(temp.getType() == CellType.LABEL) 
					{ 
						LabelCell label=(LabelCell) temp; 
						stringtemp = label.getString();
						stringtemp = "'"+stringtemp+"'";
					    list.get(j).add(stringtemp);
					} 
					if(temp.getType() == CellType.NUMBER) 
					{
						inttemp = temp.getContents();
						list.get(j).add(inttemp);
					} 
					if(temp.getType() == CellType.DATE) 
					{ 
						datetemp = temp.getContents();
						datetemp = "'"+datetemp+"'";
						list.get(j).add(datetemp);
					} 
				}
			}
		}
		catch (FileNotFoundException e) 
		{ 
			e.printStackTrace(); 
		} 
		catch (BiffException e) 
		{ 
			e.printStackTrace(); 
		} 
		catch (IOException e) 
		{ 
			e.printStackTrace(); 
		} 
	}
}

⌨️ 快捷键说明

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