I have the excel sheet, I want to keep it as datasource to the gridview. gridview will be editable so whatever the data updated sholud be write to again in excel sheet with respected location in sheet.
How can I do this?
You could use the Jet driver to select from the spreadsheet via OLEDB. Your spreadsheet will need to be laid out in a table-like fashion, and you can have some painful problems with type guessing, but this may work for your situation.
Connection string samples here
Related
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 am working on read,write excel sheets.I have an excel sheet to update and unfortunately it does not have header columns.So I am stuck how to update this?
Is it possible to update excel sheet without header? If yes than plz help how to update?
thanks in advance
Try using excel data reader from Codeplex and check how it returns the data set. Also try to manipulate dataset based on your need
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.
I dont want intermittent of using Gridview or Datagrid controls. I want directly to export a DataTable data to an Excel in straight forward.
Is there a way to export by querying the DataTable and export the same into a new Excel.
Please HELP!!
Take a look at this you can do it with XSLT
http://www.codedigest.com/Articles/ASPNET/13_Export_dataset_to_Excel_with_XSLT_in_AspNet_20.aspx
I have created a function to read an excel sheet using OLEDb. I can make the connection and read the excel sheet.
With DbDataReader and a while loop using Read() method I retrieved all cell data from an excel sheet.
I want to check the alignment info of each cell. If a cell is left-aligned, I will pick data from those left-aligned cells.
How can I do that?
Sorry It is a stupid question but I really need it.
Thanks
You can't do that with Excel OleDb provider; cell alignment isn't exposed. The OleDb provider makes the Excel spreadsheet mimic a database table and database columns don't have alignment.
You'll have to use Excel interop if you need to that. See this question for help on that.