I'm having issue using the apache poi for excel 2007 utilizing the XSSF
I have two code snippets below (fat-fingered). The first seems to work, as the workbook opens correctly in excel 2007, and there is some change.
If I run the second code snippet then open in excel 2007, I get an error about unreadable content. I have to click a confirmation box, then excel opens my file.
Why is the second code snippet causing this error? the only difference is in the second one I am trying to shift all rows from row 2(zero indexed) up two rows...
All i really want to do is remove some header rows, and after I get that down some footer rows from a file. I'm not doing anything fancy. I'm guessing I'm misunderstanding the API, but I've been fighting with this for a while now.
Any ideas? Also should I be shifting the rows, or removing them, or some combination of both?
String filename = "C:\\file.xlsx";
FileInputStream file = new FileInputStream( new File(fileName) );
XSSFWorkbook wb = new XSSFWorkbook(file);
XSSFSheet sheet = wb.getSheetAt(0);
int lastRow = sheet.getlastRow();
sheet.shiftRows(1, lastRow, -1);
file.close()
FileOutputStream out = new FileOutputStream(fileName);
wb.write(out);
out.flush();
out.close();
String filename = "C:\\file.xlsx";
FileInputStream file = new FileInputStream( new File(fileName) );
XSSFWorkbook wb = new XSSFWorkbook(file);
XSSFSheet sheet = wb.getSheetAt(0);
int lastRow = sheet.getlastRow();
sheet.shiftRows(2, lastRow, -2);
file.close()
FileOutputStream out = new FileOutputStream(fileName);
wb.write(out);
out.flush();
out.close();
Edit: Actually it apears that the first snippet is also causing an issue...sometimes???? I'm under the impression I am doing something wrong... Any suggestions?
sheet.shiftRows(2, lastRow, -2);
. – Lion