Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
1
Answer
Open and authenticate password protected Excel File
Yokeswaran G
3y
990
1
Reply
HI All,
I just want to open excel file before reading the uploaded excel file, i am using xlsx.read javascript API to read uploaded excel file, before that i need to open the file because the file is being password protected, i have shared the both concepts read excel file and open excel file can anyone please let me know how to open the using xlsx.read
Excel Reader using Javascript:
<html>
<input type=
"file"
id=
"fileUpload"
/>
<input type=
"button"
id=
"upload"
value=
"Upload"
onclick=
"UploadProcess()"
/>
<br/>
<div id=
"ExcelTable"
></div>
<script type=
"text/javascript"
src=
"https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.5/xlsx.full.min.js"
></script>
<script type=
"text/javascript"
src=
"https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.5/jszip.js"
></script>
<script type=
"text/javascript"
>
function
UploadProcess() {
//Reference the FileUpload element.
var
fileUpload = document.getElementById(
"fileUpload"
);
//Validate whether File is valid Excel file.
var
regex = /^([a-zA-Z0-9\s_\\.\-:])+(.xls|.xlsx)$/;
if
(regex.test(fileUpload.value.toLowerCase())) {
if
(
typeof
(FileReader) !=
"undefined"
) {
var
reader =
new
FileReader();
//For Browsers other than IE.
if
(reader.readAsBinaryString) {
reader.onload =
function
(e) {
GetTableFromExcel(e.target.result);
};
reader.readAsBinaryString(fileUpload.files[0]);
}
else
{
//For IE Browser.
reader.onload =
function
(e) {
var
data =
""
;
var
bytes =
new
Uint8Array(e.target.result);
for
(
var
i = 0; i < bytes.byteLength; i++) {
data += String.fromCharCode(bytes[i]);
alert(
"Data:"
+data)
}
GetTableFromExcel(data);
};
reader.readAsArrayBuffer(fileUpload.files[0]);
}
}
else
{
alert(
"This browser does not support HTML5."
);
}
}
else
{
alert(
"Please upload a valid Excel file."
);
}
};
function
GetTableFromExcel(data) {
//Read the Excel File data in binary
var
workbook = XLSX.open(data, {
type:
'binary'
});
//get the name of First Sheet.
var
Sheet = workbook.SheetNames[0];
//Read all rows from First Sheet into an JSON array.
var
excelRows = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[Sheet]);
//Create a HTML Table element.
var
myTable = document.createElement(
"table"
);
myTable.border =
"1"
;
//Add the header row.
var
row = myTable.insertRow(-1);
//Add the header cells.
var
headerCell = document.createElement(
"TH"
);
headerCell.innerHTML =
"Id"
;
row.appendChild(headerCell);
headerCell = document.createElement(
"TH"
);
headerCell.innerHTML =
"Name"
;
row.appendChild(headerCell);
headerCell = document.createElement(
"TH"
);
headerCell.innerHTML =
"Country"
;
row.appendChild(headerCell);
headerCell = document.createElement(
"TH"
);
headerCell.innerHTML =
"Age"
;
row.appendChild(headerCell);
headerCell = document.createElement(
"TH"
);
headerCell.innerHTML =
"Date"
;
row.appendChild(headerCell);
headerCell = document.createElement(
"TH"
);
headerCell.innerHTML =
"Gender"
;
row.appendChild(headerCell);
//Add the data rows from Excel file.
for
(
var
i = 0; i < excelRows.length; i++) {
//Add the data row.
var
row = myTable.insertRow(-1);
//Add the data cells.
var
cell = row.insertCell(-1);
cell.innerHTML = excelRows[i].Id;
cell = row.insertCell(-1);
cell.innerHTML = excelRows[i].Name;
cell = row.insertCell(-1);
cell.innerHTML = excelRows[i].Country;
cell = row.insertCell(-1);
cell.innerHTML = excelRows[i].Age;
cell = row.insertCell(-1);
cell.innerHTML = excelRows[i].Date;
cell = row.insertCell(-1);
cell.innerHTML = excelRows[i].Gender;
alert(row);
}
var
ExcelTable = document.getElementById(
"ExcelTable"
);
ExcelTable.innerHTML =
""
;
ExcelTable.appendChild(myTable);
};
</script>
</html>
Open or Download Excel File using Javascript:
<html>
<body>
<input type=
"button"
onclick=
"Upload()"
value=
"Open File"
>
<!--<input type=
"button"
onclick=
'window.open("test.xlsx")'
value=
"Open File"
>-->
<script type=
"text/javascript"
>
function
Upload() {
var
request =
new
XMLHttpRequest();
request.open(
"GET"
,
"C:\Users\user\Downloads\test.xlsx"
);
request.responseType =
"blob"
;
request.onload =
function
() {
// set `blob` `type` to `"text/html"`
var
blob =
new
Blob([
this
.response], {type:
"text/html"
});
var
url = URL.createObjectURL(blob);
window.open(url);
}
request.send();
}
</script>
</body>
</html>
I just want to open or authenticate before read an excel file, kindly let me know if any solution for this, thanks in advance.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Use Include in CSS.
Compilers for Website