You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Sean Stephens <ss...@apprev.com> on 2012/07/20 20:22:59 UTC

Re: Tabs on workbook with hidden sheets

I am having the same issue as the post below with both 3.7 and the 
latest 3.8.  If I don't set the first sheet hidden then the issue goes away.

Office/Mac opens the sheet fine, but Win/2007 has erratic sheet tab 
behavior after opening.

I've tried all combinations of setting the active and hiding, For 
example, setting the active before setting the hidden to make sure the 
active is the visible sheet before hiding the other sheet.



**************************

Hi all,

If I run the following code:

	Workbook wb = new XSSFWorkbook();
	wb.createSheet("Invisible sheet");
	wb.createSheet("Sheet 1");
	wb.createSheet("Sheet 2");
	
	wb.setSheetHidden(0, true);
	wb.setActiveSheet(1);

...and then open the resulting workbook in Excel (2007), I notice that the sheet tabs don't
work correctly. Only two tabs ("Sheet 1", "Sheet 2") are visible, but clicks are detected
as if the "Invisible sheet" tab was present as well.

Should I create a bug for this issue? Does anybody know of any possible work-arounds?

Thanks,

Alex Panayotopoulos, Software Engineer
ViaTelemetry Limited


Enabling technology for the Brulines Group plc

Buchan House  Carnegie Campus  Dunfermline  KY11 8PL  UK
Office: +44 (0) 1383 748000    Telephone: +44 (0) 1383 748097
Website: www.viatelemetry.com

If you wish to view Brulines Group email disclaimer please click here




Re: Tabs on workbook with hidden sheets

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Sorry to not reply before today but with the recent rains everything has been
growing like topsy and we have been very busy keeping paths open. Anayway,
that aside, can I ask you to try this code please?

import java.io.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;

/**
 *
 * @author Mark Beardsley
 */
public class HidingTest {
    
    public HidingTest(String filename) throws IOException {
        File file = null;
        FileOutputStream fos = null;
        XSSFWorkbook workbook = null;
        XSSFSheet sheet = null;
        try {
            workbook = new XSSFWorkbook();
            sheet = workbook.createSheet();
            this.populateSheet(sheet);
            workbook.setSheetHidden(0, 2);
 
            sheet = workbook.createSheet();
            this.populateSheet(sheet);
            
            sheet = workbook.createSheet();
            this.populateSheet(sheet);
            
            file = new File(filename);
            fos = new FileOutputStream(file);
            workbook.write(fos);
        }
        finally {
            if(fos != null) {
                fos.close();
            }
        }
    }
    
    private void populateSheet(Sheet sheet) {
        Row row = sheet.createRow(0);
        Cell cell = null;
        for(int i = 0; i < 5; i++) {
            cell = row.createCell(i);
            cell.setCellValue(i + 1);
        }
    }
    
}

It is far from being a complete replacement for your code as it does not
select sheets nor make tabs active, but it ought to hide the sheet
successfully for you. If it does work, the key is in this line of code;

workbook.setSheetHidden(0, 2);

which replaces the setSheetHidden(int, boolean) method call. From looking at
the source for the Workbook class, it would appear that there are three
possible setting for the sheets visibility, visible, hidden or very hidden.
Passing the int value 2 as the argument to the second parameter of the
overloaded setSheetHidden(int, int) method, makes the sheet very hidden and
I think this might be the solution to your problem.

Yours

Mark B



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Re-Tabs-on-workbook-with-hidden-sheets-tp5710502p5710522.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org