Created attachment 38565 [details] xlsm file containing a empty macrosheet that reproduces the problem In XSSFWorkbook, the macro sheet (http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet) is not added to the sheets-shIdMap. Example document contains Macro1, Sheet1, Sheet2. workbook.getNumberOfSheets() returns 2 (Sheet1, Sheet2 not Macro1) I can't find relationships with : workbook.getPackage.getRelationshipsByType("application/vnd.ms-excel.macrosheet+xml") or with this: wbpart = workbook.getPackagePart() wbrelcollection = wbpart.getRelationshipsByType("http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet") I need to get xlm macro sheet index and remove it from the document completely.
Have you tried getRelationshipsByType("http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet") - from a quick check of the POI code, getRelationshipsByType expects strings like this - not 'content types'
1umos - is this you? https://stackoverflow.com/questions/76306947/how-to-get-xlm-macro-sheet-from-excel-with-apache-poi-xssfworkbook Seems similar but seems to suggest that you can get relationships of this type - while maybe running into issues removing them.
I tested your xlsm file and this code seems to get the macrosheet part String relType = "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet"; PackageRelationshipCollection prc = workbook.getPackagePart().getRelationships(); assertNotNull(prc); assertEquals(6, prc.size()); PackageRelationshipCollection prc2 = prc.getRelationships(relType); assertNotNull(prc2); assertEquals(1, prc2.size()); workbook.getPackage() checks the wrong relationships - you need workbook.getPackagePart().getRelationships()
(In reply to PJ Fanning from comment #3) > I tested your xlsm file and this code seems to get the macrosheet part > > String relType = > "http://schemas.microsoft.com/office/2006/relationships/xlMacrosheet"; > PackageRelationshipCollection prc = > workbook.getPackagePart().getRelationships(); > assertNotNull(prc); > assertEquals(6, prc.size()); > PackageRelationshipCollection prc2 = > prc.getRelationships(relType); > assertNotNull(prc2); > assertEquals(1, prc2.size()); > > workbook.getPackage() checks the wrong relationships - you need > workbook.getPackagePart().getRelationships() Thanks, I get macrosheets part like this, but if I try to removeRelationship then document doesn't open. Do you have a solution for that? And yes stackoverflow question is mine.