如何使用PHP读取.xls文件(Excel) ?

时间:2023-01-15 12:40:54

I need to convert an .xls file to text, i dont need it formatted in any way. The file is filled with productids like PN-5098P, which i will preg_match_all to get.

我需要将.xls文件转换为文本,我不需要以任何方式格式化它。文件中填充了productids,如PN-5098P,我将preg_match_all获取它。

What is the simplest solution? I tried simply opening the file in a regular texteditor, the ids are not showing, so i guess i need some kind of binary converter?

最简单的解是什么?我试着在一个普通的texteditor中打开文件,id没有显示,所以我想我需要某种二进制转换器?

4 个解决方案

#1


14  

This is a good start:

这是一个良好的开端:

http://code.google.com/p/php-excel-reader/

http://code.google.com/p/php-excel-reader/

#2


6  

XLS is a complex proprietary format, and it might be difficult to work with. If you end up having trouble with libraries like Clint suggested, consider only accepting files in a more simpler format, like CSV, which is super-duper easy to deal with. If that solution is acceptable in this situation, it'll end up making your life much easier.

XLS是一种复杂的私有格式,可能很难使用它。如果您最终在使用Clint建议的库时遇到麻烦,请考虑只接受更简单格式的文件,比如CSV,它非常容易处理。如果这个解决方案在这种情况下是可以接受的,那么它最终会让你的生活变得更容易。

#3


6  

Newer versions of MS Office can output your spreadsheet directly in XML format. Here's an example of using such an XML-format spreadsheet directly from PHP:

更新版本的MS Office可以直接以XML格式输出电子表格。下面是一个直接从PHP使用xml格式电子表格的例子:

Otherwise, I've heard good things about PHPExcel:

除此之外,我还听说了PHPExcel的优点:

Here's one other link that might at least give you some additional ideas:

这里还有一个链接,至少可以给你一些额外的想法:

#4


1  

I convert my Excel sheets to MySQL using xls2mysql.com , but it isn't perfect. It doesn't recognize characters like -, /, é, ü, ô etc.. I've been working around this by converting those characters to a number in between hash tags (#4# for -) and unconverting them afterwards, but it is a bit of a hassle.

我使用xls2mysql.com将Excel表转换为MySQL,但它并不完美。它不能识别像-,/,e, u,等等的字符。我一直在解决这个问题,将这些字符转换为哈希标签之间的数字(#4# for -),然后再取消它们的转换,但这有点麻烦。

#1


14  

This is a good start:

这是一个良好的开端:

http://code.google.com/p/php-excel-reader/

http://code.google.com/p/php-excel-reader/

#2


6  

XLS is a complex proprietary format, and it might be difficult to work with. If you end up having trouble with libraries like Clint suggested, consider only accepting files in a more simpler format, like CSV, which is super-duper easy to deal with. If that solution is acceptable in this situation, it'll end up making your life much easier.

XLS是一种复杂的私有格式,可能很难使用它。如果您最终在使用Clint建议的库时遇到麻烦,请考虑只接受更简单格式的文件,比如CSV,它非常容易处理。如果这个解决方案在这种情况下是可以接受的,那么它最终会让你的生活变得更容易。

#3


6  

Newer versions of MS Office can output your spreadsheet directly in XML format. Here's an example of using such an XML-format spreadsheet directly from PHP:

更新版本的MS Office可以直接以XML格式输出电子表格。下面是一个直接从PHP使用xml格式电子表格的例子:

Otherwise, I've heard good things about PHPExcel:

除此之外,我还听说了PHPExcel的优点:

Here's one other link that might at least give you some additional ideas:

这里还有一个链接,至少可以给你一些额外的想法:

#4


1  

I convert my Excel sheets to MySQL using xls2mysql.com , but it isn't perfect. It doesn't recognize characters like -, /, é, ü, ô etc.. I've been working around this by converting those characters to a number in between hash tags (#4# for -) and unconverting them afterwards, but it is a bit of a hassle.

我使用xls2mysql.com将Excel表转换为MySQL,但它并不完美。它不能识别像-,/,e, u,等等的字符。我一直在解决这个问题,将这些字符转换为哈希标签之间的数字(#4# for -),然后再取消它们的转换,但这有点麻烦。