js读取excel文件内容|怎么用js将excel中的数据读取后显示到网页中的表格

js读取excel文件内容|怎么用js将excel中的数据读取后显示到网页中的表格的第1张示图

㈠ 怎么用js将excel中的数据读取后显示到网页中的表格

以前读书的时候绝不会想到会用客户端脚本来实现这些功能,现在却一开始就要用上了,而且还觉得挺实用的。参考《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 SheetNamevar strSheetName = "Sheet1$";var rsTemp = new ActiveXObject("ADODB.Recordset");rsTemp = objCon.OpenSchema(20);if(!rsTemp.EOF)strSheetName = rsTemp.Fields("Table_Name").Value;rsTemp = nullrsExcel = 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 fileobjCon.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..com/netcorner/blog/item/4c35a818788f670635fa41d3.html通过Javascript操作Excelfunction 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;//指定要写入的数据源的idvar 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 SheetNamevar strSheetName = "Sheet1$";var rsTemp = new ActiveXObject("ADODB.Recordset");rsTemp = objCon.OpenSchema(20);if(!rsTemp.EOF)strSheetName = rsTemp.Fields("Table_Name").Value;rsTemp = nullrsExcel = 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 fileobjCon.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..com/netcorner/blog/item/4c35a818788f670635fa41d3.html通过Javascript操作Excelfunction 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;//指定要写入的数据源的idvar 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>

㈡ js打开已有excel表格并进行内容替换

可以简单都用高级筛选来完成:鼠标定位到第二张表格的数据区域,数据菜单——高级筛选条件区域:第一张表的B列数据区域,勾选“将数据复制其他区域”,在第二张表的右侧第1行空白处放置筛选结果。点“确定”,得到筛选结果。PS:如果第2步中,不勾选“将数据复制其他区域”,则在原数据区域得到筛选结果,第1张表没有的厅店被隐藏。下面演示是一个类似的模拟

㈢ chrome浏览器下 js如何读取EXCEL内容。全部豆子求解

如果js能直接这么读客户端文件,互联网还有没有隐私可言呢?全部豆子捧上都没法用js直接去读本地的Excel文件的,和浏览器木有关系。文件上传也是传到服务器段在服务器本地读数据的。我建议你先了解一下js,Web相关的bulabula的东西,直接这样问问题,你的豆子很快就不够用了

㈣ 怎么用js将excel中的数据读取后显示到网页中的表格

1、进入Internet属性。

2、点击安全。

3、选择自定义级别。

4、把ActiveX控件和插件下的所有选项都改成启用。

5、服务器生成html格式的Excel,然后设置

㈤ JS读取excel,获取其中的单元格占多少行/列

获取行/列var colcount=wb.Worksheets(1).UsedRange.Cells.Rows.Count ;var colcolumn=wb.Worksheets(1).UsedRange.Columns.Count;读取本地Excel文件内容的Javascript代码:<script type="text/javascript">function read_excel(){ var filePath="D:\abcd9.com.xls"; //要读取的xls var sheet_id=2; //读取第2个表 var row_start=3; //从第3行开始读取 var tempStr=''; try{ var oXL = new ActiveXObject("Excel.application"); //创建Excel.Application对象 }catch(err) { alert(err); } var oWB = oXL.Workbooks.open(filePath); oWB.worksheets(sheet_id).select(); var oSheet = oWB.ActiveSheet; var colcount=oXL.Worksheets(sheet_id).UsedRange.Cells.Rows.Count ; for(var i=row_start;i<=colcount;i++){ if (typeof(oSheet.Cells(i,8).value)=='date'){ //处理第8列部分单元格内容是日期格式时的读取问题 d= new Date(oSheet.Cells(i,8).value); temp_time=d.getFullYear()+"-"+(d.getMonth() + 1)+"-"+d.getDate(); } else temp_time=$.trim(oSheet.Cells(i,7).value.toString()); tempStr+=($.trim(oSheet.Cells(i,2).value)+" "+$.trim(oSheet.Cells(i,4).value)+" "+$.trim(oSheet.Cells(i,6).value.toString())+" "+temp_time+"\n"); //读取第2、4、6、8列内容 } return tempStr; //返回 oXL.Quit(); CollectGarbage();}</script>

㈥ js遍历表格,内容读取到数组。

<html><head><title> just a test </title></head><script>function getTdContent(){var tab = document.getElementById("tab");var len = tab.cells.length;var arr = new Array();for(var i=0;i<len;i++){arr.push(tab.cells[i].innerText);}alert(arr);}function getRowContent(){var tab = document.getElementById("tab");var rownum = document.getElementById("rownum").value;var len = tab.rows[rownum-1].cells.length;var arr = new Array();for(var i=0;i<len;i++){arr.push(tab.rows[rownum-1].cells[i].innerText);}alert(arr);}</script> <body><table id="tab"><tr><td>01</td><td>02</td><td>03</td><td>04</td></tr><tr><td>05</td><td>06</td><td>07</td><td>08</td></tr><tr><td>09</td><td>10</td><td>11</td><td>12</td></tr></table><input id="rownum" /><button onclick="getRowContent()">获取指定行单元格内容</button><button onclick="getTdContent()">获取所有单元格内容</button> </body></html>

㈦ js读取excel一个单元格内容,然后显示在网页上。打开页面什么都不显示,请教!

Excel文件来,另存为Html格式,就知自道了Response.ContentType 是告诉浏览器,服务器传递过来的内容是什么格式这个值默认是text/html这个要在所有的客户机上设置浏览器权限,比如IE的修改方法:进入Internet属性=》安全=》自定义级别,把ActiveX控件和插件下的所有选项都改成启用因为js是客户端的,所以服务器不可能控制我一般是用服务器生成html格式的Excel,然后设置Response.ContentType = "application/vnd.ms-excel";Response.AppendHeader("Content-Disposition", "inline;filename=abc.xls");这样来下载excel,而且这样不用修改客户端的ie设置

㈧ js读取本地excel文件出现问题,这是咋回事

貌似js没有这种功能,做为客户端语言有限制。

㈨ 用js脚本怎么读取excel表格指定列的内容,然后写入到txt里面

楼主解决了吗 我没有查到方法

未经允许不得转载:山九号 » js读取excel文件内容|怎么用js将excel中的数据读取后显示到网页中的表格

赞 (0)