Exporting html data to Excel [modified]
-
Guys, How do we copy a set of data from the web and paste it in Excel sheet, Programatically in C#? e.g. If i go to http://www.eurofound.europa.eu/eiro/2006/03/articles/no0603029i.htm[^] I want to copy this table 1 data and then paste it in Excel. In other words, does any one know how to parse the html data and save it in excel, Programatically in C#? Thanks for your expertise.
modified on Tuesday, April 15, 2008 10:50 AM
Copy and paste in notepad, then in notepad copy and paste in Excel ...
Waleed Eissa Software Developer Sydney
-
Copy and paste in notepad, then in notepad copy and paste in Excel ...
Waleed Eissa Software Developer Sydney
-
:) Thanks Waleed. I bet i did nt ask how to do that programatically in C# (assumed it to be understood.) So does any one know how to parse the html data and save it in excel, Programatically in C#?
Well, you said copy and paste, you don't programmatically copy and paste, you import/export/parse .. etc .. this is why I was confused .. anyway, you have to parse the page (it's also called html scraping I believe) .. you can use mshtml to access the DOM of the page .. I have written a tool recently that does exactly this, read data from a table in an html page and save it to a table in a database but it only works with MySQL but I believe you could change the code easily, anyway, tell me if you want the code ... regards
Waleed Eissa Software Developer Sydney
-
Well, you said copy and paste, you don't programmatically copy and paste, you import/export/parse .. etc .. this is why I was confused .. anyway, you have to parse the page (it's also called html scraping I believe) .. you can use mshtml to access the DOM of the page .. I have written a tool recently that does exactly this, read data from a table in an html page and save it to a table in a database but it only works with MySQL but I believe you could change the code easily, anyway, tell me if you want the code ... regards
Waleed Eissa Software Developer Sydney
-
Thanks Waleed for helping out here. Now i know the right technical terms for what i want to acheive here :) If you can send me the code for your tool, i will really appreciate that man. ytb
Sure, I uploaded the code to my website .. you may download it from http://www.waleedeissa.com/temp/HTM2MySQL.zip[^] BTW, you could just replace MySQL with OleDb and export to Excel using OleDb and this connection string: string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=YES;\"", excelFilePath) Just change HDR=YES to HDR=No if you don't have headers in your Excel sheet ...
Waleed Eissa Software Developer Sydney
modified on Wednesday, April 16, 2008 3:20 AM
-
Sure, I uploaded the code to my website .. you may download it from http://www.waleedeissa.com/temp/HTM2MySQL.zip[^] BTW, you could just replace MySQL with OleDb and export to Excel using OleDb and this connection string: string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=YES;\"", excelFilePath) Just change HDR=YES to HDR=No if you don't have headers in your Excel sheet ...
Waleed Eissa Software Developer Sydney
modified on Wednesday, April 16, 2008 3:20 AM
-
You're right, sorry, I fixed the link try it again... I also added a missing file, so if you already downloaded the file, then please download it again...
Waleed Eissa Software Developer Sydney
-
Guys, How do we copy a set of data from the web and paste it in Excel sheet, Programatically in C#? e.g. If i go to http://www.eurofound.europa.eu/eiro/2006/03/articles/no0603029i.htm[^] I want to copy this table 1 data and then paste it in Excel. In other words, does any one know how to parse the html data and save it in excel, Programatically in C#? Thanks for your expertise.
modified on Tuesday, April 15, 2008 10:50 AM
You can try this link http://www.codersource.net/csharp_screen_scraping.html[^]
Sarvesh Upadhyay Senior Software Engineer Birlasoft India Ltd. Microsoft Certified Professional Developer in Dotnet 2.0 Enterprise Application
-
You're right, sorry, I fixed the link try it again... I also added a missing file, so if you already downloaded the file, then please download it again...
Waleed Eissa Software Developer Sydney
Arite, I have written the problem scenario below. Can you help me with Step 2? How do i make my application launch the browser with username and password already entered in it? Sample Scenario: Step 1 - I want to launch a webpage (www.hotmail.com) using C# Application. Step 2 - I want my application to enter the username and password in the fields and then click the 'Sign In' button. Therefore when i launch this application, it takes me directly into the page where data is sitting (Emails) Here is the code that is working for Step 1
string url = "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=10&ct=1208358013&rver=4.5.2130.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&id=64855"; System.Diagnostics.Process proc = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(url); proc.StartInfo = startInfo; proc.Start();
-
Arite, I have written the problem scenario below. Can you help me with Step 2? How do i make my application launch the browser with username and password already entered in it? Sample Scenario: Step 1 - I want to launch a webpage (www.hotmail.com) using C# Application. Step 2 - I want my application to enter the username and password in the fields and then click the 'Sign In' button. Therefore when i launch this application, it takes me directly into the page where data is sitting (Emails) Here is the code that is working for Step 1
string url = "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=10&ct=1208358013&rver=4.5.2130.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&id=64855"; System.Diagnostics.Process proc = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(url); proc.StartInfo = startInfo; proc.Start();
Actually I never tried this before but I believe (not sure though) I saw an article here on codeproject.com that talks just about that , so, you could try searching the site .. I can tell you though that you don't need to do it in two steps, you can pass the username and password as a POST request but to do this in the browser this is what I'm not sure of, I'm almost sure it's possible but I don't have experience with that, so, I guess you need to do a little googling .. sorry man, wish I could help ...
Waleed Eissa Software Developer Sydney
-
Arite, I have written the problem scenario below. Can you help me with Step 2? How do i make my application launch the browser with username and password already entered in it? Sample Scenario: Step 1 - I want to launch a webpage (www.hotmail.com) using C# Application. Step 2 - I want my application to enter the username and password in the fields and then click the 'Sign In' button. Therefore when i launch this application, it takes me directly into the page where data is sitting (Emails) Here is the code that is working for Step 1
string url = "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=10&ct=1208358013&rver=4.5.2130.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&id=64855"; System.Diagnostics.Process proc = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(url); proc.StartInfo = startInfo; proc.Start();
Well, just wanted to be sure that I understood correctly, are you talking about launching the default web browser e.g. IE or FireFox? (this is what I understood) or hosting a browser control in your application? ie. showing the page in your application .. it's much easier in the later case ...
Waleed Eissa Software Developer Sydney