KarDinal Royce

KarDinal Royce

  • NA
  • 1
  • 838

selcting excel range or cells & export to sql using asp.net

Feb 8 2016 6:39 AM
I want to import data from Excel using range or cell, like data from row '9' to column 'G'...all the data within these rows and columns will be Exported from excel to sql data table, and this i want to achieve through asp.net.

it is like using X axis and Y axis .

i have code to import the whole file

string csvPath = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(csvPath);

DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("KPI", typeof(string)),
new DataColumn("KPIPN", typeof(string)),
new DataColumn("KPIPV", typeof(string))});
string csvData = File.ReadAllText(csvPath);
foreach (string row in csvData.Split('\n'))
{
if (!string.IsNullOrEmpty(row))
{
dt.Rows.Add();
int i = 0;
foreach (string cell in row.Split(','))
{
dt.Rows[dt.Rows.Count - 1][i] = cell;
i++;
}
using (SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(con))
{
sqlbulkcopy.DestinationTableName = "dbo.csv";

sqlbulkcopy.WriteToServer(dt);
con.Close();
} 

Answers (1)