-2

How do I insert an entire blank row at the top of my test1.xls in Groovy/POI? I am so close to finishing my project and this is the last piece of the puzzle. Your help is greatly appreciated.

@Grab( 'org.apache.poi:poi:3.9' )
import static org.apache.poi.ss.usermodel.CellStyle.*
import static org.apache.poi.ss.usermodel.IndexedColors.*
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.apache.poi.hssf.usermodel.*
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.util.CellRangeAddress

// Open the spreadsheet
new File( 'C:\\test1.xls' ).withInputStream { ins ->
  new HSSFWorkbook( ins ).with { workbook ->
    getSheetAt( 0 ).with { sheet ->
      getRow( 0 ).getCell( 0 ).setCellValue( 'ID' )
      getRow( 0 ).getCell( 1 ).setCellValue( 'Start Date' )
      getRow( 0 ).getCell( 2 ).setCellValue( 'End Date' )
      getRow( 0 ).getCell( 3 ).setCellValue( 'Status' )
      getRow( 0 ).getCell( 4 ).setCellValue( 'Instrusive' )
      getRow( 0 ).getCell( 5 ).setCellValue( 'State(s) Impacted' )      
      getRow( 0 ).getCell( 6 ).setCellValue( 'Impacted' )      
    }
    new File( 'C:\\test2.xls' ).withOutputStream { os ->
      write( os )
    }
  }
}
Marco Polo
  • 267
  • 1
  • 5
  • 16
  • possible duplicate of [Scriptom Groovy formating Excel Examples](http://stackoverflow.com/questions/17573651/scriptom-groovy-formating-excel-examples) – tim_yates Jul 10 '13 at 19:48
  • Asking the same question again isn't going to endear you to the stackoverflow community – tim_yates Jul 10 '13 at 19:49

1 Answers1

5

You can use:

testSheet.shiftRows(0,testSheet.getLastRowNum(), 1);

This will shift all the rows from 0 to last row of the sheet by one row down.

Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74