问题描述
- 小白求帮助 jxl实现excel的修改
-
实现一个方法,判断表1中 A列第一行的值是否为X,若是则将B列同行的值赋值到表2中C列第一行
依次往下循环
下面是我的思路,求大神帮忙看看如何实现
package com.excelchange;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;public class ExcelChange {
//workbook=sheet[];sheet=cell[][];
Workbook wb=null;
Sheet sheet=null;public Sheet input(String sourcepath,int page) throws BiffException, FileNotFoundException, IOException{ //读取excel到workbook类对象;page=0是第一页 Workbook wb=Workbook.getWorkbook(new FileInputStream(sourcepath)); Sheet st=wb.getSheet(page); return sheet; } public void output(String targetpath,int page,int type) throws BiffException, FileNotFoundException, IOException{ Workbook wb=Workbook.getWorkbook(new FileInputStream(targetpath)); Sheet st=wb.getSheet(page); //输出excel //case switch(type) { case 1: wb.setCell(st,x,y); break; /* case 2:语句2; default:语句; */ } wb.write(); wb.close(); } public int type(Sheet sheet){ //判断表格类型 int type=0; String c=getCell(sheet,2,3,0); //用case判断 switch(c) { case "3602013619200130631":type=1; break; case "123": type =2; break; } return type; } public String getCell(Sheet sheet,int x,int y,int page){ //获取指定单元格内容 Sheet st=wb.getSheet(page); //获取第一个sheet WritableCell cell =((WritableSheet) sheet).getWritableCell(x, y);//获取第一个单元格 String a=cell.toString(); return a; } public void setCell(Sheet sheet,int x,int y){ //设置指定单元格内容 Sheet st=wb.getSheet(0); WritableSheet sheet1 = (WritableSheet) wb.getSheet(0); WritableCell cell1 = sheet1.getWritableCell(x,y); Label l = (Label) cell1; l.setString(getCell(st,x,y,0)); }
}
解决方案
解决方案二:
http://blog.csdn.net/wugouzi/article/details/12951381
时间: 2024-10-15 05:39:23