# how to export table data into excel

**URL:** https://discourse.vtk.org/t/how-to-export-table-data-into-excel/9669
**Category:** Support
**Created:** [October 25, 2022, 5:01am UTC](https://discourse.vtk.org/t/how-to-export-table-data-into-excel/9669 "2022-10-25T05:01:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![we\_create](https://discourse.vtk.org/user_avatar/discourse.vtk.org/we_create/32/5917_2.png) [@we\_create](https://discourse.vtk.org/u/we_create)
#### Post date: [October 25, 2022, 5:01am UTC](https://discourse.vtk.org/t/how-to-export-table-data-into-excel/9669/1 "2022-10-25T05:01:58Z")

</div>

Hi .  
I want to export table data into excel file .  
can anyone plz help .  
with vtk (c++)

---

<div class="post-metadata">

### Author: ![DStranz](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@DStranz](https://discourse.vtk.org/u/DStranz)
#### Post date: [October 26, 2022, 12:14am UTC](https://discourse.vtk.org/t/how-to-export-table-data-into-excel/9669/2 "2022-10-26T00:14:11Z")

</div>

Exporting directly into Excel will require an external (non-vtk) library. You could export to a CSV (comma separated values) file instead.

vtk has the [DelimitedTextWriter](https://kitware.github.io/vtk-examples/site/Cxx/InfoVis/DelimitedTextWriter/) class which will do what I described below. Just took me a while to find it.

Forget all this and use the example above:

If your data is represented as a vtkTable, then all of the methods you need are part of this class:

vtkTable::GetNumberOfRows()  
vtkTable::GetNumberOfColumns()  
vtkTable::GetValue() or vtkTable::GetRow()

If you want to add a header row to your output, use vtkTable::GetColumnName()

Basically, your code will open the file (in text format) for output, then loop over the columns, writing each column name separated by a comma and adding “\n” at the end of the header row. Then loop over each row, and within each row loop over each column and retrieve the vtkVariant value at the row, column index. You can use vtkVariant::ToString() to write it out directly as a string with default formatting, or determine the type using vtkVariant::GetType() and do custom formatting. Between each value, put a comma and at the end of each row put a “\n”. At the end of all the rows, close the file.

If your data is not a vtkTable, then you’ll have to determine how to extract the data and represent it in table form for a spreadsheet.

---

<div class="post-metadata">

### Author: ![we\_create](https://discourse.vtk.org/user_avatar/discourse.vtk.org/we_create/32/5917_2.png) [@we\_create](https://discourse.vtk.org/u/we_create)
#### Post date: [October 26, 2022, 2:31am UTC](https://discourse.vtk.org/t/how-to-export-table-data-into-excel/9669/3 "2022-10-26T02:31:52Z")

</div>

Thank you for your reply .

> [@DStranz](#):
>
> You could export to a CSV (comma separated values) file instead.

Yes,I have already exported the table data to csv file using DelimitedTextWriter.

Isn’t there any otherway to export data to excel file directly or making csv to excel .  
Thank you.
