以å读书çæ¶åç»ä¸ä¼æ³å°ä¼ç¨å®¢æ·ç«¯èæ¬æ¥å®ç°è¿äºåè½ï¼ç°å¨å´ä¸å¼å§å°±è¦ç¨ä¸äºï¼èä¸è¿è§å¾æºå®ç¨çã
åèãWindowsèæ¬ææ¯ãï¼åºè¯¥ä¼æä¸ç¹æ¶è·ã
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<script language="javascript" type="text/javascript">
function importXLS(fileName)
{
objCon = new ActiveXObject("ADODB.Connection");
objCon.Provider = "Microsoft.Jet.OLEDB.4.0";
objCon.ConnectionString = "Data Source=" + fileName + ";Extended Properties=Excel 8.0;";
objCon.CursorLocation = 1;
objCon.Open;
var strQuery;
//Get the SheetName
var strSheetName = "Sheet1$";
var rsTemp = new ActiveXObject("ADODB.Recordset");
rsTemp = objCon.OpenSchema(20);
if(!rsTemp.EOF)
strSheetName = rsTemp.Fields("Table_Name").Value;
rsTemp = null
rsExcel = new ActiveXObject("ADODB.Recordset");
strQuery = "SELECT * FROM [" + strSheetName + "]";
rsExcel.ActiveConnection = objCon;
rsExcel.Open(strQuery);
while(!rsExcel.EOF)
{
for(i = 0;i<rsExcel.Fields.Count;++i)
{
alert(rsExcel.Fields(i).value);
}
rsExcel.MoveNext;
}
// Close the connection and dispose the file
objCon.Close;
objCon =null;
rsExcel = null;
}
</script>
</head>
<body>
<input type="file" id="f" />
<input type="button" id="b" value="import" onclick="if(f.value=='')alert('请éæ©xlsæ件');else importXLS(f.value)" />
</body>
</html>
trackback:
http://hi.baidu.com/netcorner/blog/item/4c35a818788f670635fa41d3.htmléè¿Javascriptæä½Excel
function AutomateExcel()
{
// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
oXL.Visible = true;
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
// Add table headers going cell by cell.
oSheet.Cells(1, 1).Value = "First Name";
oSheet.Cells(1, 2).Value = "Last Name";
oSheet.Cells(1, 3).Value = "Full Name";
oSheet.Cells(1, 4).Value = "Salary";
// Format A1:D1 as bold, vertical alignment = center.
oSheet.Range("A1", "D1").Font.Bold = true;
oSheet.Range("A1", "D1").VerticalAlignment = -4108; //xlVAlignCenter
// Create an array to set multiple values at once.
// Fill A2:B6 with an array of values (from VBScript).
oSheet.Range("A2", "B6").Value = CreateNamesArray();
// Fill C2:C6 with a relative formula (=A2 & " " & B2).
var oRng = oSheet.Range("C2", "C6");
oRng.Formula = "=A2 & " " & B2";
// Fill D2:D6 with a formula(=RAND()*100000) and apply format.
oRng = oSheet.Range("D2", "D6");
oRng.Formula = "=RAND()*100000";
oRng.NumberFormat = "$0.00";
// AutoFit columns A:D.
oRng = oSheet.Range("A1", "D1");
oRng.EntireColumn.AutoFit();
// Manipulate a variable number of columns for Quarterly Sales Data.
DispalyQuarterlySales(oSheet);
// Make sure Excel is visible and give the user control
// of Excel's lifetime.
oXL.Visible = true;
oXL.UserControl = true;
}
<HTML>
<HEAD>
<TITLE>å°é¡µé¢ä¸æå®è¡¨æ ¼çæ°æ®å¯¼å
¥å°Excelä¸</TITLE>
<SCRIPT LANGUAGE="javascript">
<!--
function AutomateExcel()
{
var oXL = new ActiveXObject("Excel.Application"); //å建åºè¯¥å¯¹è±¡
var oWB = oXL.Workbooks.Add();//æ°å»ºä¸ä¸ªExcelå·¥ä½ç°¿
var oSheet = oWB.ActiveSheet;//æå®è¦åå
¥å
容çå·¥ä½è¡¨ä¸ºæ´»å¨å·¥ä½è¡¨
var table = document.all.data;//æå®è¦åå
¥çæ°æ®æºçid
var hang = table.rows.length;//åæ°æ®æºè¡æ°
var lie = table.rows(0).cells.length;//åæ°æ®æºåæ°
// Add table headers going cell by cell.
for (i=0;i<hang;i++){//å¨Excelä¸åè¡
for (j=0;j<lie;j++){//å¨Excelä¸åå
//å®ä¹æ ¼å¼
oSheet.Cells(i+1,j+1).NumberFormatLocal = "@";
//!!!!!!!ä¸é¢è¿ä¸å¥æ¯å°åå
æ ¼çæ ¼å¼å®ä¹ä¸ºææ¬
oSheet.Cells(i+1,j+1).Font.Bold = true;//å ç²
oSheet.Cells(i+1,j+1).Font.Size = 10;//åä½å¤§å°
oSheet.Cells(i+1,j+1).value = table.rows(i).cells(j).innerText;//ååå
æ ¼åå
¥å¼
}
}
oXL.Visible = true;
oXL.UserControl = true;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<table border="0" width="300" id="data" bgcolor="black" cellspacing="1">
<tr bgcolor="white">
<td>ç¼å·</td>
<td>å§å</td>
<td>å¹´é¾</td>
<td>æ§å«</td>
</tr>
<tr bgcolor="white">
<td>0001</td>
<td>å¼ ä¸</td>
<td>22</td>
<td>女</td>
</tr>
<tr bgcolor="white">
<td>0002</td>
<td>æå</td>
<td>23</td>
<td>ç·</td>
</tr>
</table>
<input type="button" name="out_excel" onclick="AutomateExcel();" value="导åºå°excel">
</BODY>
</HTML>
以å读书çæ¶åç»ä¸ä¼æ³å°ä¼ç¨å®¢æ·ç«¯èæ¬æ¥å®ç°è¿äºåè½ï¼ç°å¨å´ä¸å¼å§å°±è¦ç¨ä¸äºï¼èä¸è¿è§å¾æºå®ç¨çã
åèãWindowsèæ¬ææ¯ãï¼åºè¯¥ä¼æä¸ç¹æ¶è·ã
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<script language="javascript" type="text/javascript">
function importXLS(fileName)
{
objCon = new ActiveXObject("ADODB.Connection");
objCon.Provider = "Microsoft.Jet.OLEDB.4.0";
objCon.ConnectionString = "Data Source=" + fileName + ";Extended Properties=Excel 8.0;";
objCon.CursorLocation = 1;
objCon.Open;
var strQuery;
//Get the SheetName
var strSheetName = "Sheet1$";
var rsTemp = new ActiveXObject("ADODB.Recordset");
rsTemp = objCon.OpenSchema(20);
if(!rsTemp.EOF)
strSheetName = rsTemp.Fields("Table_Name").Value;
rsTemp = null
rsExcel = new ActiveXObject("ADODB.Recordset");
strQuery = "SELECT * FROM [" + strSheetName + "]";
rsExcel.ActiveConnection = objCon;
rsExcel.Open(strQuery);
while(!rsExcel.EOF)
{
for(i = 0;i<rsExcel.Fields.Count;++i)
{
alert(rsExcel.Fields(i).value);
}
rsExcel.MoveNext;
}
// Close the connection and dispose the file
objCon.Close;
objCon =null;
rsExcel = null;
}
</script>
</head>
<body>
<input type="file" id="f" />
<input type="button" id="b" value="import" onclick="if(f.value=='')alert('请éæ©xlsæ件');else importXLS(f.value)" />
</body>
</html>
trackback:
http://hi.baidu.com/netcorner/blog/item/4c35a818788f670635fa41d3.htmléè¿Javascriptæä½Excel
function AutomateExcel()
{
// Start Excel and get Application object.
var oXL = new ActiveXObject("Excel.Application");
oXL.Visible = true;
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
// Add table headers going cell by cell.
oSheet.Cells(1, 1).Value = "First Name";
oSheet.Cells(1, 2).Value = "Last Name";
oSheet.Cells(1, 3).Value = "Full Name";
oSheet.Cells(1, 4).Value = "Salary";
// Format A1:D1 as bold, vertical alignment = center.
oSheet.Range("A1", "D1").Font.Bold = true;
oSheet.Range("A1", "D1").VerticalAlignment = -4108; //xlVAlignCenter
// Create an array to set multiple values at once.
// Fill A2:B6 with an array of values (from VBScript).
oSheet.Range("A2", "B6").Value = CreateNamesArray();
// Fill C2:C6 with a relative formula (=A2 & " " & B2).
var oRng = oSheet.Range("C2", "C6");
oRng.Formula = "=A2 & " " & B2";
// Fill D2:D6 with a formula(=RAND()*100000) and apply format.
oRng = oSheet.Range("D2", "D6");
oRng.Formula = "=RAND()*100000";
oRng.NumberFormat = "$0.00";
// AutoFit columns A:D.
oRng = oSheet.Range("A1", "D1");
oRng.EntireColumn.AutoFit();
// Manipulate a variable number of columns for Quarterly Sales Data.
DispalyQuarterlySales(oSheet);
// Make sure Excel is visible and give the user control
// of Excel's lifetime.
oXL.Visible = true;
oXL.UserControl = true;
}
<HTML>
<HEAD>
<TITLE>å°é¡µé¢ä¸æå®è¡¨æ ¼çæ°æ®å¯¼å
¥å°Excelä¸</TITLE>
<SCRIPT LANGUAGE="javascript">
<!--
function AutomateExcel()
{
var oXL = new ActiveXObject("Excel.Application"); //å建åºè¯¥å¯¹è±¡
var oWB = oXL.Workbooks.Add();//æ°å»ºä¸ä¸ªExcelå·¥ä½ç°¿
var oSheet = oWB.ActiveSheet;//æå®è¦åå
¥å
容çå·¥ä½è¡¨ä¸ºæ´»å¨å·¥ä½è¡¨
var table = document.all.data;//æå®è¦åå
¥çæ°æ®æºçid
var hang = table.rows.length;//åæ°æ®æºè¡æ°
var lie = table.rows(0).cells.length;//åæ°æ®æºåæ°
// Add table headers going cell by cell.
for (i=0;i<hang;i++){//å¨Excelä¸åè¡
for (j=0;j<lie;j++){//å¨Excelä¸åå
//å®ä¹æ ¼å¼
oSheet.Cells(i+1,j+1).NumberFormatLocal = "@";
//!!!!!!!ä¸é¢è¿ä¸å¥æ¯å°åå
æ ¼çæ ¼å¼å®ä¹ä¸ºææ¬
oSheet.Cells(i+1,j+1).Font.Bold = true;//å ç²
oSheet.Cells(i+1,j+1).Font.Size = 10;//åä½å¤§å°
oSheet.Cells(i+1,j+1).value = table.rows(i).cells(j).innerText;//ååå
æ ¼åå
¥å¼
}
}
oXL.Visible = true;
oXL.UserControl = true;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<table border="0" width="300" id="data" bgcolor="black" cellspacing="1">
<tr bgcolor="white">
<td>ç¼å·</td>
<td>å§å</td>
<td>å¹´é¾</td>
<td>æ§å«</td>
</tr>
<tr bgcolor="white">
<td>0001</td>
<td>å¼ ä¸</td>
<td>22</td>
<td>女</td>
</tr>
<tr bgcolor="white">
<td>0002</td>
<td>æå</td>
<td>23</td>
<td>ç·</td>
</tr>
</table>
<input type="button" name="out_excel" onclick="AutomateExcel();" value="导åºå°excel">
</BODY>
</HTML>