I have a ListView that I need to export to an Excel spread sheet. There a bunch of documentation to export GridViews and to a lesser extent ListViews to Excel but not so much in terms of doing some customization before export.
Before exporting I need to prep the data, as a) only a subset of the columns need to be exported b) some of these columns are editable textbox controls.
Doing a simple export without preping the table means that the control gets exported as well which obviously looks really ugly.
At the moment I can iterate the controls and remove the formatting from both the Grid and ListViews thus solving b.
In the GridView and I can just set some the columns I want to hide using Visible = false; and then set back to true when I have finished.
The thing I can't figure is how to do this with the listview.
I am wondering what is the best way to do this as I am kind of stuck.
Thanks,
Michael
I actually think this is a dumb question. If I want to export the list view to excel then i'll export all columns removing the unnecessary formatting. Then users can do any customization of the columns in Excel.
To do any customization of the data prior to export then I should use the underlying data types.
The above approach (admittedly my own) is simply bad.
Related
I have a dataGrid in my WPF application. I can export this dataGrid due to this good tutorial :
http://www.codeproject.com/Articles/120480/Export-to-Excel-Functionality-in-WPF-DataGrid
My problem is : I get every column of my Object, and i'd want to display only the columns of my actual Datagrid, not every strings of my Object. One guy asked the question in this tutorial, he didn't get any answer.
Also, I want to switch the order of my columns, so I found this snappet :
Excel.Range copyRange = _range.Range["D:D"];
Excel.Range insertRange = _range.Range["A:A"];
insertRange.Insert(Excel.XlInsertShiftDirection.xlShiftToRight, copyRange.Cut());
The only problem is : It only works one time, I can switch A column to D but once it's done I can't move B to E for example ...
So I heard about MyXls and other librairies (I'm quoting this one cause that's a free one and I can only use free librairies for this project).
I'm a bit lost, I've been working on this for 2 days and I don't know what to do.
Do you have a great librairy for Excel import in WPF ? Or do you have a snippet to switch columns and especially (most important) display only the DataGrid row ?
Thanks in advance !
Have you tried copying your list of objects into a smaller list of DTO objects that contain only the fields on the data grid? That way, the export to Excel functionality would only iterate the fields from the datagrid because that's all the datagrid knows about. I'd open a second question for the ordering / reordering of columns.
I'm currently working on a WPF based data management system, which is planned to replace the old Excel based one. This old system is mainly consist of tables where the user can input his data. One of these tables looks like this:
The number of rows and columns are fixed (25 rows per day, from 6AM to 6AM the next day).
It is kinda difficult to provide an input form for this kind of data, so I tried implementing the table in WPF using a DataGrid. However, I wasn't able to get these nifty merged cells, especially in the first and second row.
Are there any 'DataGrid' usercontrols on the market that allow merging cells, shading rows etc.? Or is there any other way of providing an user-friendly input form that I've overlooked?
If you're looking for Grid cell merging tool you can try Devexpress.
Here is a link on how to merge DataGrid cells using Devexpress
Another solution to merge DataGrid Rows is to use a ListBox
I've had a Google but I find no answer. You know how say in MS Word, when you insert a table, you can merge the columns of one single row to create a column-less row? Or have say a main header and then more columns inside it? Like so:
Merged Row:
|Column 1|Column 2|Column 3|
|Value|Value|Value|
|Merged Row|
|Value|Value|Value|
God the text formatting is awful on this web-site...and the Header Column example:
|Main Header||Another Main Header|
|Column 1|Column2||Column1|Column2|
I'm trying to achieve this in a written DataTable in C# which is being populated by an array. But I'm interested in changing its structure as one of the above, whichever is possible/easier.
So I've created my DataTable and added normal columns and rows etc. But I'd like to create either a merged row or a main header to display. Instead of having a repeated value in a single column for the values I am getting.
Can someone please provide a quick example on how I could achieve either one of those? Because repeated value will just look ugly.
Cheers.
You're talking about displaying data in a particular way but a
DataTable has nothing to do with display. It is for storage and that's
that. How you display the data is up to you. The same data can be
displayed in innumerable different ways. In a WinForms app, one of the
most common ways to display the contents of a DataTable is with a
DataGridView. You can choose which columns to display and merge cells
in that grid if desired. In short, you're looking in the wrong place
to do what you want to do. It is a presentation issue, not a data
issue. –
jmcilhinney
I want to read and display an excel file in a web page. I am using Microsoft.Office.Interop.Excel in .aspx.cs and GridView in .aspx. I am just reading it into a DataTable and binding it to GridView.
The problem with this is, I can't handle merged cells. For example, if two columns are merged in Excel, while displaying, it will show two columns with the value in first cell and second cell will be empty. I just want to retrieve the sheet as it is. Is there any way to achieve this?
Microsoft.Office.Interop.Excel is designed to provide programmatic access to excel files. It will do some formatting work (see Text property) but most of the difficulty of rendering is left to the consumer (your program).
MergeCells will return True if you have a merged cell and MergeArea will return a Range containing the merged cells. You can then use the RowSpan and ColumnSpan fields of the GridView's cells to duplicate the functionality.
I have a asp.net page in which i am exporting gridview records to the excel files. But in some records only ############# is displayed in the excel file & when i view that record in function bar of the excel i am able to view correct record. So what can be the problem?
Waiting for your reply.Thanks a lot in advance.
Thanks
Mehul Thakkar
Make the columns wide enough so that the entire number can be displayed.
####### in the cell only means that the cell is too narrow to fit the value (for some data types). If you make it wider the problem will disappear.