Home  >  Article  >  Backend Development  >  How to convert php excel to html

How to convert php excel to html

藏色散人
藏色散人Original
2020-08-27 09:50:153486browse

How to convert php excel to html: first introduce the PHPExcel class library; then obtain an Excel file you want to convert; then instantiate a reading object; and finally instantiate it into a "PHPExcel_Writer_HTML" object.

How to convert php excel to html

Recommended: "PHP Video Tutorial"

Use PHP to convert excel to html for display

Recently I need to make a function to display excel on the page. Reading the data in excel is very simple, but how can I display it on the page and try to restore it 100%? After searching online for a long time, I couldn't find a good method (it seems that not many people want to do this function...). How to do it? The PHPExcel class library is so powerful, is there any solution in this regard? Just do it as soon as you think of it, and I really found the classes for converting HTML in PHPExcel: PHPExcel_Writer_HTML and PHPExcel_Reader_HTML. What I want to do now is to convert excel into HTML. Obviously we need to use PHPExcel_Writer_HTML (I have to say again here, PHPExcel is really powerful, 32 likes).

PHPExcel has encapsulated all relevant functions, so we can use them directly. The code is very simple, as follows:

$filename = '你想转化的excel文件.xls';
 
$objReader = new \PHPExcel_Reader_Excel5(); //实例化一个读取对象
 
$objWriteHTML = new \PHPExcel_Writer_HTML($objReader->load($filename));  //读取excel文件,并将它实例化为PHPExcel_Writer_HTML对象
 
//在页面上打印(这里会直接打印,没有返回值。需要返回值的童鞋请根据save()方法自行改写)
$objWriteHTML->save("php://output");

In this way, we can display excel on the page.

As for PHPExcel_Reader_HTML, it has the exact opposite function. It can convert HTML into excel. We won’t talk about how to use it here, please do your own research.

The above is the detailed content of How to convert php excel to html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn