最近的項目中需要大量用到導出excel文件,這期間遇到兩個問題,1:身份證號導出之後在excel文件以科學計數法顯示,後面通過修改tableExport.js文件解決
導出.xls文件處理方法
//源文件
if (typeof tdcss == 'undefined' && typeof defaults.onMsoNumberFormat === 'function')
tdcss = defaults.onMsoNumberFormat(cell, row, col);
//修改之後
if (typeof tdcss == 'undefined' && typeof defaults.onMsoNumberFormat === 'function')
tdcss = defaults.onMsoNumberFormat(cell, row, col);
else
{
tdcss = '\\@';
}
導出.xlsx文件處理方法
//源文件
// Handle Value
if ( typeof defaults.onCellData !== 'function' ) {
// Type conversion
if ( cellValue !== "" && cellValue == +cellValue )
cellValue = +cellValue;
}
//修改之後
// Handle Value
if ( typeof defaults.onCellData !== 'function' ) {
// Type conversion
// if ( cellValue !== "" && cellValue == +cellValue )
// cellValue = +cellValue;
}
2:按照以上的方案處理,身份證不再以科學計數方式顯示。但是出現一個新問題,excel表格中的數字格式的數據不能進行選中計算,這導致在使用的時候很不方便計算,所以就行了第二次修改源文件
處理方案:1:將不需要轉換成數字的列通過指定的方式進行單獨處理成以字符串的格式顯示。
導出.xls文件處理方法
if (typeof tdcss == 'undefined' && typeof defaults.onMsoNumberFormat === 'function')
tdcss = defaults.onMsoNumberFormat(cell, row, col);
else
{
var index = defaults.displayStringColumn.indexOf(col);
if (index > -1)
tdcss = '\\@';
}
導出.xlsx文件處理方法
// Handle Value
if ( typeof defaults.onCellData !== 'function' ) {
var index = defaults.displayStringColumn.indexOf(col)
if (index == -1)
{
if (cellValue !== "" && cellValue == +cellValue)
cellValue = +cellValue;
}
}