I have a WPF
project that used Gridcontrol
. There are 6 columns, I don't know how to export 1st,2nd,3rd column to an excel
file? I have searched many documents but they don't helpful.
Asked
Active
Viewed 187 times
-1
-
If you want to export columns of data then an itemscontrol of some sort would probably be a better starting point. You could then have a bound collection of data ( rather than a bunch of controls ) to iterate. Working with the underlying data and binding that to or templating that into controls is the way to work with WPF. – Andy Apr 26 '18 at 07:50
-
Sound good. I'm try follow your idea. Thanks – j.doen Apr 28 '18 at 13:39
2 Answers
0
If you are using DevExress GridControl and you need to prevent certain columns from being printed or exported, set the GridColumn.AllowPrinting property to false.

Alex Russkov
- 323
- 2
- 8
-
But I want two `exportings` combine in this `Gridcontrol`. One is `columns` selected and one is another. – j.doen Apr 27 '18 at 07:57
0
Here is an example of how to get info from a DataTable:
var lines = new List<string>();
string[] columnNames = dataTable.Columns.Cast<DataColumn>().
Select(column => column.ColumnName).
ToArray();
var header = string.Join(",", columnNames);
lines.Add(header);
var valueLines = dataTable.AsEnumerable()
.Select(row => string.Join(",", row.ItemArray));
lines.AddRange(valueLines);
File.WriteAllLines("excel.csv",lines);
Code taken from : How to export DataTable to Excel
So the basic idea is this: iterate over your data bound collection and get the needed info. When done, add all the created lines to a .csv file.
This may be a solution, or maybe not, I am not aware of your constraints regarding the result file format.

Olaru Mircea
- 2,570
- 26
- 49
-
Sorry, but it didn't work because you are saying about `Datagridview` but I'm `Gridcontrol`. They have some different `properties`. – j.doen Apr 27 '18 at 07:00