You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by kris79ric <kr...@yahoo.com> on 2013/05/15 18:15:33 UTC

Altering a Table through XSSF Event API

Using an XSSFWorkbook, I can change the range of a table by doing this:

sheet = (XSSFSheet)wb.getSheetAt(4);
sheet.getTables().get(0).getCTTable().setRef("A1:E5");
sheet.getTables().get(0).getCTTable().getAutoFilter().setRef("A1:E5");

I have to instead use the XSSF Event API and SAX because I'm creating a
large Excel file and have limited memory.  How can I achieve the same thing
as above using XSSFReader?

-Kris



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Altering-a-Table-through-XSSF-Event-API-tp5712708.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Altering a Table through XSSF Event API

Posted by kris79ric <kr...@yahoo.com>.
In case anyone is interested, here's how I updated the tables successfully:

opcPackage = OPCPackage.open(file);
List<PackagePart> parts =
opcPackage.getPartsByName(Pattern.compile("/xl/tables/.*\\.xml"));
      
for (int i = 0; i < (parts != null ? parts.size() : 0); i++)
{
      PackagePart part = parts.get(i);     	
      TableDocument td = TableDocument.Factory.parse(part.getInputStream());
      CTTable ctt = td.getTable();
      CTAutoFilter ctaf = ctt.getAutoFilter();      	
      ctt.setRef("A1:I"+reLastRow);
      ctaf.setRef("A1:I"+reLastRow);      	    	      	
      OutputStream os = part.getOutputStream();
      td.save(os);
      os.close();
}
opcPackage.close();



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Altering-a-Table-through-XSSF-Event-API-tp5712708p5712711.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Altering a Table through XSSF Event API

Posted by kris79ric <kr...@yahoo.com>.
I found the XML that needs to be changed.  Can you direct me to anything that
helps with doing this low-level XML manipulation?  



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Altering-a-Table-through-XSSF-Event-API-tp5712708p5712710.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Altering a Table through XSSF Event API

Posted by Nick Burch <ap...@gagravarr.org>.
On Wed, 15 May 2013, kris79ric wrote:
> I have to instead use the XSSF Event API and SAX because I'm creating a 
> large Excel file and have limited memory.  How can I achieve the same 
> thing as above using XSSFReader?

XSSFReader is read-only, it doesn't support writing. You'll either need to 
do very low level xml manipulations on the raw xml, or just buy some more 
memory for your server. (Memory is cheap, programmers aren't...)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org