[英]Java - merge two excel sheets into one
我需要將兩張紙合並為一張。
例如。 我有兩個工作表,sheet0和sheet1的excel文件test.xls。 兩張紙上都有一些文字和表格。
我想將它們合並,因此合並后的工作表將如下所示:
我需要在Java中執行此操作。
有沒有簡單的方法可以做到這一點? 就像是 :
HSSFWorkbook book = new HSSFWorkbook("/tmp/test.xls");
HSSFSheet sheet0 = book.getSheetAt(0);
HSSFSheet sheet1 = book.getSheetAt(1);
sheet0.merge(sheet1); //or combine or something
在Poi API中找不到這種方法
否則,您可以手動將sheet1的內容附加到sheet0中,例如:
int lastRowNum1 = sheet1.getLastRowNum();
int i=0;
int currentLinePos=sheet0.getLastRowNum();
while ( i <= lastRowNum1 ){
Row currentRow = sheet1.getRow(i++);
Row copiedRow = sheet0.createRow(currentLinePos++);
// code that copy the content of currentRow into copiedRow
// such as copying every cells
// or try copiedRow = currentRow; but not sure it will copy the cells
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.