I have a DevExpress WPF grid (version 9.3). When I export to excel, it has horrible additional rows* that completely mess up excel's functionality such as auto filter.
I've been trying to make sense of the documentation and I think that the solution may lie in setting TableView.PrintCellStyle somehow. But it's really not clear.
I am using the TableView.ExportToXls(string path); method.
Is there a quick way of switching off this behaviour and getting a working xls file?
*I understand that this is to help with creating a spreadsheet that looks the same as the grid. Horrible default behaviour - a working spreadsheet is more important than it looking like the UI.
EDIT: #DmitryG - I have tried this and now, instead of three lines I now get two. Better, but not solved.
I have also checked the KB article you cited and get the following result:
I am using version 9.3.6.
Anything else I can try?
EDIT 2: Have tried the value converter approach. Getting the same additional row.
Worst case, is there anyway of excluding these columns from the export?
As far as I can see the problem like yours was already discussed here:
Exporting Boolean Values causes Three Merged Rows To Appear for each Row of data.
The problem solution for version 9.3 was the direct assigning of the GridColumn.EditSettings property:
<dxg:GridColumn x:Name="Boolean" FieldName="Boolean">
<dxg:GridColumn.EditSettings>
<dxe:CheckEditSettings HorizontalContentAlignment="Center"/>
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
Please also review the following KB article:
How to change representation of data cells via PrintCellStyle when printing/exporting grid data.
P.S. This problem is absent in the latest versions.
DevExpress has significantly improved the export engine in the latest version 14.2 and now the issue should be solved.
Please refer to the following help article for more information:
Printing and Exporting
I was still getting the additional rows. The quickest and easiest way to get around this was to set the EditSettings of the column so it exports 'True' or 'False', export the grid then set the column back to a checkbox.
Thusly:
public void ExportGridToExcel()
{
TableView.Grid.Columns["*FieldName*"].EditSettings = new TextEditSettings();
TableView.ExportToXls(#"C:\temp\spreadsheet.xls");
TableView.Grid.Columns["*FieldName*"].EditSettings = new CheckEditSettings();
}
NB It's the fieldname the column is bound to and NOT the column name. That caught me out for a minute.
Related
I'm working with a DevExpress 14.1 GridControl on WPF, which must bind to a dynamic source. We don't know the number of columns or rows on design time, so this must be calculated on the fly.
The source may be changed while executing, adding more rows, or columns, or BOTH (I could have a table with 3 columns and 5 rows, and a 6th row with 4 columns could be inserted, adding a new column to the model with empty data for the previous rows).
I was using a DataTable as ItemsSource for the grid, but it will only load data inserted on design time. If I add columns while running the app, the grid wont update for some reason.
Is there an observable object that can satisfy this needs?
It's using code-behind (not MVVM) and maybe you already tried it, but have you tried explicitly calling myGrid.RefreshData() in your .xaml.cs file? There'd be some hook-ups to get it to call at the right times depending on your data changes, but it might at least help you narrow in on the problem if it helps or not.
DevExpress support answer here may help also.
Changing from a DataTable to an ObservableCollection may also do the trick: see this.
BTW, I've found DevExpress's support ticket system to be very helpful; they seem to respond within ~24 hours for issues and questions. If you're still able to get support for your license & can't solve it still, I'd ask them the same question here.
Please take a look at the screenshot below.
I am trying to create the page with a gridview. The number of column are so many. There are two issues that I am facing here.
1 ) I am using Databale js to provide paging, searching and other facilities. As shown in the screenshot due to large number of columns the search box and paging box are not getting applied on proper place.
2 ) If the column is having a large string , Is there any way we can achieve excel like facility. Where default the overflowed text is hidden and when we click on column to re size it can show the whole value. I am using colresizable plugin for re sizable columns but it is not working as expected.
IdeaSparks ASP.NET CoolControls will work for your problem.
I am extremely new to c# and WinForms, so I apologize in advance if this is something trivial.
With my mouse only, I created a form in the Visual Studio Designer and added a DataGridView to it. Then via code, I created a DataTable, added a few columns, added a bunch of generated rows, and bound it to the DataGridView with the following command:
dataGridView.DataSource = dt;
The program works just fine. However, in the Designer I see the DataGridView empty, and cant make any column related changes such as changing a column color, changing its size, etc.
Note that I DO know the column names and types in advance. It is only the data itself which is dynamic and generated on the fly.
Please help!
I'm know for sure you can change make your column related change in the backend code.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview_properties(v=vs.110).aspx
You would need to iterate trough your grid and change every row/columns/cell properties.
`Dim test As New DataGrid
test.Columns(0).ItemStyle.BackColor = Drawing.Color.AliceBlue`
This is vb code, but it would be pretty much the same thing in every language.
Otherwise, to use the GUI you can go in the properties->style
Exemple :
http://imageshack.com/a/img837/4024/hvda.png
Hi I need a quick solution to do filtering/sorting using the Winforms DataGridView control just as in Excel.
I have reviewed the existing posts on this area but none seems to meet my needs.
I am populating my DataGridView manually - no data binding
The DataGridView columns already support sorting.
I would populate a DataTable with your data and then bind the DataGridView to myDataTable.DefaultView.
You can filter the rows displayed by setting myDataTable.DefaultView.RowFilter.
You could place Textboxes and/or Comboboxes above the DataGridView and update myDataTable.DefaultView.RowFilter as the input/selections change.
If you're looking for a Excel like filtering funcionality, check out this article:
http://msdn.microsoft.com/en-us/library/aa480727.aspx
Why don't use a cheap 3rd-party component? Even if you buy it, eventually it could really save your money. This DataGridView alternative with autofilter works very fast, and unbound mode is its main work mode. Plus it supports Excel-style AutoFilter.
Do you want something like this?
DataGridView-AutoFilter is a ready-made Nuget package, you just need to download it and follow this article, it is an easy and enhanced approach.
Microsoft has created a sample project for VB and C# where they show how to create what they say is an "auto-filter" plugin. I personally do not like it as it allows filter exact only so product and customer will work, open invoice where price > some value is not implemented
Sorting is implemented by using:
foreach (DataGridViewColumn column in MyDataView.Columns)
{
column.SortMode = DataGridViewColumnSortMode.Automatic;
}
You do this when the grid has it's columns, if auto creating the columns… after binding.
I'm attemping to update an Excel 2007 pivot table in VSTO (C#) and would like to ensure that the pivot table doesn't get updated until all of my edits are done. So there's a property on the PivotTable class, ManualUpdate, that apparently does exactly what I want. Unfortunately it appears that often times when I assign it the value "true" the value doesn't change. Additionally, I've also seen on other occassions where it will change from "true" to "false" by itself.
BTW, I'm working with an OLAP cube. Does anyone know what the issue/conditions I need to consider with PivotTable.ManualUpdate?
Thanks!