TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
abhirami umayal
NA
4
3.8k
Xpath retrieval using asp.net c#
Aug 12 2013 12:23 AM
I know the title is not appropriate,Im unable to put it in a single statement.,When the university results are published,the results of each student have to be retrieved individually,my task is to retrieve,a particular number of records,based on the textbox values in my aspx page(eg:1-10) and display them in an Excel sheet in a particular format(if you notice the university website,when a roll number is typed,for each student the results are displayed in a table format,with subject codes as first column,grades 2nd column,status as 3rd column,my task is to display them in an Excel sheet like:first row alone will be subject codes,remaining rows will display the grades of the particular number of students).I have created a webpage using asp.net-c#,im using xpath to retrieve the values from university website.I partially succeeded,still my output is not exact.I assumed that if the subject codes of the first record are alone displayed in the first row of the Excel sheet,then its easy to display the grades(2nd column)values of all the remaining numbers.
this is my code:
int rowno=2;
for(j=from;j<to;j++)>
{
if (j.Equals(from))
{
myExcelWorksheet.get_Range("A1", misValue).Formula = "REGISTER NUMBER";
myExcelWorksheet.get_Range("B1", misValue).Formula = "NAME";
//retrieve the first column values of 1st roll number
var query = from table in doc.DocumentNode.SelectNodes("//table[2]").Cast<HtmlNode>()
from row in table.SelectNodes("tr[position()>2]").Cast<HtmlNode>()
from cell in row.SelectNodes("td[1]").Cast<HtmlNode>()
select new { CellText = cell.InnerText };
int cc = 1;
foreach (var cell in query)
{
int rwn = 1;
if (cc == 1)
{
myExcelWorksheet.get_Range("C" + rwn, misValue).Formula = cell.CellText;
}
if (cc == 2)
{
myExcelWorksheet.get_Range("D" + rwn, misValue).Formula = cell.CellText;
}
if (cc == 2)
{
myExcelWorksheet.get_Range("D" + rwn, misValue).Formula = cell.CellText;
}
if (cc == 3)
{
myExcelWorksheet.get_Range("E" + rwn, misValue).Formula = cell.CellText;
}
}
//retrieve the second column values of all roll number
var query1 = from table in doc.DocumentNode.SelectNodes("//table[2]").Cast<HtmlNode>()
from row in table.SelectNodes("tr[position()>2]").Cast<HtmlNode>()
from cell in row.SelectNodes("td[2]").Cast<HtmlNode>()
select new { CellText = cell.InnerText };
string ans = "";
int cc = 1;
foreach (var cell in query1)
{
Console.WriteLine("{0}", cell.CellText);
ans = ans + cell.CellText + "*" + "\n";
if (cc == 1)
{
myExcelWorksheet.get_Range("C" + rowno, misValue).Formula = cell.CellText;
}
if (cc == 2)
{
myExcelWorksheet.get_Range("D" + rowno, misValue).Formula = cell.CellText;
}
if (cc == 3)
{
myExcelWorksheet.get_Range("E" + rowno, misValue).Formula = cell.CellText;
}}
This code works fine,when the sequential numbers do not have arrear results,when there is an arrear result(which will not be orderedly displayed in the website,then the values are overwritten in the excel sheet,and finally extra subjects(arrear subject codes)are not displayed with their code in the 1st row(that is cause,the 1st roll number might have not had an arrear) now im unable to solve this issue,im having no idea how to retrieve the column values and correctly display,pls help.
Reply
Answers (
0
)
web.config
Where do i get Mvc Setup for VS-2008?