poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Reuter <c.reu...@testingsolutions.de>
Subject Re: How to remove XSSFTable and CTTable ?
Date Mon, 29 Feb 2016 15:10:26 GMT
Thank you for your reply Dominik.

I tried to extend the class XSSFWorkbook to be able to call the 
protected method
removeRelation of XSSFWorkbook:

public class XSSFWorkbookExt extends XSSFWorkbook {
     public final boolean removePartRelation(POIXMLDocumentPart part, 
boolean removeUnusedParts){
         return removeRelation(part, removeUnusedParts);

then I tried to delete the tables like this:

for (XSSFTable table : sheet.getTables()) {
         workbook.removePartRelation(table, true);

The code is executed and does the job it is intended to do (I stepped 
through with the debugger) but the tables still don't get deleted from 
the archive file. When I save the document the tables still exist in the 
file as xml files under xl/tables.

No matter if I do the steps above or not: When I open the file from 
which I deleted some sheets in Excel and save it again then the tables 
of the deleted sheets are gone. I assume that Excel does recognize that 
all links to the tables have been removed while POI does not.

Can anyone help on how to improve that?



Am 26.02.2016 um 22:36 schrieb Dominik Stadler:
> Hi,
> It should be possible to remove these pieces via the low-level POI APIs for
> Relationships/Parts on the XSSFWorkbook before you write out the XSLX,
> however I don't know the code well enough to state how exactly you would go
> about that.
> Dominik.
> On Fri, Feb 26, 2016 at 5:31 PM, Christian Reuter <
> c.reuter@testingsolutions.de> wrote:
>> Hi there,
>> I am working with XSSFTable and CTTable in my workbooks.
>> My program opens an .xlsx - template file with POI in order to delete and
>> recreate some of the sheets in this file and save it as a new file.
>> The problem is that the deleted sheets as well as the new sheets created
>> programmatically may contain tables. Unfortunately if there are tables
>> defined in the deleted sheets they are not deleted when the sheet is
>> deleted.
>> I therefore get ID conflicts later if one of my newly created tables has
>> the same ids as one of the tables which have been left over from the sheet
>> deletions.
>> The only way I see to remove the existing tables is to open the zip file
>> before reading it as a workbook and deleting the contents of the subfolder
>> "xl\tables" which contains the table definitions.
>> Can somebody help me to find a better solution please?
>> If not: can someone provide a code snippet for the above mentioned
>> low-level manipulation of the file?
>> Thx,
>> Christian

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message