Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
to prevent excel file corruption, Set non-numeric data as a string ce…
…ll instead of a numeric type cell.

Note: if not, bad numeric type cell causes "(filename.xlsx)の一部の内容に問題が見つかりました。可能な限り内容を回復しますか?" in the Japanese version of Excel.
(English version perhaps "Excel found unreadable contents in (filename.xlsx). Do you want to recover the contents of this workbook?")
  • Loading branch information
hnx8 committed Jul 2, 2018
commit 342a04a0318b9b8c825490ab249fa35ca3b14eed
6 changes: 5 additions & 1 deletion xlsxwriter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ protected function writeCell(XLSXWriter_BuffererWriter &$file, $row_number, $col
} elseif ($num_format_type=='n_datetime') {
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="n"><v>'.self::convert_date_time($value).'</v></c>');
} elseif ($num_format_type=='n_numeric') {
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="n"><v>'.self::xmlspecialchars($value).'</v></c>');//int,float,currency
if (!is_string($value) || $value=='0' || ($value[0]!='0' && ctype_digit($value)) || preg_match("/^\-?(0|[1-9][0-9]*)?(\.[0-9]+)?$/", $value)){
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="n"><v>'.self::xmlspecialchars($value).'</v></c>');//int,float,currency
} else { //not numeric, treat it as string
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="inlineStr"><is><t>'.self::xmlspecialchars($value).'</t></is></c>');
}
} elseif ($num_format_type=='n_string') {
$file->write('<c r="'.$cell_name.'" s="'.$cell_style_idx.'" t="inlineStr"><is><t>'.self::xmlspecialchars($value).'</t></is></c>');
} elseif ($num_format_type=='n_auto' || 1) { //auto-detect unknown column types
Expand Down