* Get the width for an Excel column based on the contents of that column * @param {object} data Data for export * @param {int} col Column index * @return {int} Column width
(data, col)
| 16033 | * @return {int} Column width |
| 16034 | */ |
| 16035 | function _excelColWidth(data, col) { |
| 16036 | var max = data.header[col].length |
| 16037 | var len, lineSplit, str |
| 16038 | |
| 16039 | if (data.footer && data.footer[col] && data.footer[col].length > max) { |
| 16040 | max = data.footer[col].length |
| 16041 | } |
| 16042 | |
| 16043 | for (var i = 0, ien = data.body.length; i < ien; i++) { |
| 16044 | var point = data.body[i][col] |
| 16045 | str = point !== null && point !== undefined ? point.toString() : "" |
| 16046 | |
| 16047 | // If there is a newline character, workout the width of the column |
| 16048 | // based on the longest line in the string |
| 16049 | if (str.indexOf("\n") !== -1) { |
| 16050 | lineSplit = str.split("\n") |
| 16051 | lineSplit.sort(function (a, b) { |
| 16052 | return b.length - a.length |
| 16053 | }) |
| 16054 | |
| 16055 | len = lineSplit[0].length |
| 16056 | } else { |
| 16057 | len = str.length |
| 16058 | } |
| 16059 | |
| 16060 | if (len > max) { |
| 16061 | max = len |
| 16062 | } |
| 16063 | |
| 16064 | // Max width rather than having potentially massive column widths |
| 16065 | if (max > 40) { |
| 16066 | return 54 // 40 * 1.35 |
| 16067 | } |
| 16068 | } |
| 16069 | |
| 16070 | max *= 1.35 |
| 16071 | |
| 16072 | // And a min width |
| 16073 | return max > 6 ? max : 6 |
| 16074 | } |
| 16075 | |
| 16076 | // Excel - Pre-defined strings to build a basic XLSX file |
| 16077 | var excelStrings = { |
no test coverage detected