Reading contents from xlsx file using DocumentFormat namespace in C# - c#

How to read rows one by one by its column name from xlsx file using C# or making use of DocumentFormat namespace.
Please help..!
Thanks.

Look at below question. You can get the data into dataset first and then read it from there by column name. I think that's a better option than trying to figure out how to read data using column name in excel(if at all it's possible which I doubt).
Get column name from excel worksheet

Related

Overwrite Data in Excel file with OleDb C#?

is it possible to overwrite data in cells with OleDb in C# with a specific row range?
I only found adding data to first empty cells in specific column like
string sql = "Insert into [Tabelle1$] (testA, testB) values(6,7)";
If its not possible what assembly is fast for this task ....Microsoft.Office.Interop is horrible slow.
Thanks for any tip

Skip first cell & last cell - From Excel to DataTable in C# with Open XML

I have implemented this code as mentioned here :
From Excel to DataTable in C# with Open XML
My excel is like this :
So now the code which I wrote does not work as I am unable to skip the first row with unwanted text.
I need to skip the first row & last row, extracting data only from the columns & rows
Please help
The easiest way to read an Excel file is to use EPPlus library.
You could then take a look at the following examples to import your worksheet into datatables here or here.
Hope this helps !

Retrieving table data from a doc file using c#

I am working on a project which involves getting data from a .doc or a .docx file. The input requirements are in a tabular format. Is it possible to retrieve data from table in a row wise manner or as a dataset.I am using Microsoft.Office.Interop.Word to get the data from the doc file.
You can use the property Tables of the Document interface to get a collection with all the tables in your document. For each Table in this collection you can get the rows and for each row the cells.
I.e. if app is your Application object you can write something like this to get the text contained in each cell(supposing that there is exactly one in your doc):
string aCellText;
foreach (Row aRow in Application.ActiveDocument.Tables[0].Rows)
foreach (Cell aCell in aRow.Cells)
aCellText = aCell.Range.Text;
That is not possible with the word, but if you want something like that than you should put tabular data in you excel file and than you can easily read it in the dataset object....
this is not possible to get the data in dataset object from .doc or .docx file. But if your data is in tabular form and also in the excel sheet than you can retrieve the data in dataset object. MS Word is for documentation purpose and excel is used for maintaining data sheets..

Importing from Excel - Header is not on row 1

Is there some simple way I am missing to import an Excel worksheet into a datatable using an OleDBConnection and change what row the header is located on? I have HDR=YES in my connection string and that works great when header is on row 1 but the header is actually going to need to be on row 3. I am using the following CommandText:
SELECT [headercol1name], [headercol2name], [headercol3name] FROM [sheetname]
You can specify a range: How can I programmatically import Excel data into an Access table?
"SELECT * FROM [Sheet1$A3:G65536]" will only return records for used range, though I did not test very carefully.
To my knowledge, neither the HDR parameter or the schema.ini file allow anything but the first row to be the header row.
http://msdn.microsoft.com/en-us/library/ms709353%28v=vs.85%29.aspx

Importing an Excel WorkSheet into a Datatable

I have been asked to create import functionality in my application. I am getting an excel worksheet as input. The worksheet has column headers followed by data. The users want to simply select an xls file from their system, click upload and the tool deletes the table in the database and adds this new data.
I thought the best way would be too bring the data into a datatable object and do a foeach for every row in the datatable insert row by row into the db.
My question is what can anyone give me code to open an excel file, know what line the data starts on in the file, and import the data into a datable object?
Take a look at Koogra.
You instantiate a WorkBook object from a path to an XLS file.
You access a WorkSheet object from the workbook's Sheets property.
You can enumerate over the rows in the worksheet by accessing the sheet's Rows property from index MinRow to MaxRow.
You can enumerate over the cells in a given row by accessing the row's Cells property from index MinColumn to MaxColumn.
Each cell has a Value property (object) as well as a FormattedValue method (string).
Give it a try -- I've found it to be extremely intuitive and easy to use.
You can make use of an OleDbConnection to connect to excel file and the query it using SQL queries.
If it is an Asp.Net application, then you make use of the FileUpload control and get the bytes from the file. Then you will have to manually convert it to a datatable.
Try out these links:
OleDbConnection to excel file
Byte array to datatable
What your looking for is the concept described Here
Providing you dont want to use a third party library anyway, else Dans solution will suit you
First you have to download the dll file namely
NExcel.dll
By using this dll you can make various object which are very useful for
import excel data in .net using both vb as well as c#.
Good luck.

Categories