I have 35 protected workbook. I'm using PHPExcel to extract information from respective excel files. Unfortunately, PHPExcel failed to load the file I suspect due to protected workbook. Here's my code:
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
Is there any workaround to enable PHPExcel to extract the information from protected workbook?
Thanks in advance.
Note that from version 1.8.0, PHPExcel does support reading protected Excel5 workbooks. It isn't covered in the documentation because you don't need to do anything special, PHPExcel simply decrypts the document as it reads it
Note that this doesn't apply to documents with a user password, but "VelvetSweatshop" protected documents
http://meindertjan.nl/2012/08/22/microsoft-offic-and-its-velvetsweatshop-password-protected-files/
In short, PHPExcel does not support protected sheets / workbook . See: http://phpexcel.codeplex.com/discussions/244865
Related
I use devexpress gridview export to export excel to a folder, I am able to export the excel file but i have no idea how to export the excel file to a specific folder. Can anyone guide me on this?
For example this is the code to export my gridview xlsx and it works fine
exportFeedbackGrid.WriteXlsToResponse()
and i wanted my xlsx file to export to the e:\filelocation, how can i achieve this?
<dx:ASPxGridViewExporter GridViewID="FeedbackGrid" ID="exportFeedbackGrid" OnLoad="ExportTo" runat ="server"></dx:ASPxGridViewExporter>
Public Sub ExportTo(sender As Object, e As EventArgs)
Dim stream As Stream = New FileStream("e:\filelocation", FileMode.Create)
exportFeedbackGrid.WriteXlsToResponse()
End Sub
Assumed exportFeedbackGrid is an ASPxGridViewExporter control, you may use standard I/O methods provided by System.IO namespace to handle output from grid exporter control before executing WriteXlsToResponse() method, as given in example below:
Public Sub ExportTo(sender As Object, e As EventArgs)
' write to specified folder
Using ms As New MemoryStream()
exportFeedbackGrid.WriteXls(ms)
ms.Seek(0, SeekOrigin.Begin)
Using stream As New FileStream(Server.MapPath("~/path/to/file/location/example.xls"), FileMode.Create, FileAccess.Write)
ms.WriteTo(stream)
End Using
End Using
' write as response
exportFeedbackGrid.WriteXlsToResponse()
End Sub
Notes:
The specified server's folder path must have enabled write access permission (i.e. permission to create files).
If you experiencing problems when assigning direct file path, consider using IIS virtual directory (also with enabled write permission to the physical path).
Reference:
ASPxGridViewExporter - How to save a file to a disk
I have this method here:
[Authorize]
[HttpPost]
[ValidateInput(false)]
public void ExportCostMatrixExcel(string GridHtmlExcel, string GridCommunityExcel)
{
Response.ClearContent();
Response.ClearHeaders();
Response.BufferOutput = true;
Response.ContentType = "application/excel";
Response.AddHeader("Content-Disposition", "attachment; filename=Reliquat.xlsx");
Response.Write(GridHtmlExcel);
Response.Flush();
Response.Close();
Response.End();
}
This takes me html table and converts it over to an Excel spreadsheet, when I try to open the file, I get this error message:
Excel cannot open the file 'Reliquat.xlsx' because the file format
or file extension is not valid. Verify that the file has not been
corrupted and that the file extension matches the format of the file.
Why is this happening, you can see GridHtmlExcel here on the link below, its an HTML table with colspans, is the colspans messing it up?
https://jsfiddle.net/2nyjhpaz/3/
In essence it looks like you're merely dumping the contents into a file and just renaming it to an XLSX. However, that extension follows a specific XML-based schema, and that's why it doesn't play well.
You have a few options:
Find a library that can do this for you - initial searches list a few but they're often fickle little beings.
Use something like HTML Agility Pack to parse the HTML into a usable format and write it into an excel file. You might have to create an excel file manually, possibly using the Office Interop stuff.
If the excel format itself isn't that much of an issue, you could choose to write a CSV file instead (and can be opened by excel), using CSV Helper - but you'd still have to parse the HTML.
our product is Aspose.Words for .NET
I have read this link http://www.aspose.com/docs/display/wordsnet/Licensing
We had implemented the aspose license previously (by former developer) in our web application.
this is our code for extracting document .
Imports Aspose.Words
Imports System.IO
Public Class Converter
Public Shared Sub ConvertDocument(ByRef docPath As String, ByRef expPath As String)
Dim license As New Aspose.Words.License()
license.SetLicense("Aspose.Words.lic")
Dim info As Aspose.Words.FileFormatInfo = FileFormatUtil.DetectFileFormat(docPath)
Dim format As String = info.LoadFormat.ToString().ToLower()
If Not format = "pdf" Then
Dim doc As New Aspose.Words.Document(docPath)
doc.Save(expPath)
Else
' This object will help us generate the document.
Dim builder As New DocumentBuilder()
' You might need to specify a different encoding depending on your plain text files.
Using reader As New StreamReader(docPath, Encoding.UTF8)
' Read plain text "lines" and convert them into paragraphs in the document.
Dim line As String = Nothing
line = reader.ReadLine()
Do While line IsNot Nothing
builder.Writeln(line)
line = reader.ReadLine()
Loop
End Using
builder.Document.Save(expPath)
End If
End Sub
End Class
All the setup for aspose was done. After that our aspose license expired and we did not upgraded that for a while. Then we again applied for a temporary license for 30 days.
Now we have the new license for next one year. What do I have to do to apply the new license. Is it ok if I just replace the old licence file ( Aspose.Words.lic) with the new license file ( Aspose.Words.lic)
Or do I need to change anything in the XML file (Aspose.Words.xml) inside Bin folder as well.
You do not need to change anything in XML file or license file. If you're accessing the license from a file, you can simply replace the old file with the new one.
If you're using the license as an embedded resource, you can remove existing resource and then embed the new license file as a resource.
I hope this helps.
Disclosure: I work at Aspose.
Okay, this might be a bit unusual. If there are better ways to do this (that are just as easy, I'm open to ideas). I found a while ago that I could open a web page consisting of a Gridview or a table, with titles, etc. as an excel file and it worked great! It formatted the Excel file with colors and alignment similar to the html from the page. With later versions of excel, though, it gives me a warning that the format time isn't valid before opening it, though it still seemed to work. So I tried changing the content type to a more current version of excel, but then I don't get anything at all. Here's what I have been doing (below).
Does anyone know how to change it so that I can open the page in a current version of Excel without getting the warning?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Response.AppendHeader("Content-disposition", "attachment; filename=Filename.xls")
Response.ContentType = "application/vnd.ms-excel"
End Sub
You are not creating an Excel file.
You are creating a HTML file with a .xls file extension. That's the wrong extension for a HTML file, and that's why Excel gives you a warning. The correct extension would be .html or .htm. Unfortunately, .html files don't automatically open in Excel, so changing the extension would require your users to manually open the file in Excel instead of just double-clicking it.
I'm afraid there's no easy way to solve this. We had the same problem, and we solved it by creating a real Excel file. There are lots of Excel libraries for .NET available. We used SpreadsheetLight, because it easily allows you to copy a DataTable to an Excel file and send that file to the web client.
I have a big problem with exporting my table to Excel file format.
Firstly I created code which runs on server and allows me to export data to Excel. Due to the fact that my table is created dynamically from the database there is nothing WITHIN the table at that stage, so no data were exported.
My second approach was targeting the final compiled table on the client side using either javascript or a very nice jQuery plugin called "DataTables" (www.datatables.net). Both of the attempts failed. Javascript seems to be to complex for me, plus it has difficulties running in Firefox, plugin on the other hand requires a very specific table structure which I am afraid I cannot provide.
So, a new idea of mine is: grab the page just after compiling and building it on the server, but before sending it to the browser. Target THE table and source its data using function on server. Finally export data to Excel, and send the page to the browser. Now. Is it possible? And if yes, then how?
I am beginner in programming world so any constructive suggestions and criticism would be highly appreciated. I would not mind any hard code examples ;)
You can try doing something like this:
protected void btnExport_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
//if you're exporting a table put the table in a placeholder and render
//the placeholder to the text writer here
grdJobs.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
What you need to do is export your query results in a .CSV file. CSV files can be opened in Excel no problem at all. http://wiki.asp.net/page.aspx/401/export-to-csv-file/ This shows you how to export into a .CSV format.
You're going to get a lot of suggestions instead of answers on this here. My recommendation would be to try the jQuery plugin: table2csv in order to create a more universal file format. But there are ways to target an actual Excel format, like this project.
If you want to export to actual XLS or XLSX instead of just CSV or something that just "opens" in Excel, there are third party tools that can help you with this. One example here:
http://www.officewriter.com