Talk:Team:TU-Delft/SynBioData

From 2013.igem.org

(Difference between revisions)
Line 1: Line 1:
 +
<html>
<html>
-
<script>
+
<head>
-
function mytest1() {
+
<title>Read from Excel or Access</title>
-
var Excel, Book; // Declare the variables
+
<script language="JavaScript">
-
Excel = new ActiveXObject("Excel.Application"); // Create the Excel application object.
+
function getCount()
-
Excel.Visible = false; // Make Excel invisible.
+
{
-
Book = Excel.Workbooks.Add() // Create a new work book.
+
-
Book.ActiveSheet.Cells(1,1).Value = document.all.my_textarea1.value;
+
-
Book.SaveAs("B:/Dimitra/TEST.xls");
+
-
Excel.Quit(); // Close Excel with the Quit method on the Application object.
+
-
}
+
-
function mytest2() {
+
var fso = new ActiveXObject("Scripting.FileSystemObject");
-
var Excel;
+
var s = fso.CreateTextFile("C:\\ASPConnection\\test.txt", true);
-
Excel = new ActiveXObject("Excel.Application");
+
var t = fso.CreateTextFile("C:\\ASPConnection\\test1.txt", true);
-
Excel.Visible = false;
+
var r = fso.CreateTextFile("C:\\ASPConnection\\test2.txt", true);
-
form1.my_textarea2.value = Excel.Workbooks.Open("C:/Documents and Settings/ProGamer/Desktop/word to text/TEST.xls").ActiveSheet.Cells(1,1).Value;
+
var cn = new ActiveXObject("ADODB.Connection");
-
Excel.Quit();
+
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\\ASPConnection\\Barcodes_VOCS_2011.xls;Persist Security Info=False;Extended Properties=Excel 8.0;";
 +
cn.Open(strConn);
 +
var rs = new ActiveXObject("ADODB.Recordset");
 +
var SQL = "select * from [Sheet7$]";
 +
rs.Open(SQL, cn);
 +
if(rs.bof)
 +
{
 +
document.write('No records available for this query');
 +
}
 +
if(!rs.bof)
 +
{
 +
rs.MoveFirst()
 +
while(!rs.eof)
 +
{
 +
var store = rs.fields(2).value;
 +
for(var i=0; i!= rs.fields.count; ++i)
 +
{
 +
document.write(rs.fields(i).value + ",");
 +
t.Write(rs.fields(i).value + ","); }
 +
s.WriteLine(rs.fields(2).value + ",");
 +
t.WriteLine(",");
 +
document.write("<br />");
 +
rs.MoveNext() }
 +
}
 +
rs.Close();
 +
cn.Close();
 +
s.Close();
 +
t.Close();
 +
r.Close();
}
}
-
</script>
+
var ForReading = 1, ForWriting = 2, ForAppending = 8;
 +
var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
 +
var fso = new ActiveXObject("Scripting.FileSystemObject");
-
<body>
+
// Open the files for input and output
-
<form name="form1">
+
//CHANGE THESE LOCATIONS TO ENSURE THAT :
-
<input type=button onClick="mytest1();" value="Send Excel Data"><input type=text name="my_textarea1" size=70 value="enter ur data here">
+
// a) testfile1.txt exists and
-
<br><br>
+
// b) testfile2.txt can be created and is writable
-
<input type=button onClick="mytest2();" value="Get Excel Data"><input type=text name="my_textarea2" size=70  value="no data collected yet">
+
var filename1 = "C:\\ASPConnection\\test.txt";
 +
var filename2 = "C:\\ASPConnection\\test2.txt";
-
</form>
+
var f1 = fso.OpenTextFile(filename1, ForReading, true);
 +
// Open the file for input.
 +
f2 = fso.OpenTextFile(filename2, ForWriting);
 +
 
 +
var r = f1.ReadLine(); //This line will read the data to the input file
 +
var g = r;
 +
// Read from the file and display the results.
 +
var r = f1.ReadLine(); //This line will read the data to the input file
 +
f2.WriteLine(r); //This line will write the data to the output file
 +
document.write(r + "<br />");
 +
// Read from the file and display the results.
 +
while (!f1.AtEndOfStream)
 +
{
 +
if(r!=g)
 +
{var r = f1.ReadLine(); //This line will read the data to the input file
 +
document.write (r + "<br />"); //This line will display the data on the screen
 +
f2.WriteLine(r); //This line will write the data to the output file
 +
var g = r;
 +
}
 +
else
 +
{var r = f1.ReadLine(); //This line will read the data to the input file
 +
}
 +
/*var r = f1.ReadLine(); //This line will read the data to the input file
 +
document.write (r + "<br />"); //This line will display the data on the screen
 +
f2.WriteLine(r); //This line will write the data to the output file*/
 +
}
 +
f1.Close();
 +
f2.Close();
 +
</script>
 +
</head>
 +
<body>
 +
<input type="button" value="Get count" onClick="getCount()">
</body>
</body>
</html>
</html>
 +
 +
Reply With Quote

Revision as of 09:45, 2 September 2013

Read from Excel or Access

Reply With Quote