Php download excel files cannot be opened
Solutions and precautions for php excel files that cannot be opened after being downloaded
Php downloads excel files,
1. Do not output any non-file information, such as echo log information, during the download process. Otherwise, t
, generate an Excel file, and download it to the client
Advantages:1. There is a fixed format that looks nice (the DataGrid looks nice)
Limitations:1. It is not suitable for data exchange. It contains HTML code, which is messy and has no fixed format.2. The DataGrid cannot contain paging or sorting; otherwise, an error occurs.
Implementation Method:Response. Clear ();Response. Buffer = false;Response. chars
"] + "\ t" + Dr ["iage"]);}In addition, modify the output file extension to XLS.Method 3: Export HTML code from the DataGrid, generate an Excel file, and download it to the client
Advantages:1. There is a fixed format that looks nice (the DataGrid looks nice)
Limitations:1. It is not suitable for data exchange. It contains HTML code, which is messy and has no fixed format.2. The DataGrid cannot contain
better way, I just have to finish the demand on time. This returns the desired byte[]. The final step is to return to the stream in the response. @RequestMapping (value = "/xxx") public Void cell (HttpServletResponse response) throws Exception { byte[] bytes = Cellservice.selectexcel (); Response.setcontenttype ("Application/x-msdownload"); Response.setheader ("Content-disposition", "attachment;filename=" + uuidutil.getuuid () + ". xls"); Response.setcontentlengt
When exporting excel files in phpexcel, you cannot download the files using IE8. when you save the files as a dialog box, the IE 6 ie7 ie9 chrome ff is normal, that is, ie8 is unavailable, after clicking the export button, the "save" dialog box pops up and closes instantly. no solution was found after I checked it online.
You can see a solution in phpexcel:
If (strpos ($ _ SERVER ['http _ USER_AGENT '], 'ms
Jxl.jar jxls-core-0.9. 9. Jar jxls-reader-0.9. 9. Jar Poi-3.5-final.jar (must be more than 3.5 version) other jars are prompted to go to http://jarvana.com/jarvana/Find//Generate Excel Incoming template file The content generation file to generate returns the build file The full path
public static string Doexcel (string from, Map beans, string to) {
ServletContext sc = (ServletContext) actioncontext.g Etcontext (). Get (
servletactioncontext.servlet_c
T-code:smw0Only binary data is introduced here, and the HTML template is uploaded as well.Alternatively, you can use the CBO table to manage the file to see my other blog post: CBO table management file upload downloadSelect binaryWrite Package Name:Click New after enteringPress the input button after entering the object name and descriptionSelect FileUpload complete.If you are prompted for the following information.MIME types can be maintained.In the menu:Click the New button.Save it.Download:D
This article mainly introduces about PHP through the html-table form to complete the function of Excel download, has a certain reference value, now share to everyone, the need for friends can refer to
/** * @param $datas specific data * @param $titles column name * @param $filename file name * @param $extraMessage additional information */public static function Createexcel ($datas, $titles, $filename, $ext
Imports System
Imports System.Text
Namespace Toexcel
' Function: The datagrid in the ASP.net to generate Excel file downloads.
' Mountains improvement: 1, Support Chinese 2, hidden column does not show
' Date: 2002.10.30
Public Class Datagridtocsv
Public Function Generatefile (ByRef Page as System.Web.UI.Page, ByVal Mydatagrid as System.Web.UI.WebControls.DataGrid, ByVal FileName As String) as String
Dim resp as HttpResponse
Dim ColCount as Integer =
Because of the project requirements, you need to export the data as an Excel table, and you can choose to export items that you can download. The SPRING+MYBATIS+SPRINGMVC framework used by the project uses Apache POI to export Excel. Poi specific use please own Baidu. Words not much to say, on the code.
Exportexcelutil Code
Package com.rixin.common.util;
Im
{ $key=$keys[$k-1]; $value=$data[$j-1][$key]; } $objPHPExcel->setactivesheetindex (0) ->setcellvalue ($colname,$value); } } //Set column widths $objPHPExcel->getactivesheet ()->getcolumndimension (' C ')->setwidth (49); //Set Active sheet Index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setactivesheetindex (0); //Redirect output to a client ' s Web browser (EXCEL5)
Recently made grid list related data export to Excel function, export to Excel according to the column you choose and download to local. The download location is configured according to the configuration file. Nonsense does not say directly on the key code:Need to introduce the relevant packages:Compile ' net.sourcefor
php Solutions and considerations that cannot be opened after you download Excel, please refer to use PHP download Excel file, 1, in the process of downloading do not output any non-file information, such as Echo log information. Otherwise, the downloaded file cannot be opened, prompting for formatting errors or corru
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.