I am using jquery plugin tableExport.jquery.plugin to export html table.
Plugin is working fine.
I am using excel 2007.
Issue:
When I open Exported file it says
The file you are trying to open is in different format than specified by the file extension.etc
When I say yes it open the file and I can see my content.
But I don't need to see the warning that is coming up after opening.
// For BIFF .xls files
var data_type = 'data:application/vnd.ms-excel;filename=exportData.xls;' + base64data;
// For Excel 2007 and above .xlsx files
// var data_type = 'data:application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet;filename=exportData.xls;' + base64data;
I tried both above methods but It never worked.
There is no way to remove this warning if you are using jquery plugin or any plugin which export html as excel.
Its excel ability to open an HTML table in excel. Since file extension is .xls and file format is HTML. It will always show you this warning.
Its better to look for javascript library which actually create an xls file otherwise go for server side excel generation if you really want to remove this warning.
Related
Problem: I am unable to open a local Excel file using a file URL if the directory that the Excel file is in has spaces.
I have a local HTML file that has a link to open a local Excel file.
The files are in the same directory. The link is tied to a callback that uses the JavaScript function window.open() to open the Excel file URL, however, pasting the file URL directly into the browser address bar yields the exact same results.
I am not trying to download the Excel file, I want to open the given file in Excel externally in the Excel Windows application. I have Excel installed on my system. I am using a Chromium-based browser in Windows 10.
It works perfectly fine to open a local Excel file if the directory does not have spaces in it. The path I am using to do this is:
ms-excel:ofe|u|C:/folder_without_spaces/file_name.xlsx
However, if the directory has spaces in it, it does not work. The path I am using to do this is:
ms-excel:ofe|u|C:/folder with spaces/file_name.xlsx
I have tried converting the spaces to %20 and the result is the same. I have tried converting the spaces to + and the result is the same.
The error that I get when trying to open the Excel file with a directory that has spaces reads:
Sorry, we couldn't find C://folder%20with%20spaces/file_name.xlsx. Is it possible it was moved, renamed or deleted?
The error is always the same, regardless of if I substitute the space characters or not.
Why does this not work?
I am trying to export HTML table to xls format. But when I try to open the file using Excel, I am given a warning message. The waring message:
I using this lines of code:
var file = new Blob([ html.outerHTML], {
type: "application/vnd.ms-excel"
});
var url = URL.createObjectURL(file);
var filename = dateSelected + "-" + "attendance" + ".xls"
//here we are creating HTML <a> Tag which can be trigger to download the excel file.
var a = document.createElement('a');
a.id = "export";
document.body.appendChild(a);
//here we are checking if the bwoswer is IE or not if IE then we use window.navigator.msSaveBlob function otherwise Go with Simple Blob file.
if (window.navigator && window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(file, filename);
a.click();
document.body.removeChild(a);
document.body.removeChild(html);
} else {
a.download = filename;
a.href = url;
a.click();
document.body.removeChild(a);
document.body.removeChild(html);
}
I tried to change the blob type but nothing is working. How can i solve this issue?
The Problem
If you open the file in notepad or other text editor, you will find that what is saved in the file is html or xml. However, open any XLS file generated by Excel, and you will see unreadable binary characters.
Since Excel can open xml files, you don't feel that there's something wrong under the hood. However the *.xls format is binary in nature and is different from xml. Excel would warn you if the file extension doesn't match the underlying file format. Google for excel extension hardening and you would know what I'm talking about.
The Solution
You need to save it in that (excel binary) format if you want excel to recognize it as XLS file. There are so many libraries available (some paid and some free) that can help you generate true XLS files. I would recommend you using one of those. The other way is to switch to another format like XLSX. The problem would remain same though. Unless excel is able to match the file extension with the file format, it will continue to show this warning. This is a security measure.
AFAIK there's probably a registry hack to get around this problem. But I won't recommend you that, because it will open you to the security problem for which this feature is there in Excel.
I used the following code. I can download the file with extension .xls. When I open this downloaded file I receive this warning:
The file you are trying to open, 'Statement.xls', is in a different
format than specified by the file extension. Verify that the file is
not corrupted and is from a trusted source before opening the file. Do
you want to open the file now?
Javascript Code:
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.ms-excel;" });
saveAs(blob, "Statement.xls");`
HTML code:
`<table id="exportable">
<tbody>
<tr><th>ColumnOne</th><th>ColumnTwo</th><th>ColumnThree</th></tr>
<tr><td>row1Col1</td><td>row1Col2</td><td>row1Col3</td></tr>
<tr><td>row2Col1</td><td>row2Col2</td><td>row2Col3</td></tr>
<tr><td>row3Col1</td><td>row3Col2</td><td>test</td></tr>
</tbody>
</table>`
External library:
https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js
Office and Excel are able to cope with two different file formats. As those formats are totally different from the inside (the old one is binary, the new one is simply zipped up XML) different extensions and mimetypes were assigned to these formats.
Obviously you are creating a file with the new format and assign it the old extension. Excel complains about that.
Change your code to look like this:
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
saveAs(blob, "Statement.xlsx");
For the sake of learning you might want to have a look at your created file with a hex editor.
Others had similar issues, have a look here: https://github.com/eligrey/FileSaver.js/issues/139
When saving file with *.xls extension, file type should be set to "application/xls"
Since file type and extension will be matching, you shouldn't get any warning.
How can I create a blank file, (*.docx | *.ppt | *.xlsx), using OneDrive API?
I am using the following URL for creating a file.
PUT /drive/root:/{parent-path}/{filename}:/content
According to the documentation, the request body should consist of binary stream to be uploaded. Since I want to create a new file, I send a white space as content.
It works perfectly when I do for a *.txt file like,
PUT /drive/root:/myFilename.txt:/content
But it doesn't work for any of the other file formats mentioned above. It creates a file, but when I try to open it with either Word Online or local Word, it fails to open the file.
I've tried to send the content as plain text, html-formatted text, XML-formatted text. None of them seem to work.
Any ideas on how the body content should be formatted for the file formats mentioned above or am I doing this the wrong way? Is there another way to create blank files in OneDrive?
The OneDrive API does not support creating blank files.
As the formats of applications such as Microsoft Office are expanding and growing we would recommend you generate the file that you would like to upload first with the application that should open/modify it and then put that file on OneDrive.
This feature is available on the OneDrive website so users can quickly use the web editor experiences.
I have a decodification problem.
I have an offline desktop application, where I have to generate a pdf file and save at his open.
To generate the PDF file I use BytescoutPDF library createpdf.js.
This returns a document variable that I have to save.
I tried with:
//this calls the createPDF to BytescoutPDF library
//and returns the variable into 'doc'
var doc = generaStaticPartBolla_2();
//take the stream
var bolla = Ti.Filesystem.getFileStream(billPath);
//open in write mode
bolla.open(Ti.Filesystem.MODE_WRITE);
//write the doc file decodified in Base 64
bolla.write(doc.getBase64Text());
//close the stream
bolla.close();
Now, the file generated is currupted.
I'm not able to open this. How can I do this? The file must be converted in Base 64 or other?
I don't know if you have solved your issue now, but I had the same requirements : offline app, generating pdf from HTML, and in my case, styling the generated pdf with CSS.
After trying many solutions, the main problem was to style with CSS.
Finally I used WkhtmlToPdf (http://wkhtmltopdf.org/). Basically I embed the binaries (for mac os and for windows) in the app, and regarding the platform, I execute them with the Ti.Process method.
WkhtmlToPdf generates a pdf in the specified path, so in this way, you will be able to open this pdf.
(In order to set the path for the pdf, i use openSaveAsDialog (http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.UI.UserWindow-method-openFileChooserDialog) which allows the user to set the path and the name of the generated pdf).