导航:首页 > 文件类型 > js获取excel文件信息

js获取excel文件信息

发布时间:2023-01-21 17:48:26

㈠ 怎么用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 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..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..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>

㈡ js怎么获取 excel的数据

js怎么获取 excel的数据
在一个html页面生成的时候,js就已经把dom树创建好了
只要这棵树上有的数据,我们都可以通过js来获取使用
那么这个问题就变成js如何去查询dom树的节点了
js内置了以下几个查询节点的方法
document.getElementById("id") //通过id来获取一个dom元素
document.getElementsByName("name") //通过name属性来获取一个集合
document.getElementsByTagName("tag") //通过标签来获取一个集合
如果要查找的元素本身有id,通过第一个方法可以直接获取,当我们得到了这个dom节点的时候就可以输出他的一系列数据了
举个栗子
var dom = document.getElementById("id");
//如果是图片
alert(dom.src);
//如果该dom有class
alert(dom.className);
//如果该dom有value
alert(dom.value);
//如果该dom有文本
alert(dom.innerHTML);
//输出dom的style
alert(dom.style.width);
//等等
当dom没有id的时候,我们就要依靠一些条件去找到我们想要的dom了
//寻找所有class为bold的div
var c = document.getElementsByTagName("div"), len = c.length, r = [];
for(var i=0;i<len;i++){
if(c[i].className == 'bold'){
r.push(c[i]);
}
}
//当得到了这些dom节点后,就可以用上面提到的方法继续访问每个dom的数据啦

㈢ JavaScript 原生 提取excel文件 需要学习那些知识或者哪方面的,不要插件。最好有例子。

JavaScript is a versatile platform that allows easy customization of client-side scripting tools. In some applications, it's useful to have some sort of spreadsheet interface that is easy to code and maintain. TheSpreadJS client-side JavaScript spreadsheet component, part of the SpreadJS package, is perfect for this.

A JavaScript export to Excel

You can import and export Excel files, and provide users with an interface to interact with those files -- all in pure JavaScript. In this tutorial, I'll show you how easy it is to add a SpreadJS component to an HTML page and import an Excel file into it.

Set Up the JavaScript Spreadsheet Project

Create a new HTML page and add references to the Spread.Sheets script and the CSS files that are included in your SpreadJS download:

<!DOCTYPE html> <html> <head>
<title>SpreadJS ExcelIO</title>

<script src="http://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>

<link href="http://cdn.grapecity.com/spreadjs/hosted/css/gc.spread.sheets.excel2013white.10.1.0.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://cdn.grapecity.com/spreadjs/hosted/scripts/gc.spread.sheets.all.10.1.0.min.js"></script>
<script type="text/javascript" src="http://cdn.grapecity.com/spreadjs/hosted/scripts/interop/gc.spread.excelio.10.1.0.min.js"></script> </head> <body>
<div id="ss" style="height:600px ; width :100%; "></div> </body> </html>

Then add a script to the page that initializes the Spread.Sheets component, and a div element to contain it (since the SpreadJS spreadsheet component utilizes a canvas, this is necessary to initialize the component):


<script type="text/javascript">
$(document).ready(function () {
var workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
});
</script> </head> <body>
<div id="ss" style="height:600px ; width :100%; "></div> </body>

Add Excel Import Code

We need to create an instance of the client-side ExcelIO component that we can use to actually open the file:

var excelIO = new GC.Spread.Excel.IO();

Then we need to add a function to import a file. In this example, we import a local file, but you can do the same thing with a file on a server. If you’re importing a file from a server, you need to reference the location. The following is an example of an input element where the user can enter the location of the file:

<input type="text" id="importUrl" value="http://www.testwebsite.com/files/TestExcel.xlsx" style="width:300px" />

Once you have that, you can directly access that value in script code:

var excelUrl = $("#importUrl").val();

The following code for the import function just uses a local file for the "excelUrl" variable:

function ImportFile() {
var excelUrl = "./test.xlsx";

var oReq = new XMLHttpRequest();
oReq.open('get', excelUrl, true);
oReq.responseType = 'blob';
oReq.onload = function () {
var blob = oReq.response;
excelIO.open(blob, LoadSpread, function (message) {
console.log(message);
});
};
oReq.send(null);
}
function LoadSpread(json) {
jsonData = json;
workbook.fromJSON(json);

workbook.setActiveSheet("Revenues (Sales)");
}

Regardless of whether you're referencing a file on a server or locally, you'll need to add the following to your script inside the$(document).readyfunction:

$(document).ready(function () {
$.support.cors = true;
workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
//... });

你可以搜寻 黑体字 , 如果需要更详细的介绍

㈣ node.js解析excel大文件的问题

问题:使用 koa-bodyparser 可以解析post提交的问题,但是发现获取不到formdata上传的文件。
后经查资料,改用 koa-body 解决:
constkoaBody = require('koa-body'); app.use(koaBody({ multipart:true, formidable: { maxFileSize:200*1024*1024//设置上传文件大小最大限制,默认2M} }))
然后就可以在 ctx.request.files 里面获取到上传的 文件信息了。ctx.request.files 为一个对象,里面包含一个 file 字段(为你前端上传定义的值),值为文件信息,主要是文件name和path,path为临时存储路径。
二、解析xlsx文件信息
主要使用模块 node-xlsx :npm i xlsx --save
1、加载模块
使用模块:fs--主要用于写入文件;node-xlsx主要用于转换xlsx数据和读取xlsx的文件数据;
constfs = require('fs')constxlsx = require('node-xlsx');//读写xlsx的插件
2、读取功能
读取功能相对简单,直接使用模块的 prase(路径) 方法就能读取
let list = xlsx.parse("./doc/hello.xlsx");
返回结果,name:表名,data:二维数组。(由于Excel以表格的形式表示,因此表格的数据都是通过二维数组进行接收。)
需要注意的是:data里的第一行数组为表头的信息
[ { name:'firstSheet', data: [ [Array], [Array] ] }, { name:'secondSheet', data: [ [Array], [Array] ] } ]
3、写入功能
写入功能,对应的写入数据与上面读取功能的返回格式需要一致,以数组的形式,name:表名,data:二维数组(Excel每行每列的数据)
如下面代码,生成一个Excel文件,分别两张表,表名分别是firstSheet,secondSheet
let xlsxObj =[ { name:'firstSheet', data: [ [1,2,3], [4,5,6] ], }, { name:'secondSheet', data: [ [7,8,9], [10,1,12] ], } ]
生成Excel文件:
fs.writeFileSync(路径,Buffer数据)
xlsx.build(xlsxObj) 会将数组转换为Buffer数据
执行下面代码就会生成对应的Excel文件
fs.writeFileSync('./doc/hello.xlsx', xlsx.build(xlsxObj),"binary")

㈤ IE、谷歌如何通过js读取Excel中数据到Web页面的表格

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表格

https://www.cnblogs.com/liuxianan/p/js-excel.html

由 SheetJS 出品的js-xlsx是一款非常方便的只需要纯JS即可读取和导出excel的工具库,功能强大,支持格式众多,支持xls、xlsx、ods(一种OpenOffice专有表格文件格式)等十几种格式。本文全部都是以xlsx格式为例。

dist目录下有很多个JS文件,一般情况下用xlsx.core.min.js就够了,xlsx.full.min.js则是包含了所有功能模块。

JavaScript读取和导出excel示例(基于js-xlsx)

http://demo.haoji.me/2017/02/08-js-xlsx/

㈦ 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代码可以读取excel数据,有些地方不懂问一下您

这位仁兄,我建议你先去w3school去看下基础,先帮你改了

<script language="javascript" type="text/javascript">
var fileName = "D:\monkeyrunner\debugcase\Address\TestResult.xls";
importXLS(fileName);
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;
var strSheetName = "Sheet1$";
var rsTemp = new ActiveXObject("ADODB.Recordset");
rsTemp = objCon.OpenSchema(20);

㈨ 怎么在JS读取excel文件

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

㈩ js XLSX读取 excel 转换日期格式

前端读取excel 文件,excel内容展示在页面上,用户确认无误后再上传至后端,使用的XLSX来解析excel,读取日期的时候是数字。

excel数据解析出阿里云JSON数据如下:(tableDataJson)

阅读全文

与js获取excel文件信息相关的资料

热点内容
陕西回收贴片机如何编程 浏览:948
以前鲍鱼网站里的小说怎么没了 浏览:267
matlab程序如何调试 浏览:915
ps工程文件怎么发 浏览:95
word文件如何批量插入盖章 浏览:548
jscheckbox 浏览:338
pics规则文件 浏览:644
如何从数据中找出问题和机会 浏览:668
写作投稿在哪个网站好 浏览:895
绝代双骄版本 浏览:380
手机app在哪里找的对象靠谱吗 浏览:919
win10文件默认显示ck方式 浏览:829
如何更改桌面文件图标 浏览:418
word2010如何去掉背景 浏览:632
adp文件如何打开 浏览:531
ug编程怎么导出零件 浏览:586
asp在线文件管理系统 浏览:468
tks文件如何分解 浏览:132
java7tmd32位 浏览:49
网络公司关键词 浏览:925

友情链接