利用java向汇总表中粘贴多个excel文档,代码应该如何修改
packagejexcel;importjava.io.File;importjava.io.IOException;importjava.io.OutputStream...
package jexcel;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import jxl.Cell;
import jxl.JXLException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class test {
public static void main(String[] args) throws JXLException, IOException {
addtest();
}
private static void addtest() throws JXLException, IOException {
Workbook wb = Workbook.getWorkbook(new File("C:\\Users\\AYLX4B\\Desktop\\360\\汇总表.xls"));
Sheet st = wb.getSheet(0);
int lie = st.getColumns();
int hang = st.getRows();
Workbook wb1 = Workbook.getWorkbook(new File("C:\\Users\\AYLX4B\\Desktop\\360\\1.xls"));
Sheet st1 = wb1.getSheet(0);
int lie1 = st1.getColumns();
int hang1 = st1.getRows();
wb1.close();
WritableWorkbook wwb = Workbook.createWorkbook(new File("C:\\Users\\AYLX4B\\Desktop\\360\\1.xls"),wb);
WritableSheet sheet = wwb.getSheet(0);
for (int i = 0; i < hang; i++) {
for (int j = 0; j < lie; j++) {
Cell cell = st.getCell(j, i);
sheet.addCell(new Label(j,( hang1+i), cell.getContents()));
}
}
wwb.write();
wwb.close();
wb.close();
}
} 展开
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import jxl.Cell;
import jxl.JXLException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class test {
public static void main(String[] args) throws JXLException, IOException {
addtest();
}
private static void addtest() throws JXLException, IOException {
Workbook wb = Workbook.getWorkbook(new File("C:\\Users\\AYLX4B\\Desktop\\360\\汇总表.xls"));
Sheet st = wb.getSheet(0);
int lie = st.getColumns();
int hang = st.getRows();
Workbook wb1 = Workbook.getWorkbook(new File("C:\\Users\\AYLX4B\\Desktop\\360\\1.xls"));
Sheet st1 = wb1.getSheet(0);
int lie1 = st1.getColumns();
int hang1 = st1.getRows();
wb1.close();
WritableWorkbook wwb = Workbook.createWorkbook(new File("C:\\Users\\AYLX4B\\Desktop\\360\\1.xls"),wb);
WritableSheet sheet = wwb.getSheet(0);
for (int i = 0; i < hang; i++) {
for (int j = 0; j < lie; j++) {
Cell cell = st.getCell(j, i);
sheet.addCell(new Label(j,( hang1+i), cell.getContents()));
}
}
wwb.write();
wwb.close();
wb.close();
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询