xlsx-style 行高設置


設置單元格高度

!rows,xlsx-style沒有提供這個功能,但是xlsx有這個功能,所以解決這個問題方法有
(1)使用xlsx pro版本
(2)修改xlsx源碼,給xlsx加上style功能
(3)修改xlsx-style源碼,給xlsx加上 !rows功能
基於復雜程度和貧窮程度,選擇(3)

步驟:
  1. 使用靜態文件替代import
    (1)將node_modules里的xlsx-style的文件夾下的
    xlsx.core.min.js拿出來放在靜態文件放置的文件夾下
    (2)index.html中引入
    <script src="<%= BASE_URL %>cdn/xlsx-style/xlsx.core.min.js" charset="utf-8"></script> 

(3)刪除import xlsxstyle代碼

2.修改xlsx.core.min.js

位置:
write_ws_xml_data

 

 

 完整版代碼如下:

https://files.cnblogs.com/files/yeminglong/xlsx.zip

function write_ws_xml_data(ws, opts, idx, wb) {
    var o = [],
      r = [],
      range = safe_decode_range(ws['!ref']),
      rowsHeight = ws['!rows'],
      cell,
      ref,
      rr = '',
      rh,
      cols = [],
      R, C
    for (C = range.s.c; C <= range.e.c; ++C) cols[C] = encode_col(C)
    for (R = range.s.r; R <= range.e.r; ++R) {
      r = []
      rr = encode_row(R)
      rh = -1
      hObj = rowsHeight[R]
      if (hObj && hObj.hpx) {
        rh = px2char(hObj.hpx)
      } else if (hObj && hObj.hch) {
        rh = hObj.hch
      }
      for (C = range.s.c; C <= range.e.c; ++C) {
        ref = cols[C] + rr
        if (ws[ref] === undefined) continue
        if ((cell = write_ws_xml_cell(ws[ref], ref, ws, opts, idx, wb)) != null) r.push(cell)
      }
      let p = {
        r: rr
      }
      if (rh > -1) {
        p.ht = char2height(rh)
        p.customHeight = 1
      }
      if (r.length > 0) o[o.length] = writextag('row', r.join(''), p)
    }
    return o.join('')
  }
function char2height(chr) { return 25; }

 

本文參考:https://www.cnblogs.com/coding-swallow/p/13433213.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM