MCPcopy Create free account
hub / github.com/breck7/scroll / _excelColWidth

Function _excelColWidth

external/.datatables.js:16035–16074  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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 = {

Callers 1

.datatables.jsFile · 0.85

Calls 4

indexOfMethod · 0.80
splitMethod · 0.80
sortMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected