Import a range of cells from excel sheet into a datatable - c#

I have a data report in Excel which has got some 'header information text' in top 20 rows and then from 22nd row onward all the data stuff starts. i.e. 22nd row has all the column header names (10 columns) and then 23rd onward is the data.
I basically want to extract just the data part (i.e. 22nd row onward) from the report and import into a datatable or 'oracledatareader'.
Any help would be really appreciated.
I am using visual studio 2012.

You can use this Excel library for C# and import the range you need or the entire sheet data into a DataSet.
If you will import only the range of cell, you should know where the range ends.
If you don't know, you have to import the entire sheet and delete the first 21 rows from the DataTable.
Check some samples of code at this link:
http://www.easyxls.com/manual/basics/import-excel-to-dataset.html

Related

Excel columns are stored as text but they're numeric in the database. Need most of them as "Numeric with no decimals" in the excel sheet. Using EPPlus

I am working on a report that outputs an excel file. It has 7 tabs/worksheets that the user can choose between. I got the first 5 to format correctly.
But for some reason one of the columns in the 6th worksheet and all the columns in the 7th worksheet don't work and show up as text in the excel cells. For most of them that aren't working(They're showing up as text in the excel cells) I need them formatted as Numeric with no decimals.
Below is how I'm doing the formatting for some of the stuff that worked previously. Keep in mind this worked for the previous 5 worksheets:
ws.Columns[11].Style.Numberformat.Format = "#####0.0000"; ws.Columns[13].Style.Numberformat.Format = "###,###"; ws.Columns[20].Style.Numberformat.Format = "$###,###,##0.00;($###,###,##0.00)"
I think my issue is when the data in the database is numeric and keeping it numeric in the excel sheet isn't working. Although I just checked and I've dealt with numeric types from the database that format correctly though.. Not sure why it's not working.. What am I missing here folks?

How to Dynamically Fetch excel Cell Range in Interop Excel using c#

I am stuck in a situation where i have a dynamic pivot table that returns columns based on date range the user has selected
for eg : if user selects "Oct-2020" and "Feb-2021", following columns will be returned from datatable
Name
Oct-2020
Nov-2020
Dec-2020
Jan-2021
Feb-2021
Total
if user selects "Jan-2021" and "Feb-2021", following columns will be returned from datatable
Name
Jan-2021
Feb-2021
Total
i have custom tables as shown above, so i have used interop excel to export the resultset into excel sheet, i need to color column names based on column count. i have hardcoded range values, since, i am not able to get range dynamically
how do i fetch excel range dynamically based on column count and color its background
please help me

C# WPF - Cut and then copy an entire Excel row

I have to edit an Excel sheet with a WPF in C# and already ordered the rows by one column. But now I need to cut a few rows and write them to another position in the sheet.
Is ther anyway to completely cut out an entire row and insert this row to another position in the sheet?
Looks like this has been answered
https://social.msdn.microsoft.com/Forums/vstudio/en-US/78059590-c294-47b4-a656-aec8ca51779f/c-excel-cut-or-copy-an-excel-row-and-move-to-another-row?forum=exceldev

SSIS - Import Excel file and stop at first empty row

I am importing an Excel table into my SSIS-Package.
What I know:
I know at which row the data in the Excel file starts
I know how many columns I need
I know that after the last import row there comes an empty row
So the amount of rows vary. How can I tell SSIS to import the data until the first empty row. My idea is to write a script in C# and to store the row ID of the empty row in a variable. With that variable I could specify the import matrix of my excel file.
Actually I do not have any experiences in C#. Can anyone help me with that? Or does anyone have a better idea?
Thank you in advance!!

Bar Charts from multiple columns in Excel using C# .NET

I have an excel sheet with bulk of data( several columns and thousands of rows). However, I would like to express the data in barcharts. I had found a method which gives cell numbers in the code like A1:B2, A3:C3, etc. But the problem is the excel sheet consists of thousands of rows and several columns. So, I can't give manually. Can anyone suggest a relevant method for this?

Categories

Resources