Hidden chart is not detected

I have an Excel hiddenChart.xlsx containing a hidden chart. I tried to unhide it using the following code:

        worksheet.getShapes().forEach(s -> {
          Shape shape = (Shape) s;
          if (shape.getMsoDrawingType() == MsoDrawingType.CHART) {
          if (shape.isHidden()) {
            shape.setHidden(false); // for hiddenChart.xlsx this line is never executed
          }
        }});

Saving the hiddenChart as an PDF afterwrad the hidden chart is not visible.
As a workaround I realized that “worksheet.setVisible(true);” makes the hidden chart visible. But is that really expected and why does “shape.isHidden()” deliver false for the hidden chart.

@Tim49,

I think you may try to use chart.getChartObject().isHidden() to detect if a chart is hidden. Could you please zip and attach the Excel file containing the hidden chart. We will check your issue soon.

Hi,
attached a zip containing the hiddenCharts.zip and a Java example to reproduce the issue.
HiddenCharts.zip (10,5 KB)

Hi,

does not detect the hidden chart, too

@Tim49
Please try the following sample code:

Workbook wb = new Workbook(filePath + "hiddenChart.xlsx");

WorksheetCollection sheets = wb.getWorksheets();
int sheetCount = sheets.getCount();
int chartSheetHiddenCount = 0;
for (int i = 0; i < sheetCount;i++)
{ 
	Worksheet sheet = sheets.get(i);
	if (sheet.getType() == SheetType.CHART && !sheet.isVisible())
	{
		chartSheetHiddenCount++;
	}
	ShapeCollection shapes = sheet.getShapes();
	int shapeCount = shapes.getCount();
	int shapeHidenCount = 0;
	for (int s = 0; s < shapeCount;s++)
	{
		Shape shape = shapes.get(s);
		if (shape.isHidden())
		{
			shapeHidenCount++;
		}
	}
	
	ChartCollection charts = sheet.getCharts();
	int chartCount = charts.getCount();
	int chartHidenCount = 0;
	for (int c = 0; c < chartCount;c++)
	{
		Chart chart = charts.get(c);
		if (chart.getChartObject().isHidden())
		{
			chartHidenCount++;
		}
	}
	
	
	System.out.println(sheet.getName() + "  shape hidden count: " + shapeHidenCount);
	System.out.println(sheet.getName() + "  chart hidden count: " + chartHidenCount);
}


System.out.println("hidden chart sheet: " + chartSheetHiddenCount);

The output result:

Chart1  shape hidden count: 0
Chart1  chart hidden count: 0
Chart2  shape hidden count: 0
Chart2  chart hidden count: 0
hidden chart sheet: 1

Hope helps a bit.

@Tim49,

Thanks for the sample file.

You are doing wrong. I checked your template file and found there are two worksheets of type “Chart”, one Chart type sheet is visible and other is hidden. Please note, the chart pasted on the hidden (Chart type) sheet is not hidden. The charts are not pasted on normal sheets, so you have to evaluate sheet types to evaluate if it is chart sheet and visible or not. See the simplest example code for the purpose.

                Workbook workbook = new Workbook("d:\\files\\hiddenChart.xlsx");

                try {

                    // Loop through all worksheets in the workbook
                    for (int i = 0; i < workbook.getWorksheets().getCount(); i++) {
                        Worksheet worksheet = workbook.getWorksheets().get(i);

                        // Check if the worksheet is a Chart Sheet
                        if (worksheet.getType() == SheetType.CHART) {
                            // Check if the Chart Sheet is visible
                            if (worksheet.isVisible()) {
                                System.out.println("Chart Sheet '" + worksheet.getName() + "' is visible.");
                            } else {
                                System.out.println("Chart Sheet '" + worksheet.getName() + "' is hidden.");
                            }
                        } else {
                            System.out.println("Worksheet '" + worksheet.getName() + "' is not a Chart Sheet.");
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

Hope, this helps a bit.

Hi John.He and amajd.sahi,

I did not know the

[quote=“amjad.sahi, post:6, topic:295325”]
SheetType.CHART
[/quote].
So thanks a lot. This was very helpfull.

@Tim49,

You’re welcome! I’m glad to hear that you understand it and that the suggested code segments resolved your issue.