導航:首頁 > 文件類型 > 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相關的資料

熱點內容
淘寶網路電話叫什麼 瀏覽:231
編程要讀哪些書 瀏覽:134
如何在手機上新建文件夾里添文件 瀏覽:292
先鋒w10刷安卓系統 瀏覽:787
java設置過期日期 瀏覽:114
新版本抖音怎麼看我的數據比例 瀏覽:946
什麼是3G網路3G的發展史 瀏覽:269
如何使用ps把圖片的文件大小弄小 瀏覽:880
安卓系統根目錄文件夾 瀏覽:900
手錶怎麼設置蜂窩網路 瀏覽:51
舊愛勾搭app還有嗎 瀏覽:141
日外語言編程軟體哪個好 瀏覽:950
小論文發表了但是數據錯誤怎麼辦 瀏覽:952
注冊表禁止啟動程序運行 瀏覽:705
網路優化總體流程圖 瀏覽:735
前端程序員簡歷模板 瀏覽:706
蜂巢積木編程機器人怎麼樣 瀏覽:561
微信小程序tips 瀏覽:117
油印文件有哪些 瀏覽:854
java線程買票案例 瀏覽:672

友情鏈接