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

📄 operatorfile.java

📁 这是本人曾经在公司里用的,内部开发框架,基于struts+hibernate今天分享给大家
💻 JAVA
字号:
/**
 * 
 */
package cn.bway.common;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.util.StringTokenizer;
import java.util.Vector;

import org.hibernate.Session;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;


/**
 * @author Kson
 *
 */
public class OperatorFile {
	
	ExcelMaker excelMake = new ExcelMaker();
	//operator EXL format file
	public String getOperatorExcelErr(String filePath,Connection conn,Session sess){
		System.out.println(" the filePath == "+filePath);
		String fileErr = "1";
		try{
			//构建Workbook对象, 只读Workbook对象
			//直接从本地文件创建Workbook
			//从输入流创建Workbook
			//String filepath="D:\\excelTable\\CMB20051316.xls";
		    InputStream is = new FileInputStream(filePath);
		    jxl.Workbook rwb = Workbook.getWorkbook(is);
		    
		    //获得工作薄(Workbook)中工作表(Sheet)的个数
		    int sheets = rwb.getNumberOfSheets();
		    System.out.println(" 工作表中的个数 == "+sheets);
		    
		    //获取Sheet的名称
		    jxl.Sheet rs1 = rwb.getSheet(0);
		    String sheetName = rs1.getName();
		    System.out.println(" sheet 的名称 == "+sheetName);
		    
		    //获取第一张Sheet表
		    Sheet rs = rwb.getSheet(0);
		    
		    //总列数
		    int rsColumns = rs.getColumns();
		    System.out.println(" rsColumns 总列数为: "+rsColumns);
		    
		    //总行数
		    int rsRows = rs.getRows();
		    System.out.println("  rsRows 总行数: "+rsRows);
		    
		    Vector vector = null;
		    int count = 0;
		    while(rsRows>count){
		    	
		    	vector = new Vector();
		    	Cell[] cell = rs.getRow(count);
//		    	int i = 0;
		    	int i=2;
	    		String[] d = new String[rsColumns];
	    		String value = new String("");
	    		
	    		while (rsColumns>i){
	    			Cell c = rs.getCell(i,count);
		    		d[i] = c.getContents();		    		
		    		System.out.println(" aaa = "+d[i]);
		    		value += d[i] + "|";
		    		i++;
	    		}
	    		value = value.substring(0,value.length()-1);
	    		System.out.println(" the excel str == "+value);
		    	//vector.add(value);
	    		System.out.println(" the save into the excel == "+vector);
	    		System.out.println("=======================");
	    		excelMake.operatorExcel(value,conn,sess);
		    	count++;
		    }
		    rwb.close();
		    is.close();
		}catch(Exception e){
			e.printStackTrace();
			fileErr="Kson operator error";
		}
		return fileErr;
	}
	
	//operator txt format file
	public void readTxt(String filePath){
		System.out.println(" operator the file path == "+filePath);
		try {
			FileInputStream file = new FileInputStream(filePath);
			BufferedReader buffer = new BufferedReader(new InputStreamReader(file));
			String fileList = null;			
			while((fileList=buffer.readLine())!=null){
				StringTokenizer str = new StringTokenizer(fileList," ");
				int i = 0;
				String tmpStr = "";
				while(str.hasMoreTokens()){
					tmpStr += str.nextToken()+"|";
					i++;
				}
				tmpStr = tmpStr.substring(0,tmpStr.length()-1);
				System.out.println(tmpStr);
				System.out.println("=====================================");
				//excelMake.operatorExcel(tmpStr);
			}
			buffer.close();
			file.close();
		}
		catch(FileNotFoundException e){
			e.printStackTrace();
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	
}

⌨️ 快捷键说明

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