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.
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.
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();
}
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.