Hi, Unfortunately there are a number of "known" bugs around shifting data, you likely hit one of those, especially https://bz.apache.org/bugzilla/show_bug.cgi?id=57423 sounds related.
A list of related issues around shifting is: https://bz.apache.org/bugzilla/buglist.cgi?bug_id=59306%2C59239%2C58348%2C58221%2C57885%2C57423%2C56454%2C56123%2C55814%2C55714%2C54533%2C54509%2C54470%2C54399%2C53832%2C53678%2C53320%2C49319%2C46742%2C46266&list_id=146714&order=bug_id%20DESC&query_based_on=&query_format=advanced Naturally we gladly accept patches for any of those! Thanks... Dominik. On Sun, May 29, 2016 at 2:45 PM, Alex Broytman <alex.broyt...@instinet.com> wrote: > Hi, I am using poi v 3.14. My program reads a spreadsheet (which has just > two cells filled for the sake of this simple test) , fills rows and then > needs to swap rows. It works fine when template is in "xls" format and so > is the output. However, when template is saved as "xlsx", then resulting > xlsx file turns out to be corrupted - Excel displays a message about > unreadable contents, suggests, to recover and finally removes something > from the spreadsheet. Any suggestions ? Thanks > > My simple test program that reproduces the problem is below. > > import java.io.FileInputStream; > import java.io.FileOutputStream; > > import org.apache.poi.ss.usermodel.WorkbookFactory; > import org.apache.poi.ss.usermodel.Workbook; > import org.apache.poi.ss.usermodel.Cell; > import org.apache.poi.ss.usermodel.CreationHelper; > import org.apache.poi.ss.usermodel.Sheet; > import org.apache.poi.ss.usermodel.Row; > > > public class OpenTemplate { > > public static void main(String[] args) { > > Workbook wb; > int indexRow = 10; > int indexColumn = 3; > > try{ > FileInputStream f = new FileInputStream > ("/tmp/template.xlsx"); > wb = WorkbookFactory.create(f); > CreationHelper createHelper = wb.getCreationHelper > (); > Sheet sheet = wb.getSheetAt(0); > Row row = sheet.createRow(indexRow); > Cell cell = row.createCell(indexColumn); > cell.setCellValue(createHelper.createRichTextString > ("FIRST")); > int newPosition = indexRow; > row = sheet.createRow(++indexRow); > cell = row.createCell(indexColumn); > cell.setCellValue(createHelper.createRichTextString > ("SECOND")); > int currentRow = indexRow; > sheet.shiftRows(newPosition, currentRow, 1); > sheet.shiftRows(currentRow + 1, currentRow + 1, > newPosition - currentRow - 1); > > > FileOutputStream out = new FileOutputStream > ("/tmp/spreadsheet.xlsx"); > wb.write(out); > out.close(); > > } > catch (Exception e) { > System.out.println("Exception: " + e.getMessage()); > e.printStackTrace(); > } > } > } > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@poi.apache.org > For additional commands, e-mail: user-h...@poi.apache.org > >