Return-Path: X-Original-To: apmail-poi-user-archive@www.apache.org Delivered-To: apmail-poi-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B2BDF1985D for ; Mon, 29 Feb 2016 15:10:41 +0000 (UTC) Received: (qmail 6591 invoked by uid 500); 29 Feb 2016 15:10:36 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 6561 invoked by uid 500); 29 Feb 2016 15:10:36 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 6550 invoked by uid 99); 29 Feb 2016 15:10:35 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Feb 2016 15:10:35 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 4D195C0287 for ; Mon, 29 Feb 2016 15:10:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3 X-Spam-Level: *** X-Spam-Status: No, score=3 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id NpJfl1XZPLk6 for ; Mon, 29 Feb 2016 15:10:33 +0000 (UTC) Received: from dd33826.kasserver.com (dd33826.kasserver.com [85.13.151.30]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 8DFA45F54E for ; Mon, 29 Feb 2016 15:10:32 +0000 (UTC) Received: from [192.168.178.58] (ipbcc1af5e.dynamic.kabel-deutschland.de [188.193.175.94]) by dd33826.kasserver.com (Postfix) with ESMTPSA id 2C55857C457B for ; Mon, 29 Feb 2016 16:10:26 +0100 (CET) Subject: Re: How to remove XSSFTable and CTTable ? To: POI Users List References: <56D07DFA.9040406@testingsolutions.de> From: Christian Reuter Organization: testing solutions GmbH & Co KG Message-ID: <56D45F62.2080909@testingsolutions.de> Date: Mon, 29 Feb 2016 16:10:26 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------040409020806010803000902" --------------040409020806010803000902 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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? Thx, Christian 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 >> --------------040409020806010803000902--