2016-05-12 1 views
-1

Ich muss zwei Blätter zu einem zusammenführen.Java - Merge zwei Excel-Blätter in einem

Eg. Ich habe Excel-Datei test.xls mit zwei Blättern, Blatt0 und Blatt1. Beide Blätter haben etwas Text und Tabelle.

Ich möchte sie so fusionierte Blatt fusionieren würde wie folgt aussehen:

  • Text von sheet0
  • Tabelle von sheet0
  • Text von sheet1
  • Tabelle von sheet1

Ich muss dies in Java tun.

Gibt es eine einfache Möglichkeit, dies zu tun? Etwas wie:

HSSFWorkbook book = new HSSFWorkbook("/tmp/test.xls"); 
HSSFSheet sheet0 = book.getSheetAt(0); 
HSSFSheet sheet1 = book.getSheetAt(1); 
sheet0.merge(sheet1); //or combine or something 

Antwort

1

nicht ein solches Verfahren in Poi API

Ansonsten gefunden haben, können Sie manuell den Inhalt sheet1 in sheet0 wie anhängen:

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 
}