Hello Mark,

I am already using Sheet.setActiveCell() but it doesn't help. The cell
becomes selected but it is not in view.

My use case is a bit different. I read an existing Excel document which is
a template for the Excel document I create. The source Excel sometimes has
sheets that are scrolled down a bit and I try to "tidy" that up up. I
therefore call the Sheet.setActiveCell() for every sheet and I then save
the Excel document to another file then the original file. Could this be a
problem? Everything else seems to work except the that the sheets are not
scrolled up to make the first cell visible.

I think the basic difference is that I do not create the sheets with POI -
I read existing sheets.

/Bengt




2015-09-26 12:47 GMT+02:00 Mark Beardsley <[email protected]>:

> Seems to work. I wrote and ran this to test the idea
>
> import java.io.*;
> import org.apache.poi.xssf.usermodel.*;
>
> public class ActiveCellTest {
>
>   public static void main(String[] args) {
>
>     File file = null;
>     FileOutputStream fos = null;
>     BufferedOutputStream bos = null;
>
>     XSSFWorkbook workbook = null;
>     XSSFSheet sheet = null;
>     XSSFRow row = null;
>     XSSFCell cell = null;
>
>     // Build a workbook with five sheets for testing
>     workbook = new XSSFWorkbook();
>     for(int i = 0; i < 5; i++) {
>       sheet = workbook.createSheet("Sheet Number " + i);
>       for(int j = 0; j < 30; j++) {
>         row = sheet.createRow(j);
>         for(int k = 0; k < 20; k++) {
>           cell = row.createCell(k);
>           cell.setCellValue("Row " + j + " Column " + k);
>         }
>       }
>     }
>
>     // Iterate through the sheets and make cell active
>     for(int i = 0; i < workbook.getNumberOfSheets(); i++) {
>       sheet = workbook.getSheetAt(i);
>       // Select diffeent cell in column A to show selection is working
>       sheet.setActiveCell("A" + (i + 1));
>     }
>
>     // Save book away - change path to suit on your system
>     try {
>       file = new
> File("/home/markb/Public/java/testdocs/ActiveCellTest.xlsx");
>       fos = new FileOutputStream(file);
>       bos = new BufferedOutputStream(fos);
>       workbook.write(bos);
>     }
>     catch(IOException ioEx) {
>       System.out.println("Catch of saving book away and caught an " +
> ioEx.getClass().getName());
>       System.out.println("Message " + ioEx.getMessage());
>       System.out.println("Stacktrace");
>       ioEx.printStackTrace(System.out);
>     }
>     finally {
>       try {
>         if(bos != null) {
>           bos.flush();
>           bos.close();
>         }
>       }
>       catch(IOException ioEx) {
>         System.out.println("Catch of finally clause and caught an " +
> ioEx.getClass().getName());
>         System.out.println("Message " + ioEx.getMessage());
>         System.out.println("Stacktrace");
>         ioEx.printStackTrace(System.out);
>       }
>     }
>   }
> }
>
> and all you need to do is set the active cell for each sheet in the
> workbook.
>
> Hope this helps.
>
>
>
> --
> View this message in context:
> http://apache-poi.1045710.n5.nabble.com/showInPane-does-not-work-tp5720321p5720353.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to