通过PHP在Excel文件中设置文本格式 [英] Format text in Excel file via PHP

查看:564
本文介绍了通过PHP在Excel文件中设置文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从数据库中加载数据,并通过在此站点上找到的方法导出到Excel文件:

I'm loading data from my database, and exporting to an Excel file via a method I found on this site: http://www.appservnetwork.com/modules.php?name=News&file=article&sid=8

它可以工作,但是我现在要做的是在导出之前对文本进行格式化-更改字体和文本大小.有人对如何执行此操作有任何想法吗?

It works, but what I want to do now is format the text before it exports - change the font and text size. Does anybody have any ideas on how to do this?

推荐答案

根据您希望部署解决方案的速度,一种方法是只使用HTML table标记,使用样式标记将所有数据存储在表中,然后使用PHP标头的选项强制浏览器将其另存为.xls文件.

Depending on the speed in which you wish to deploy your solution, one method is to just use the HTML table tag, store all your data in tables using style markup, and then use PHP header's option to force the browser to save is as a .xls file.

为进行概念验证,请将此代码复制到记事本中,另存为.xls,然后使用Excel打开:

For proof of concept, copy this code into notepad, save as .xls, and then open with Excel:

<table>
<tr><th>Column 1</th><th>Column 2</th></tr>
<tr><td style="font-size:200%">Answer 1</td><td style="color:#f00">Answer 2</td></tr>
<tr><td colspan="2" style="font-weight:bold">Answer 3 with 2 columns</td></tr>
</table>

它不是最优雅的解决方案,但绝对可以满足您的需求.

Its not the most elegant solution, but it will absolutely suit your needs.

这篇关于通过PHP在Excel文件中设置文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆