-2

Groovy/POI で test1.xls の先頭に空白行全体を挿入するにはどうすればよいですか? 私はプロジェクトの完成にとても近づいており、これがパズルの最後のピースです. よろしくお願いいたします。

@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 )
    }
  }
}
4

1 に答える 1

5

以下を使用できます。

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

これにより、シートの 0 から最後の行までのすべての行が 1 行下にシフトされます。

于 2013-07-10T19:21:06.433 に答える