问题
Uploading Excel file is ok and not an issue
gone through many articles on uloading excel to mysql Tried
http://phpexcel.codeplex.com/
http://sourceforge.net/projects/phpexcelreader/
https://stackoverflow.com/a/7889220/1026905 (really nice encoding class)
MY issue is i cannot upload the chracter seen in excel file as it is
superscript part is getting converted Example in
∴ tn = n² + 2n + 1 + 2
n² ... gets converted as it is
∴ .... get converted as it is
all characters like ∠Ωπ √ ∞ ≅⊥∫∪∴≈≡⊆μ I could get converted as it is
Only issue is tn, t1, t2, t3 i am unable to get n,1,2,3 as subscript (cannot be displayed here but you can view in the image
tn ... should be t<sub>n</sub>
... in html format n should be subscript
I am not getting this as it is
回答1:
Using PHPExcel, you can identify if a cell contains rich text because a getValue() call will return a PHPExcel_RichText object rather than a string/integer/float/boolean scalar type.
You can then loop through the collection of PHPExcel_RichText_Run objects for that PHPExcel_RichText object looking at the style associated with it:
$cellValueAsString = '';
$elements = $cell->getValue()->getRichTextElements();
foreach ($elements as $element) {
// Rich text start?
if ($element instanceof PHPExcel_RichText_Run) {
if ($element->getFont()->getSuperScript()) {
$cellValueAsString .= '<sup>';
} else if ($element->getFont()->getSubScript()) {
$cellValueAsString .= '<sub>';
}
}
// Convert UTF8 data to PCDATA
$cellText = $element->getText();
$cellValueAsString .= htmlspecialchars($cellText);
if ($element instanceof PHPExcel_RichText_Run) {
if ($element->getFont()->getSuperScript()) {
$cellValueAsString .= '</sup>';
} else if ($element->getFont()->getSubScript()) {
$cellValueAsString .= '</sub>';
}
}
}
would be a simple block of code to turn the rich text cell content into simple HTML markup showing superscripted and subscripted characters
来源:https://stackoverflow.com/questions/14544042/import-excel-file-with-subscript-character