You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by margotsunshine <ma...@mail.nih.gov> on 2013/04/19 19:48:17 UTC

Re: Create a new Table into an XSSF sheet ( excel 2007 )

I have followed this thread and it seems that there used to be a way to
create a new Table before table was move to XSSFTable but I can't find
anything that tells me how to do it now. Is it possible to add a new table
to a 2010 Excel Spreadsheet? If so, is there documentation on how to do it?

Thanks,
Margot Sunshine



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Create-a-new-Table-into-an-XSSF-sheet-excel-2007-tp4288371p5712580.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: Create a new Table into an XSSF sheet ( excel 2007 )

Posted by srini2k6 <sr...@gmail.com>.
following code works with 2007..

public static XSSFTable AddTableGeneric(XSSFSheet p_sheet,
String p_tableName,
 List<String> p_listOfColumnNames,
int p_startRow,
 int p_startCol,
int p_numRows,
 TTPropBase p_fontProps) throws Exception
{

XSSFTable l_table = p_sheet.createTable();
 XSSFRow l_row = p_sheet.createRow(p_startRow);

 l_table.setName(p_tableName);
l_table.setDisplayName(p_tableName);

CTTable l_cttable = l_table.getCTTable();
 CTTableStyleInfo addNewTableStyleInfo = l_cttable.addNewTableStyleInfo();

 AreaReference NewRef = new AreaReference(new CellReference(p_startRow,
p_startCol), new CellReference((p_startRow + p_numRows - 1), p_startCol +
p_listOfColumnNames.size() - 1));
 l_cttable.setRef(NewRef.formatAsString());
l_cttable.setId(++m_tableCount);
 l_cttable.setTotalsRowShown(true);


l_cttable.setHeaderRowCellStyle("Table Style Light 4");

CTTableColumns cttabcols = l_cttable.addNewTableColumns();

int l_iCoumnCount = 1;
 for (String l_ColonName : p_listOfColumnNames)
{
 CTTableColumn l_cttabcolumn = cttabcols.addNewTableColumn();
l_cttabcolumn.setId(l_iCoumnCount);
 l_cttabcolumn.setName(l_ColonName);
l_row.createCell((p_startCol - 1) +
l_iCoumnCount).setCellValue(l_ColonName);
 l_iCoumnCount++;
}

//Header Cell styles
 if (p_fontProps != null)
{
 XSSFCellStyle l_cellStyle = getStyle(p_fontProps, p_sheet.getWorkbook());

 XSSFRow l_headerRow = p_sheet.getRow(p_startRow);

 for (int l_i = 0; l_i < p_listOfColumnNames.size(); l_i++)
{
 l_headerRow.getCell(l_i + p_startCol).setCellStyle(l_cellStyle);
}
 }

return l_table;
 }
}

* Thanks & regards
*

*        Srini.*


On Fri, Apr 19, 2013 at 11:18 PM, margotsunshine [via Apache POI] <
ml-node+s1045710n5712580h30@n5.nabble.com> wrote:

> I have followed this thread and it seems that there used to be a way to
> create a new Table before table was move to XSSFTable but I can't find
> anything that tells me how to do it now. Is it possible to add a new table
> to a 2010 Excel Spreadsheet? If so, is there documentation on how to do it?
>
> Thanks,
> Margot Sunshine
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-poi.1045710.n5.nabble.com/Create-a-new-Table-into-an-XSSF-sheet-excel-2007-tp4288371p5712580.html
>  To unsubscribe from Create a new Table into an XSSF sheet ( excel 2007 ), click
> here<http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4288371&code=c3JpbmkyazZAZ21haWwuY29tfDQyODgzNzF8MTc4Mjk0NzQxMQ==>
> .
> NAML<http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Create-a-new-Table-into-an-XSSF-sheet-excel-2007-tp4288371p5712581.html
Sent from the POI - User mailing list archive at Nabble.com.