I need to read the data of particular range in excel file and upload them in database.
The required data does not start at A1 cell instead, they start at A15 and A14 is the header row for columns. there are seven columns with headers.
(I tried to read cells via "get_Range" option)
We need to read the data in each cell and do a row by row update in database.
There are thousands of files of same type in a specific folder.
I am trying to achieve this as C# Console app because this is just a one time job.
Here is the answer i found.
step 1 : Loop through each file in the source directory.
Step 2 : Add Excel Interop Reference. and Create Excel Application Class Object, and also for Workbook, and Range(for used range).
Step 3 : Use the Get Range() function and read the rows. (since this is solution is specific for a problem, the start and end ranges of rows and columns are well known)
Step 4 : Each read row can be constructed as a string till the end of the file.
OR
Insert can be done after reading each row.
step 5 : Get Connection String and Create SQLConnection Object to perform insert. Better to use Transaction-Commit.
Done. Thanks to all.
Related
How can I get C# to transfer pictures from one Excel table to another using the EPPlus library?
I have content with a big bunch of columns and rows. In each line, starting from the second, there is a small picture of the product.
I had a task to create a table based on one content plan with a selection of certain lines. I did it, but I can't get the pictures.
From the information I found on the Internet, I realized that the Excel file can be opened as an archive and pull out a folder with a photo from there. But this option is not suitable, since you need to write several methods to somehow pull out this folder, try to understand by name, which picture belongs to each line, etc. Plus, the names have nothing to do with their cell to which they are linked in the table.
The task is to take a picture from one table for a certain line and write it to another table.
For example:
Take from "TabOne" => row: 3, column: 1
Fold into "TabTwo" => row: 5, column: 1
Thank you.
I have an excel file .xlsx which i will get from client and after certain rows data it will have a blank row and then a generic comment everytime and the starting work of that phrase will be same all the time and not the whole phrase.
I want to execute ssis only till row 5 including header as columns and not want to process line 6 and 7 and every time data changes so i can't even take a range in this case.
I have the flexibility do it either in on prem SSIS or ADF.
Tried using filters but as the text in the cell is splitted in 4-5 lines it only ignores the 1st line.
I would appreciate any help.
Using Azure data factory data flow, you can use filter transformation to ignore certain rows based on conditions.
Example:
Excel input:
ADF Data flow:
Create a source excel dataset. If your first row is not a header do not enable the First row as header property in the dataset. Here by default, the empty rows will be skipped while reading.
Add source transformation and connect it to the excel dataset. If you do not have a header row in the data, the default column names (like col0) were given to your data.
Add filter transformation after source, to filter out the unwanted rows.
Expression: not(like({_col0_},'This%'))
Filter output:
Using SSIS, in your Excel source, you can use the SQL command and write a query to pull the data from excel. If you have any mandatory columns, use filters with where condition to pull not null rows from the file (ex: SELECT * FROM [Sheet1$] WHERE [column1] IS NOT NULL). Or use the conditional split task to filter the required rows from the excel source.
I am combining multiple large excel files with different columns and number of columns.
Before starting to combine, I want to collect all header rows in order to make a data table which having all columns in advance.
I know that there is a method datatable.merge in c#, which allow to add missing column while combining.
Because there are too many big excel files, and the maximum rows per sheet in excel is about 1 millions row. So when reaching limit, I must save part of combining to excel, clear the content and keep combine after that. This will lead to the result that the saving part in the early process will don't have the same schema as the final one.
This is the reason why I must collect all header in advance.
As far as I am concerned, library in c# like Epplus or ExcelDataReader load entire content of excel. This lasts very long. I don't need to load all content at once.
Somebody here know how to load excel header row only ?
Thank you so much.
Using FastDBF I am creating DBF files on the fly dynamically) with data fed through text files. The problem is that there is always one blank column at the very end of the file. This is always true. I want to just be able to remove the very last column, and my code does this, however it seems to shift all of the data in the file arouns and turns it into a mess. In terms of code, I am just simply using these line before I close the file
odbf.Header.Unlock();
odbf.Header.RemoveColumn(colCount - 1);
It requires you to unlock to make this edit, and colCount is just the number of columns the file has. It does successfully remove the last column, but like I said it shifts all of the data round with it.
I've been requested to import an excel spreadsheet which is fine but Im getting a problem with importing a certain cell that contains both numeric and alphanumeric characters.
excel eg
Col
A B C
Row 0123 8 Fake Address CF11 1XX
XX123 8 Fake Address CF11 1XX
As per the example above when the dataset is being loaded its treating Row 2, col (A) as a numeric field resulting in an empty column in the array.
My connection for the OleDb is
var dbImportConn = new OleDbConnection(#"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dataSource
+ #";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";")
In this connection i have set the IMEX = 1 which should parse all contents as string into the dataset. Also if i change Row 1 Col (A) to have 'XX123' the entire Col (A) successfully parses as string! Unfortunately this is not going to help my scenario as the excel file is passed from an external client who have also advised that do not have the means to pass through the file with a header row which would solve my issue.
My one thought at this point is when I receive the file to edit the file (programmatically) to insert a header but again as the client may change how many columns are contained this would not be a safe option for me.
So basically I need to find a solution for dealing with the current format on the spreadsheet and to pass through all cells into the array. Has anyone come across this issue before ? Or know how to solve this ?
I await your thoughts
Thanks
Scott
ps If this is not clear just shout
Hi There is a registry setting called TypeGuessRows that you can change that tells Excel to scan all the column before deciding it's type. Currently, it seems, this is set to read an x number of rows in a column and decides the type of the column e.g. if your first x rows are integers and x+1 is string, the import will fail because it has already decided that this is an integer column. You can change the registry setting to read the whole column before deciding..
please see this also
http://jingyangli.wordpress.com/2009/02/13/imex1-revisit-and-typeguessrows-setting-change-to-0-watch-for-performance/
This isn't a direct answer, but I would like to recommend you use the Excel Data Reader, which is opensource under the LGPL licence and is Lightweight and fast library written in C# for reading Microsoft Excel files ('97-2007).