繁体   English   中英

读取和写入相同的Excel文件

[英]Read and write to the same Excel file

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文件。

我要从一个文件中取出两个字符串,然后放入另一个文件中。

如何将内容放入同一文件?

我正在创建一个新文件,然后放入内容。 如何读取和写入相同的文本文件? 如何克服这个问题?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM