OleDbAdapter reading column data - c#

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.

Related

Hide/Delete chart from excel using epplus

I am using epplus to create excel with chart where I have added 2 column charts in excel sheet and we are using this excel sheet as template.
Now, If any of the chart doesnt have data then I want to hide/delete the chart from the sheet while downloading. But, I am unable to find such option.
Below is my code
ExcelDrawing excelDrawing = excelWorksheet.Drawings["Chart1"];
After this I am not getting any option in excelDrawing object to hide/show/delete OR else do I need to go in different way ?
Any help on this appreciated !

Set readonly column in closedxml column

I got stuck for setting "ReadOnly" column using "ClosedXML" utility for export to Excel.
I am able to export records into Excel, however the first "ID" column I need to keep it read only, user should not type anything. If he want to add new row in the exported excel he can, except "ID" column. Please help me to solve this functionality (ws is my worksheet).
ws.Column("ID").Style.Protection.SetLocked(true);
Even I am setting "SetLocked" it is editable and I need non-editable field.
You need to also switch protection on for the worksheet with
ws.Protect()
See the documentation and this question for more details.
at first you need to protect the whole sheet then unlock only the cells you want to be editable as following
ws.Protect("yourPassword"); //hint: password parameter is optional
ws.Column("ID").Style.Protection.SetLocked(false); //set to false

update excel sheet without Header columns

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

Assign RTF/HTML code to Excel cell

I am Working on Microsoft C#.net(windows)
I have a requirement ,
I have an excel file containing formatted text in a cell (ex: text will be bold,italic,color) . I need to save the cell content in to the sql database.
Then i need to show the saved formatted text from database to a new excel file.
How to assign RTF code and HTML code to Excel cell.
Is there any option available. Please help
Thanks
Sandeep
i think you can use openxml to split the data along with cell formart and save in different tables in your db by referencing some id.
Lets say sheet 1 has sheetid as 1 and against this sheet id save data in your table and against same sheetid save cell number and style associated like font border fill.
Below Link can be helpful.
http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.cellformat.aspx
I am writing code for the same will share soon

Set Excel sheet as datasource to Gridview

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

Categories

Resources