读写excel

03版本

List<String> list = new ArrayList<String>();
		FileInputStream input = null;
		HSSFWorkbook wb = null;

		try {
			input = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			wb = new HSSFWorkbook(input);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HSSFSheet sheet = wb.getSheetAt(0);
		int sheetRs = sheet.getPhysicalNumberOfRows();
		int sheetCl = 0;
		if (sheetRs > 0 && sheet.getRow(0) != null) {
			sheetCl = sheet.getRow(0).getPhysicalNumberOfCells();
		}
		for (int i = 0; i < sheetRs; i++) {
			Row row = sheet.getRow(i);
			for (int j = 0; j < sheetCl; j++) {
				if (j == 11) {
					if(row.getCell(j) == null){
						System.out.println();
					}else{
					String su = row.getCell(j).toString().split("\\.")[0];
					
					}
				}
			}
		}

		return null;
	}



07版本

List<String> list = new ArrayList<String>();
		FileInputStream input = null;
		HSSFWorkbook wb = null;

		try {
			input = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			wb = new HSSFWorkbook(input);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HSSFSheet sheet = wb.getSheetAt(0);
		int sheetRs = sheet.getPhysicalNumberOfRows();
		int sheetCl = 0;
		if (sheetRs > 0 && sheet.getRow(0) != null) {
			sheetCl = sheet.getRow(0).getPhysicalNumberOfCells();
		}
		for (int i = 0; i < sheetRs; i++) {
			Row row = sheet.getRow(i);
			for (int j = 0; j < sheetCl; j++) {
				if (j == 11) {
					if(row.getCell(j) == null){
						System.out.println();
					}else{
					String su = row.getCell(j).toString().split("\\.")[0];
					
					}
				}
			}
		}

		return null;
	}



写到excel
package com.emsdatachange;

import java.io.File;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class WriteToExcel {
	public static void main(String args[])
	{
	try
	{
	//打开文件
	WritableWorkbook book=
	Workbook.createWorkbook(new File("测试.xls"));
	//生成名为“第一页”的工作表,参数0表示这是第一页
	WritableSheet sheet=book.createSheet("第一页",0);
	//在Label对象的构造子中指名单元格位置是第一列第一行(0,0)
	//以及单元格内容为test
	Label label=new Label(0,0,"时间段");
	Label label1=new Label(1,0,"订单量");
	//将定义好的单元格添加到工作表中
	sheet.addCell(label);
	sheet.addCell(label1);
	/*生成一个保存数字的单元格
	必须使用Number的完整包路径,否则有语法歧义
	单元格位置是第二列,第一行,值为789.123*/
	jxl.write.Number number = new jxl.write.Number(0,1,789.123);
	jxl.write.Number number1 = new jxl.write.Number(1,1,1011);
	
	sheet.addCell(number);
	sheet.addCell(number1);
	sheet.addCell(new Label(0, 2, "测试呵呵"));
	sheet.addCell(new Label(1, 2, "测试哈哈"));
	//写入数据并关闭文件
	book.write();
	book.close();
	}catch(Exception e)
	{
	System.out.println(e);
	}
	}
}

你可能感兴趣的:(Excel)