i am reading one xls file through java script.
function upload1()
{
var ControlCn = new ActiveXObject("ADODB.Connection");
var Conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\\TEST.xls;Persist Security Info=False;Extended Properties=Excel 8.0;";
ControlCn.Open(Conn);
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "select * from [Sheet1$]";
rs.Open(SQL, ControlCn);
if(rs.bof)
{
document.write('No Data Avaliable');
}
if(!rs.bof)
{
rs.MoveFirst()
while(!rs.eof)
{
for(var i=0; i!= rs.fields.count; ++i)
{
document.write(rs.fields(i).value + ", ");
}
document.write("<br />");
rs.MoveNext()
}
}
rs.Close();
ControlCn.Close();
}
In the third line we are giving path of the xls file that we want to read. Is it possible to dynamically fetch the excel file through one browse button<input type="flie" ...
You can try the below:
<input type="file" id="myexcelfile"/>
once the user browses the file, then you can get the path as below:
var filepath=document.getElementById("myexcelfile").value;
You can use the "filepath" variable in your code for passing the excel sheet name
Related
I try to download a pdf file from my sql database.
I display list from database. My purpose is get pdf file from link.
Because of loop "for" I don't know how to get a correct path to download it.
///FRONTEND CODE
<tr v-for="not in notatki">
<td>{{not.NotatkaId}}</td>
<td>{{not.NotatkaName}}</td>
<td>{{not.Przedmiot}}</td>
<td>{{not.DateOfJoining}}</td>
<td><a href="http://localhost:37924/api/Notatki/{{not.NotatkaFileName}}" download>Download File</a></td>
<td>
///API CODE
public JsonResult SaveFile()
{
try
{
var httpRequest = Request.Form;
var postedFile = httpRequest.Files[0];
string filename = postedFile.FileName;
var physicalPath = _env.ContentRootPath + "/Notatki/" + filename;
using (var stream = new FileStream(physicalPath, FileMode.Create))
{
postedFile.CopyTo(stream);
}
return new JsonResult(filename);
}
It is link with error
[1]: https://i.stack.imgur.com/H5fqW.png
I am currently creating a html page that would load a XLSX file from local directory and then convert it into an HTML table on the same page underneath it, but my current html page requires a user to browse their directory and open said file.
<html>
<input id = "fileUpload" type ="file" >
<input type="button" id="upload" value="Upload" onclick="Upload()"/>
<table id="dvExcel"></table>
<hr>
</html>
<script>
function Upload() {
//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) {
ProcessExcel(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]);
}
ProcessExcel(data);
};
reader.readAsArrayBuffer(fileUpload.files[0]);
}
} else {
alert("This browser does not support HTML5.");
}
} else {
alert("Please upload a valid Excel file.");
}
};
</script>
No - for security reasons it is not allowed to access local files from web pages without user interaction.
This will only work if you deploy a local application or something similar to the users PC.
This is my first attempt to prepare a dynamic pdf form in livecycle designer es4. In this form, there is an option to add and view attachment. As I have little experience in javascript coding, I went to the adobe forum and found a very good example here. I have done some changes in original code to run in my form. I can attach file successfully with this code. But my problem is that when I want to open file attachment in Acrobat Pro XI, it is showing below error instead of opening the file. This error is showing independent of file attachment type (e.g. .doc, .jpg, .txt and .pdf file).error image. Here is screenshot of security of Acrobat Pro XIscreenshot 1 screenshot 2 and file linkhere.
Below code is written in the form-
//Code for add button
// Get Import Name
var cName = AttachName.rawValue;
// Test for empty value
if(!/^\s*$/.test(cName))
{// Do Import
try{
var bRtn = event.target.importDataObject(cName);
if(bRtn)
{
var cDesc = AttachDesc.rawValue;
if(!/^\s*$/.test(cName))
{
var oAtt = event.target.getDataObject(cName);
oAtt.description = cDesc;
}
app.alert("File Attachment Successfully Imported",3);
}
else
app.alert("Unable to import File Attachment",0);
}catch(e){
app.alert("An Error Occured while Importing the File Attachment:\n\n" + e);
}
}
else
app.alert("Attachment name must be non-empty");
//code for populating dropdown list
this.rawValue = null;
this.clearItems();
var a = event.target.dataObjects;
if (a !== null) {
for (var i = 0; i < a.length; i++) {
this.addItem(a[i].name);
}
}
//code for open attachment button
var cName = AttachNameSel.rawValue;
//var nAction = ExportAction.rawValue;
try{
event.target.exportDataObject({cName:cName, nLaunch:2});
} catch(e) {
app.alert("An Error Occured while Exporting the File Attachment: " + cName + "\n\n" + e);
}
Any help from anyone in the community would be greatly appreciated.
Thanks
Tony
I am using html5 and javascript. I want to read the Excel file which is chosen by the user from the directory (using a file dialog) but all I know is to read an excel file by the given path:
function readdata(y,x) {
try {
var excel = new ActiveXObject("Excel.Application");
excel.Visible = false;
var excel_file = excel.Workbooks.Open("D:\\Test.xls");
// alert(excel_file.worksheets.count);
var excel_sheet = excel_file.Worksheets("Sheet1");
var data = excel_sheet.Cells(x, y).Value;
//alert(data);
drawWithexcelValue(data);
}
catch (ex) {
alert(ex);
}
return data;
}
This is what I have to read the excel file. Can any one help me to read a file by directory, or without giving the path of the file. I would also like to know how to show output from that.
Thanx in advance
Try the following code, it is a bit of a hack and it seems to work with IE7. However, it will not work with other browsers because they will not show the file path. Other browsers will also never be able to show the ActiveXObject (Excel).
<!DOCTYPE html>
<html>
<head>
<body>
<div id="divHidden" style="visibility: hidden; width: 0px; height: 0px">
<input type=file id="fileInput">
</div>
<input type=button value="click here to get a file" onclick="readdata(1,1);">
<script language=javascript>
function readdata(y,x) {
// Use the <input type='file'...> object to get a filename without showing the object.
document.all["fileInput"].click();
var fileName = document.all["fileInput"].value;
try {
var excel = new ActiveXObject("Excel.Application");
excel.Visible = false;
var excel_file = excel.Workbooks.Open(fileName);
var excel_sheet = excel_file.Worksheets("Sheet1");
// var data = excel_sheet.Cells(x, y).Value;
var data;
for (; excel_sheet.Cells(x, y).Value.length > 0; x++){
data[i][0] = excel_sheet.Cells(x, y).Value;
data[i][1] = excel_sheet.Cells(x, y+1).Value;
}
drawWithexcelValue(data);
}
catch (ex) {
alert(ex);
}
// This will show the data.
alert(data);
}
</script>
</body>
</html>
I am using a script to print a spreadsheet to PDF.I would like to print it to a location on the drive "PDF Folder". Anyone know how to do this?
Heres is my code :
function printpdf(){
var spreadsheet_id="0AkcI3cOVJXI3dHg3Nnk3Y2JUakViTkUzQzdXSUdLNEE";
var spreadsheetFile = DocsList.getFileById(spreadsheet_id);
var blob = spreadsheetFile.getAs('application/pdf');
DocsList.createFile(blob);
}
just add it to the folder like this :
(I reproduce the whole code)
function printpdf(){
var spreadsheet_id="0AkcI3cOVJXI3dHg3Nnk3Y2JUakViTkUzQzdXSUdLNEE";
var spreadsheetFile = DocsList.getFileById(spreadsheet_id);
var blob = spreadsheetFile.getAs('application/pdf');
var folder = DocsList.getFolder('PDF Folder'); //get the folder by its path
var pdf = DocsList.createFile(blob).addToFolder(folder);
}