簡體   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