handsontable.js, the meged cell is not meged when use the downloadFile plugin

36 Views Asked by At

i want to export the table i generated the table cell is merged but when i export the file by useing the downloadFile plugin the file can be downloaded successfully but the cell is not merged,it become the raw data why?

this is my code

const container = document.getElementById('table-container');
  let table = new Handsontable(container, {
    data: [
      ['序号 ', '脱模角度 ', ' 纹理深度(μm) ', ' 纹理深度(μm) ', ' 纹理深度(μm) ', ' 纹理深度(μm) '], 
      ['序号 ', '脱模角度 ', '皮革纹 ', '几何纹 ', '梨地纹 ', '其他常用纹理 '], 
      ['1 ', '1° ', '13 ', '10 ', '15 ', '13 '], 
      ['2 ', '2° ', '26 ', '20 ', '20 ', '26 '], 
      ['3 ', '3° ', '39 ', '30 ', '30 ', '39 '], 
      ['4 ', '4° ', '52 ', '40 ', '40 ', '52 '], 
      ['5 ', '5° ', '65 ', '50 ', '50 ', '65 '], 
      ['6 ', '6° ', '78 ', '60 ', '60 ', '78 '], 
      ['7 ', '7° ', '91 ', '70 ', '70 ', '91 '], 
      ['8 ', '8° ', '104 ', '80 ', '80 ', '104 '], 
      ['9 ', '9° ', '117 ', '90 ', '90 ', '117 '], 
      ['10 ', '10° ', '130 ', '100 ', '100 ', '130 '], 
      ['11 ', '11° ', '143 ', '110 ', '—— ', '143 '], 
      ['12 ', '12° ', '156 ', '120 ', '—— ', '156 '], 
      ['13 ', '13° ', '—— ', '130 ', '—— ', '—— '], 
      ['14 ', '14° ', '—— ', '140 ', '—— ', '—— '], 
      ['15 ', '15° ', '—— ', '150 ', '—— ', '—— '], 
    ],
    mergeCells: [
      {'row': 0, 'col': 0, 'rowspan': 2, 'colspan': 1}, 
      {'row': 0, 'col': 1, 'rowspan': 2, 'colspan': 1}, 
      {'row': 0, 'col': 2, 'rowspan': 1, 'colspan': 4}
    ],
    rowHeaders: true,
    colHeaders: true,
    height: 450,
    className: 'htCenter htMiddle',
    stretchH: 'all',
    licenseKey: 'non-commercial-and-evaluation', // for non-commercial use only
  });
})

 const exportPlugin = table.getPlugin('exportFile');
  // export to downloadable file (named: MyFile.csv)
  exportPlugin.downloadFile('csv', {
    bom: true,
    columnDelimiter: ',',
    columnHeaders: false,
    rowHeaders:false,
    exportHiddenColumns: true,
    exportHiddenRows: true,
    fileExtension: 'csv',
    filename: 'Excel-[YYYY]-[MM]-[DD]',
    mimeType: 'text/csv',
    rowDelimiter: '\r\n',
  });
1

There are 1 best solutions below

1
ABudnik On

The Handsontable's ExportToFile plugin export only RAW data in the format of a CSV file. This means that formatting, comments, and styling is not attached. Merging is a form of cell formatting. If you'd like to have merged cells I would rather look for HTML > XLSX converted among the MIT projects on Github. Handsontable uses the COLSPAN/ROWSPAN for elements in the DOM so it should work well. You just need to remember to use renderAllRows: true and viewportColumnRenderingOffset: instance.countCols() to render all elements to the DOM.