导航:首页 > 文件类型 > js获取文件夹里的excel

js获取文件夹里的excel

发布时间:2023-06-10 01:19:45

⑴ 怎么在js读取excel文件

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

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"));
//... });

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

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

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

⑷ jQuery/JavaScript 如何读取放在项目里的Excel

兄弟,你这个问题解决了没。我现在也遇到这个问题,如果解决了,求方法。

⑸ js怎样获取excel导出控件

一。导出Excel有两种:
1.
function ExportExcel(tableid){//读取表格中每个单元到EXCEL中
try
{
var curTbl = document.getElementById(tableid);
var oXL = new ActiveXObject("Excel.Application"); //创建AX对象excel
var oWB = oXL.Workbooks.Add(); //获取workbook对象
var oSheet = oWB.ActiveSheet; //激活当前sheet
var Lenr = curTbl.rows.length; //取得表格行数
for (i = 0; i < Lenr; i++){
var Lenc = curTbl.rows(i).cells.length; //取得每行的列数
for (j = 0; j < Lenc; j++){
oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText; //赋值
}
}
oXL.Visible = true; //设置excel可见属性
}
catch(e)
{
alert(e.message);
}
}
2:
function dataToExcel(tableid) {//整个表格拷贝到EXCEL中
var curTbl = document.getElementById(tableid);
var oXL;
try {
oXL = GetObject("", "Excel.Application");
}
catch (E) {
try {
oXL = new ActiveXObject("Excel.Application");
}
catch (E2) {
//alert("Please confirm:\n1.Microsoft Excel has been installed.\n2.Internet Options=>Security=>Setting \"Enable unsafe ActiveX\"");
alert("请确认:\n1.机器上Excel已经安装.\n2.Internet 选项=>安全=>Internet \"对没有标记为安全的ActiveX控件进行初始化和脚本运行,设定为启用\"");
return;
}
}
//创建AX对象excel
var oWB = oXL.Workbooks.Add();
//获取workbook对象
var oSheet = oWB.ActiveSheet;
//激活当前sheet
var sel = document.body.createTextRange();
sel.moveToElementText(curTbl);
//把表格中的内容移到TextRange中
sel.select();
//全选TextRange中内容
sel.execCommand("Copy");
//复制TextRange中内容
oSheet.Paste();
//粘贴到活动的EXCEL中
oXL.Visible = true;
//设置excel可见属性
}

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

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

⑺ JS 下载/导出 csv、excel、txt 、img等文件的方法总结

1. 调用后端接口导出文件

示例下载接口url https://gold-cdn.xitu.io/extension/0.3.9/package.crx

1.1 window.open(url)

会打开一个新窗口,开始下载后会自动关闭新窗口。Safair 下载后没有关闭新窗口。

Chrome、IE、Safair支持,貌似火狐不支持

1.2 window.location=url

在当前窗口下载

Chrome、Safair支持

1.3 iframe

在HTML中,iframe 的属性用src,但在JS中,只有部份浏览器支持修改src(读是没问题),真正通用的是要修改对应框架的href值。

1.4 <a href="url" download="filename">点击链接下载</a>

HTML5中给a标签增加了一个download属性,只要有这个属性,点击这个链接时浏览器就不在打开链接指向的文件,而是改为下载,目前只有chrome、firefox、opera、Edge支持。常用此方法点击下载图片。

IE既不支持a标签的download属性也不允许js调用a 标签的click方法。

2. 前端直接导出文件到本地

2.1 将数据转成DataURI用<a>标签下载

<a href="DataURI" download="filename">点击链接下载</a>

Data URI Scheme

Data URI Scheme是指可以在Web 页面中包含图片但无需任何额外的HTTP 请求的一类URI。 Data URI Scheme一般用于将经过base64编码的数据嵌入网页中,从而减少请求资源的链接数。IE8 之前的版本都不支持 data URI scheme。

DataURI的格式:

生成DataURI的方式

1. encodeURIComponent

使用这种方式,当数据过多时,URI长度容易超出浏览器限制。 encodeURIComponent常用来转码接口参数,为了避免服务器收到不可预知的请求,对任何用户输入的作为URI部分的内容都需要用encodeURIComponent进行转义。

2. URL.createObjectURL

URL.createObjectURL的参数是File对象或者Blob对象

IE10以下不支持URL.createObjectURL

2.2 windows.navigator.msSaveBlob IE10~Edge 专用

msSaveBlob 是IE10~Edge 私有方法。

2.3 execCommand

有的资料有提到IE9可以使用execCommand方法来保存数据到本地文件,但是我自己没有验证过,不知道是否可行。而且MDN文档中execCommand没有查到SaveAs命令。这块只是做个小记录。

js数据直接导出/下载数据到本地到方法总结

本文转载自:https://juejin.im/post/5cd00253518825418f6f2a8c?utm_source=gold_browser_extension

⑻ js 导 Excel

共分三步:
第一步:建立EXCEL.JS文件
====文件的代码=========
var idTmr = "";
function (tabid)
{
var oControlRange = document.body.createControlRange();
oControlRange.add(tabid,0);
oControlRange.select();
document.execCommand("Copy");
}
function toExcel(tabid){
(tabid);
try
{
var xls = new ActiveXObject( "Excel.Application" );
}
catch(e)
{
alert( "Excel没有安装或浏览器设置不正确.请启用所有Active控件和插件");
return false;
}
xls.visible = true;
var xlBook = xls.Workbooks.Add;
var xlsheet = xlBook.Worksheets(1);
xlBook.Worksheets(1).Activate;
for(var i=0;i<tabid.rows(0).cells.length;i++){
xlsheet.Columns(i+1).ColumnWidth=15;
}
xlsheet.Paste;
xls=null;
idTmr = window.setInterval("Cleanup();",1);
}
function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
}
================
第二步:在网页中引用EXCEL.JS,并声明一个表格ID
第三步:在网页中控件的ONCLICK事件中加入toExcel函数,将表格的ID作为参数传入
例如:
<input type="button" onclick="toExcel(t1)">
<table id="t1"> //为表格声明一个ID

希望上面的信息能给你带来帮助

阅读全文

与js获取文件夹里的excel相关的资料

热点内容
苹果12原装数据线怎么感觉有点硬 浏览:764
js获取div中的图片不显示不出来 浏览:291
什么网站有首映动漫 浏览:461
淘宝网络电话叫什么 浏览:231
编程要读哪些书 浏览:134
如何在手机上新建文件夹里添文件 浏览:292
先锋w10刷安卓系统 浏览:787
java设置过期日期 浏览:114
新版本抖音怎么看我的数据比例 浏览:946
什么是3G网络3G的发展史 浏览:269
如何使用ps把图片的文件大小弄小 浏览:880
安卓系统根目录文件夹 浏览:900
手表怎么设置蜂窝网络 浏览:51
旧爱勾搭app还有吗 浏览:141
日外语言编程软件哪个好 浏览:950
小论文发表了但是数据错误怎么办 浏览:952
注册表禁止启动程序运行 浏览:705
网络优化总体流程图 浏览:735
前端程序员简历模板 浏览:706
蜂巢积木编程机器人怎么样 浏览:561

友情链接