package jexcel.jxl.nimit;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.LabelCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class ExcelJxl {
public static void main(String[] args) throws WriteException, IOException, BiffException{
String S="D:\\nimit.xls";
ExcelJxl.WriteFile(S);
}
public static void WriteFile(String path) throws IOException, WriteException, BiffException{
Workbook wb=Workbook.getWorkbook(new File(path));
Sheet sheet=wb.getSheet(0);
String s1=null;
String s2=null;
Cell c1=sheet.getCell(0,0);
Cell c2=sheet.getCell(1,0);
if (c1.getType() == CellType.LABEL)
{
LabelCell lc = (LabelCell) c1;
s1 = lc.getString();
}
if (c2.getType() == CellType.LABEL)
{
LabelCell lb = (LabelCell) c2;
s2 = lb.getString();
}
String s3=s1+s2;
WritableWorkbook copy=Workbook.createWorkbook(new File("D:\\demo.xls"),wb);
WritableSheet Wsheet = copy.getSheet(0);
Label l1=new Label(0,0,s1);
Wsheet.addCell(l1);
Label l2=new Label(1,0,s2);
Wsheet.addCell(l2);
Label l3 = new Label(2, 0,s3);
Wsheet.addCell(l3);
copy.write();
copy.close();
}
}
我正在尝试学习如何读取和写入同一个 Excel 文件。
我从一个文件中取出两个字符串并放入另一个文件。
如何将内容放入同一个文件中?
我正在创建一个新文件,然后我正在放置内容。如何读取和写入同一个文本文件?如何克服这个问题?