{"id":110,"date":"2015-03-26T16:03:35","date_gmt":"2015-03-26T08:03:35","guid":{"rendered":"http:\/\/blog.qiaogen.com\/?p=110"},"modified":"2015-03-26T16:03:35","modified_gmt":"2015-03-26T08:03:35","slug":"phpexcel-%e5%8d%95%e5%85%83%e6%a0%bc%e5%8c%85%e5%90%abrichtext%e7%9a%84%e8%af%bb%e5%8f%96%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.sangqiao.com\/blog\/archives\/110","title":{"rendered":"PHPEXCEL \u5355\u5143\u683c\u5305\u542brichtext\u7684\u8bfb\u53d6\u95ee\u9898"},"content":{"rendered":"<p>ello.<\/p>\n<p>When i use some style in cell like color, font size,&#8230; then an error returned among the cell value.<\/p>\n<p>I use PHPExcel in this way:<\/p>\n<p>require_once &#8216;include\/excel\/PHPExcel\/IOFactory.php&#8217;;<br \/>\n$objReader = PHPExcel_IOFactory::createReader(&#8216;Excel5&#8217;);\/\/use excel5<br \/>\n$objPHPExcel = $objReader-&gt;load($_FILES[&#8216;excelfile&#8217;][&#8216;tmp_name&#8217;]);<br \/>\n$FAValue = ($objPHPExcel-&gt;getActiveSheet()-&gt;getCell(&#8216;A&#8217;.$i)-&gt;getvalue());<\/p>\n<p>The returened value to $FAValue will be:<\/p>\n<p>__PHP_Incomplete_Class::__set_state(array(<br \/>\n&#8216;__PHP_Incomplete_Class_Name&#8217; =&gt; &#8216;PHPExcel_RichText&#8217;,<br \/>\n&#8216;_richTextElements&#8217; =&gt;<br \/>\narray (<br \/>\n0 =&gt;<br \/>\n__PHP_Incomplete_Class::__set_state(array(<br \/>\n&#8216;__PHP_Incomplete_Class_Name&#8217; =&gt; &#8216;PHPExcel_RichText_TextElement&#8217;,<br \/>\n&#8216;_text&#8217; =&gt; &#8216;dsfsdf &#8216;,<br \/>\n)),<br \/>\n1 =&gt;<br \/>\n__PHP_Incomplete_Class::__set_state(array(<br \/>\n&#8216;__PHP_Incomplete_Class_Name&#8217; =&gt; &#8216;PHPExcel_RichText_Run&#8217;,<br \/>\n&#8216;_font&#8217; =&gt;<br \/>\n__PHP_Incomplete_Class::__set_state(array(<br \/>\n&#8216;__PHP_Incomplete_Class_Name&#8217; =&gt; &#8216;PHPExcel_Style_Font&#8217;,<br \/>\n&#8216;_name&#8217; =&gt; &#8216;Arial&#8217;,<br \/>\n&#8216;_size&#8217; =&gt; 10,<br \/>\n&#8216;_bold&#8217; =&gt; true,<br \/>\n&#8216;_italic&#8217; =&gt; false,<br \/>\n&#8216;_superScript&#8217; =&gt; false,<br \/>\n&#8216;_subScript&#8217; =&gt; false,<br \/>\n&#8216;_underline&#8217; =&gt; &#8216;none&#8217;,<br \/>\n&#8216;_strikethrough&#8217; =&gt; false,<br \/>\n&#8216;_color&#8217; =&gt;<br \/>\n__PHP_Incomplete_Class::__set_state(array(<br \/>\n&#8216;__PHP_Incomplete_Class_Name&#8217; =&gt; &#8216;PHPExcel_Style_Color&#8217;,<br \/>\n&#8216;_argb&#8217; =&gt; &#8216;FF000000&#8217;,<br \/>\n&#8216;_isSupervisor&#8217; =&gt; false,<br \/>\n&#8216;_parent&#8217; =&gt; NULL,<br \/>\n&#8216;_parentPropertyName&#8217; =&gt; NULL,<br \/>\n)),<br \/>\n&#8216;_parentPropertyName&#8217; =&gt; NULL,<br \/>\n&#8216;_isSupervisor&#8217; =&gt; false,<br \/>\n&#8216;_parent&#8217; =&gt; NULL,<br \/>\n&#8216;colorIndex&#8217; =&gt; 32767,<br \/>\n)),<br \/>\n&#8216;_text&#8217; =&gt; &#8216;sdfsdf&#8217;,<\/p>\n<p>Thanks in Advance<\/p>\n<p>&nbsp;<\/p>\n<p>Answer:<\/p>\n<p>This isn&#8217;t quite the same of styling of a cell&#8230;. it&#8217;s actually rich text styling of the cell content: test to see if $FAValue is an instance of a PHPExcel_RichText object, and if so then use the getPlainText() method (or simply cast to string, as PHPExcel_RichText has a magic __toString() method).<\/p>\n<p>&nbsp;<\/p>\n<p>\u53c2\u8003\uff1a<br \/>\nhttp:\/\/phpexcel.codeplex.com\/discussions\/353348<br \/>\nhttp:\/\/blog.csdn.net\/longxuu\/article\/details\/7480311<br \/>\nhttp:\/\/phpexcel.codeplex.com\/discussions\/34513 \u8fd9\u91cc\u6709\u5f88\u591a\u7b54\u6848:)(<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u6211\u7528\u4ee5\u4e0b\u65b9\u6cd5\u89e3\u51b3\u4e86\uff0c\u4ec5\u9650\u4e8e\u8bfb\u53d6\u3002<\/p>\n<p>If you need just the plain text then probably the right solution for you is to use <code>setReadDataOnly(true)<\/code> for the reader.<\/p>\n<p>Example:<\/p>\n<p><code>$reader = new PHPExcel_Reader_Excel2007();<br \/>\n$reader-&gt;setReadDataOnly(true);<\/p>\n<p>$PHPExcel = $reader-&gt;load('test.xlsx');<\/p>\n<p>$ws = $PHPExcel-&gt;getActiveSheet();<\/p>\n<p>\/\/ A1 contains Rich-Text<br \/>\necho $ws-&gt;getCell('A1')-&gt;getValue();<\/p>\n<p><\/code>It is important that you use the latest source found under &#8216;Source Code&#8217; as the behavior was changed after the release of PHPExcel 1.6.3. Until recently you would get Rich-Text even with <code>setReadDataOnly(true)<\/code>.<br \/>\n<a href=\"http:\/\/www.codeplex.com\/PHPExcel\/Thread\/View.aspx?ThreadId=34770\" rel=\"nofollow\">http:\/\/www.codeplex.com\/PHPExcel\/Thread\/View.aspx?ThreadId=34770<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ello. When i use some style in cell like color, font si [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts\/110"}],"collection":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":1,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":111,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/posts\/110\/revisions\/111"}],"wp:attachment":[{"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sangqiao.com\/blog\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}