dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersPadma
Jivani
Ultimaterengan
Pritom Nandy
Lakshmi
Sunil Jas
Ranipriya
abhinav
krishna
Rakesh Chaubey
Mariswari
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » .NET »

Browse excel file and create XML map for each column


Posted Date: 30 Jun 2012      Posted By:: Sarang Singnapurkar     Member Level: Gold    Member Rank: 55     Points: 2   Responses: 2



Hi,
I want to develop one program which will browse excel file from C# and create XML map for each of the column.
Does anyone know how to develop this?




Responses

#678199    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 30/Jun/2012   Rating: 2 out of 52 out of 5     Points: 4

Sarang

You cannot get client full path using file upload control save it in server thenread data from excel in to dataset then write in to the xml like below


using System.Data.OleDb;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath(filename));
ExportToGrid(Server.MapPath(filename));
}
}
void ExportToGrid(String path)
{
OleDbConnection MyConnection = null;
DataSet DtSet = null;
OleDbDataAdapter MyCommand = null;
MyConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';Extended Properties=Excel 12.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet, "[Sheet1$]");
//I have data now DtSet DataSet i use below line to write into xml
DtSet.WriteXml(Server.MapPath("Xmlfile.XML")); //filename of your xml
if(System.IO.File.Exists(path))
{
System.IO.File.Delete(path);
}
}
}


Regards
N.Ravindran
Your Hard work never fails



 
#678206    Author: Lalji      Member Level: Gold      Member Rank: 131     Date: 30/Jun/2012   Rating: 2 out of 52 out of 5     Points: 3

show this code sample you can create xml file form excel
using System;
using System.Data;
using System.Windows.Forms;
using System.Xml;
using System.Data;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
System.Data.OleDb.OleDbConnection MyConnection ;
System.Data.DataSet ds ;
System.Data.OleDb.OleDbDataAdapter MyCommand ;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='Specify path here \\xl2xml.xls';Extended Properties=Excel 8.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "Product");
ds = new System.Data.DataSet();
MyCommand.Fill(ds);
MyConnection.Close();
ds.WriteXml("Product.xml");
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString());
}
}


}
}[\code]
for more reference will get here
---------------
http://csharp.net-informations.com/xml/xml-from-excel.htm
http://www.codeproject.com/Articles/10581/Convert-Excel-to-XML-file-XML-Schema-and-validate



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Access TextBox from a thread- winforms
Previous : Copy one Datatable to another datatable.
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.