开发者

shiftRows in apache poi not working

InputStream inp = new FileInputStream("workbook.xls");
HSSFWorkbook wb = new HSSFWor开发者_运维百科kbook(inp);

String text="";
Sheet sheet1 = wb.getSheetAt(0);

for (Row row : sheet1) {
    for (Cell cell : row) {
        // Do something here
        ExcelExtractor extractor = new ExcelExtractor(wb);
        text=extractor.getText();
        System.out.print("text="+text);
    }
}
sheet1.shiftRows(0,sheet1.getLastRowNum(),1);

I am not getting the result in my excel sheet after the shiftrows is called. the data stays the same. Where am I doing it wrong?


This is because you're workbook is only open for reading since it came from an inputstream

InputStream inp = new FileInputStream("workbook.xls");

To get the result you would have to write the new workbook object out to a new xsl spreadsheet. Something like...

File outWB = new File("workbook2.xls");
OutputStream out = new FileOutputStream(outWB);
wb.write(out);
out.flush();
out.close();

You could do this to the same file but you would need to inp.close() first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜