i am working in an old application developed using classic ASP and VB, i am trying to export an HTML table from an asp page to word, i searched the internet for this and i found a good code that its working perfectly, he problem is that it export the whole page to word, i need to export only a part of the page which is the <table></table>
<%# Language=VBScript %>
<%
Option Explicit
Response.Buffer = TRUE
Response.ContentType = "application/vnd.ms-word"
Response.AddHeader "Content-Disposition", "attachment; filename = MyDoc.doc"
%>
<html>
<head>
</head>
<body>
<%
Dim Conn,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("shotdev/mydatabase.mdb"),"" , ""
strSQL = "SELECT * FROM customer "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, Conn, 1,3
%>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<%
While Not objRec.EOF
%>
<tr>
<td><div align="center"><%=objRec.Fields("CustomerID").Value%></div></td>
<td><%=objRec.Fields("Name").Value%></td>
<td><%=objRec.Fields("Email").Value%></td>
<td><div align="center"><%=objRec.Fields("CountryCode").Value%></div></td>
<td align="right"><%=objRec.Fields("Budget").Value%></td>
<td align="right"><%=objRec.Fields("Used").Value%></td>
</tr>
<%
objRec.MoveNext
Wend
%>
</table>
<%
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</body>
</html>
you can check the link here
can you please help me to solve this issue
thank you
Related
I am able to float the two tables, one is on the left side and one is on the right side. However, the table size on the left is not symmetrical to the table on the right. I am unable to display the table size equally. What should i do to display the table side by side equally?
html
html file
<div class="floatleft">
<div class="left">
<div class="row">
<div class="col-md-3">
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver");
String connURL = "jdbc:mysql://localhost/test?user=1234&password=1234";
conn = DriverManager.getConnection(connURL);
String sql = "select * from test";
PreparedStatement pstmt=conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
%>
</div>
</div>
<div>
<p<u>Arm</u></a></font></p>
<table>
<tr>
<th >Arm Exercises</th>
<th >Number of times</th>
<th colspan='1'> </th>
<%
String sql1="";
{
sql1 = "select * from test";
PreparedStatement pstmt1=conn.prepareStatement(sql1);
ResultSet rs1 = pstmt1.executeQuery();
while(rs1.next()){
String id = rs1.getString("ID");
out.println("<tr>");
out.println("<td style = 'width: 85%'>");
out.println(arm);
out.println("</td>");
%>
<td>
<textarea cols="2"></textarea>
</td>
<%
out.println("</tr>");
}
conn.close();
}
%>
</table><br>
</div>
Just put the table in the div element with a class name.
<div class="floatleft">
<table>
</table>
<div class="floatright">
<table>
</table>
I am working on an Excel VBA project to scrape some specific information from a website. The view of this data on the website is as such:
Website View:
What I am looking to do is extract text based on two criteria: Name and post date. For example, I have the name Kaelan and the post date of 11/16/2016. I want to extract the amount of $365.
This is the HTML code:
<div class="familyLedgerAmountCategory" id="id_4541278">
<table>
<tr>
<td class="tdCategoryRow">
<div class="cmFloatLeft divExpandToggle expanded" id="divCategoryToggle_id_4541278"></div>
<div class="cmFloatLeft" id="divCategoryLabel_id_4541278" style="width: 430px;">
Kaelan
</div><span style="margin-left: 5px;">$ 465.00</span>
</td>
</tr>
<tbody>
<tr class="trListTableBody LedgerExisting" id="CamperFamilyLedgerRowControl_14816465">
<td class="tdCamperFamilyLedgerTableColumnDescription tdBorderTop" id="tdCamperFamilyLedgerTableColumnDescription_CamperFamilyLedgerRowControl_14816465">
<div class="divListTableBodyCell" id="tdColumnDescriptionCell">
<table class="tblListTableBodyCell">
<tr>
<td>
<div class="divListTableBodyLabel">
<a class="aColumnDescriptionCell" id="aColumnDescriptionCell_CamperFamilyLedgerRowControl_14816465" name="aColumnDescriptionCell_CamperFamilyLedgerRowControl_14816465" target="_self" title="Click to view details">2017 Super Early Bird Teen Camp - Tuition</a>
</div>
</td>
</tr>
</table>
</div>
</td>
<td class="tdCamperFamilyLedgerTableColumnPostDate tdBorderTop" id="tdCamperFamilyLedgerTableColumnPostDate_CamperFamilyLedgerRowControl_14816465">
<div class="divListTableBodyCell" id="tdColumnPostDateCell">
<table class="tblListTableBodyCell">
<tr>
<td>
<div class="divListTableBodyLabel">
11/16/2016
</div>
</td>
</tr>
</table>
</div>
</td>
<td class="tdCamperFamilyLedgerTableColumnEffective tdBorderTop" id="tdCamperFamilyLedgerTableColumnEffective_CamperFamilyLedgerRowControl_14816465">
<div class="divListTableBodyCell" id="tdColumnEffectiveCell">
<table class="tblListTableBodyCell">
<tr>
<td>
<div class="divListTableBodyLabel">
11/15/2016
</div>
</td>
</tr>
</table>
</div>
</td>
<td class="tdCamperFamilyLedgerTableColumnQty tdBorderTop" id="tdCamperFamilyLedgerTableColumnQty_CamperFamilyLedgerRowControl_14816465">
<div class="divListTableBodyCell" id="tdColumnQtyCell">
<table class="tblListTableBodyCell">
<tr>
<td>
<div class="divListTableBodyLabel">
1
</div>
</td>
</tr>
</table>
</div>
</td>
<td class="tdCamperFamilyLedgerTableColumnAmount tdBorderTop" id="tdCamperFamilyLedgerTableColumnAmount_CamperFamilyLedgerRowControl_14816465">
<div class="divListTableBodyCell" id="tdColumnAmountCell">
<table class="tblListTableBodyCell">
<tr>
<td>
<div class="divListTableBodyLabel">
$ 365.00
</div>
</td>
</tr>
</table>
</div>
</td>
<td class="tdCamperFamilyLedgerTableColumnAction tdBorderTop" id="tdCamperFamilyLedgerTableColumnAction_CamperFamilyLedgerRowControl_14816465"></td>
</tr>
</tbody>
</table>
</div>
My attempt to pull the amount is as follows:
Sub Test()
Dim ie As Object
Dim oElement As Object
Dim wsTarget As Worksheet
Dim i As Integer
Dim NewWB As Workbook
Set NewWB = ActiveWorkbook
Set wsTarget = NewWB.Sheets(1)
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate website...
Wait 6
ie.document.All.Item("txtUserName").Value = "User"
ie.document.All.Item("pswdPassword").Value = "Pass
Wait 1
ie.document.getElementById("btnLogin").Click
Wait 5
ie.navigate website...
i = 1
For Each oElement In ie.document.getElementsByClassName("cmFloatLeft")
If oElement.innerText = "Kaelan" Then
extract1 = oElement.getElementsByClassName("divListTableBodyLabel").innerText
MsgBox extract1
Else
End If
Next
However, I get an error when running the code above. Can I get the class for cmFloatLeft that I am looking for and then try to call the divLisTableBodyLabel class immediately even though that class does not fall directly below the cmFloatLeft class?
Sorry, I'm still pretty new to scraping web data.
Thanks
That structure is a bit difficult to scrape - you could try going "up" from the "Kaelan" node to the patent table, and then looping over that to extract the various pieces of information. If the post structures are consistent then that could provide one approach.
Set doc = IE.document
Set els = doc.getElementsByClassName("cmFloatLeft")
i = 1
For Each oElement In els
Debug.Print oElement.innerText
If Trim(oElement.innerText) = "Kaelan" Then
Set tbl = GetParent(oElement, "table") '<< find the parent table
If Not tbl Is Nothing Then
'loop over the parent table
For Each rw In tbl.Rows
For Each cl In rw.Cells
Debug.Print cl.innerText
Next cl
Next rw
End If
End If
Next
Function to find a named parent (by tag name):
Function GetParent(el, tagParent)
Dim rv As Object
Set rv = el
Do While Not rv.parentElement Is Nothing
Set rv = rv.parentElement
If UCase(rv.tagName) = UCase(tagParent) Then
Set GetParent = rv
Exit Function
End If
Loop
Set GetParent = Nothing
End Function
How do I go about displaying the results of a query from MYSQL in a jsp using html tags? My instructor said to do the query in the .jsp file and use html tags to display the results. What is the correct syntax for this. Can I get an example or a link to a page that will show me. I have no problem writing the query, just unsure about the jsp/html display. Thanks
<BODY>
<H2>JSP Expressions</H2>
<UL>
<LI>Current time: <%= new java.util.Date() %>
<LI>Your hostname: <%= request.getRemoteHost() %>
<LI>Your session ID: <%= session.getId() %>
<LI>The <CODE>testParam</CODE> form parameter:
<%= request.getParameter("testParam") %>
</UL>
</BODY>
</HTML>
in jsp we have scriptlet tags ( <% %> ).you can use the jdbc statements between these jsp tags, The below sample code shows the display query in jsp using html,
<%#page import="java.sql.*,java.util.*,java.io.*"%>
<html>
<head>
<body background="1.jpg">
<title>ehealthcare advisor</title>
</head>
<body><center>
<h1><center>E-HEALTH CARE ADVISOR</center></h1>
<h4><center>get best solutions in minuites...</center></h4>
<table border="0" cellspacing="50" cell padding="10">
<tr>
<td> HOME</td>
<td> LOGOUT</td>
<td>ABOUT US</td>
</table>
</center>
<center>
<h2>PATIENT LIST</h2>
<table border="1" width="40%">
<thead>
<th>UserId</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Occupation</th>
<th>Height</th>
<th>Weight</th>
</thead>
<tbody>
<%
Statement st = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/ehealthcare","root","root");
st = con.createStatement();
String qry ="select * from user";
rs = st.executeQuery(qry);
while(rs.next()){ %>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>
</tr>
<%
}
con.close();
st.close();
}
catch(Exception ex){
out.println(ex);
}
%>
</tbody>
</table>
</body>
</html>
Here I give the link you refer it.
Jsp Sample Database Access, it is like core java
Jsp using JSTL tags
Database from Jsp
If you use No. 2 . Jsp using JSTL tags, that will be good programming.
JSTL tags are simple to learn.
Im using a web application ,which runs on Apache Tomcat and has Mysql Database as backend
I want to retrieve multiple rows for a particular column usin the Where clause
For Example If I give select * from xyz where type=abc
I should get all the rows having type abc.
Problem:
I use the JDBC connection to achieve this, however Only the 1st row matching the where condition is returned rather than all the rows (even though multiple rows match the criteria in database)
Kindly help me resolve this
Code:
<%# page import="java.sql.*" %>
<html>
<head><link href="style.css" rel ="stylesheet" type="text/css"></head>
<body bgcolor="white" >
<div id="container">
<div id="header">
<img src="logo.jpg">
<div class ="horiztext"><p> Order Tracker</p></div>
</div>
</div>
<br>
<img src="banner.jpg" width="1500 " height="5"><br>
<% if(session.getAttribute("username") !=null)
{
%>
<div id="navbar">
<ul>
<li>New Order</li>
<li>Update Order</li>
<li>Track Order</li>
<li>Track Delay</li>
<li>View Database</li>
<li>Delete Order</li>
<li>Logout</li>
</ul>
</div>
<br>
<br>
<form>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<%
String ProductNamez=request.getParameter("ProductName");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3307
/test","root", "root");
Statement st=conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM inventory WHERE ProductName = '"+
ProductNamez +"' ");
if(rs.next()){
%>
<tr>
<tr><th>Serial No</th>
<th>Product Name</th>
<th>Product Type</th>
<th>Model</th>
<th>Make</th>
<th>License / Voucher</th>
<th>Location</th>
</tr>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>
</tr>
<%
}
%>
</table>
</form>
<%
}
else { %>
you are not logged in click here to <b>login</b>
<%
} %>
</body>
</html>
You'll be wanting
while (rs.next()){
instead of
if (rs.next()){
It's because you just do a if(rs.next()){ so only the first row is shown.
You should do this instead
while (rs.next()) {
[...]
}
The below code breaks when I place a while not EOF in another while not EOF.
Is this illegal in ASP Classic code? How do I fix it?
<table cellspacing = "0" cellpadding = "3" class = "horiz ">
<tr>
<th width = "20%">Acronym</th>
<th width = "50%">Meaning</th>
<th width = "30%">Source</th>
</tr>
<%
count = 0
pletter = "z"
fletter = left(con("acronym"),1)
%>
<% while (NOT con.EOF) %>
<tr>
<td colspan = "3" ><h2><a name="A">A</a></h2></td>
</tr>
<% while (NOT con.EOF) %>
<tr>
<td><%=con("acronym")%></td>
<td><%=con("meaning")%></td>
<td><%=con("source")%></td>
</tr>
<%
con.MoveNext()
Wend
%>
<%
con.MoveNext()
Wend
%>
</table>
Why not have a single while loop. Add an if statement to determine if the first character has changed (E.g., from A to B). If the character changes, add a TR to display the character.
dim lastCharacter = ""
while (not con.EOF)
dim firstLetterOfAcronym = left(con("acronym"),1)
if lastCharacter <> firstLetterOfAcronym then
rem show TR of firstLetterOfAcronym
lastCharacter = firstLetterOfAcronym
end if
<tr>..... show row as usual </tr>
con.MoveNext()
wend
Assuming you have your recordset sorted on the Acronym .
This is exactly like #Valamas his solution, meaning a single loop, but a bit more complete example.
<table cellspacing = "0" cellpadding = "3" class = "horiz">
<tr>
<th width = "20%">Acronym</th>
<th width = "50%">Meaning</th>
<th width = "30%">Source</th>
</tr>
<%
mainletter = ""
While (NOT con.EOF)
letter = Left(con("acronym")
If mainletter <> letter Then
%>
<tr>
<td colspan = "3" ><h2><a name="<%=letter%>"><%=letter%></a></h2></td>
</tr>
<%
mainletter = Left(con("acronym"),1)
End If
<tr>
<td><%=con("acronym")%></td>
<td><%=con("meaning")%></td>
<td><%=con("source")%></td>
</tr>
<%
con.MoveNext()
Wend
%>
</table>
Once you get to the end of the recordset (via the loop) it does not reset back to the start (unless you tell it too) so once you get to the end of the recordset in the first loop when the second loops start it is already at the end.
I would rewrite your code as it is not really logical but if you want your code to work as is add a movefirst after the loop ends to go back to the start of the recordset.
...
</tr>
<%
con.MoveNext()
Wend
con.movefirst
con.MoveNext()
Wend
%>
</table>
Edit: Actually you'll end up in a loop if you do this, clone the recordset before the first loop and loop two different recordsets with the same data. Otherwise re-write to be a little cleaner.