|
|
|
@ -5,21 +5,22 @@ export const copyTable = async (rows: Row[], cols: ColumnType[]) => {
|
|
|
|
|
let copyHTML = '<table>' |
|
|
|
|
let copyPlainText = '' |
|
|
|
|
|
|
|
|
|
rows.forEach((row) => { |
|
|
|
|
rows.forEach((row, i) => { |
|
|
|
|
let copyRow = '<tr>' |
|
|
|
|
cols.forEach((col) => { |
|
|
|
|
cols.forEach((col, i) => { |
|
|
|
|
let value = (col.title && row.row[col.title]) ?? '' |
|
|
|
|
if (typeof value === 'object') { |
|
|
|
|
value = JSON.stringify(value) |
|
|
|
|
} |
|
|
|
|
copyRow += `<td>${value}</td>` |
|
|
|
|
copyPlainText = `${copyPlainText} ${value} \t` |
|
|
|
|
copyPlainText = `${copyPlainText}${value}${cols.length - 1 !== i ? '\t' : ''}` |
|
|
|
|
}) |
|
|
|
|
copyHTML += `${copyRow}</tr>` |
|
|
|
|
copyPlainText = `${copyPlainText.trim()}\n` |
|
|
|
|
if (rows.length - 1 !== i) { |
|
|
|
|
copyPlainText = `${copyPlainText}\n` |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
copyHTML += '</table>' |
|
|
|
|
copyPlainText.trim() |
|
|
|
|
|
|
|
|
|
const blobHTML = new Blob([copyHTML], { type: 'text/html' }) |
|
|
|
|
const blobPlainText = new Blob([copyPlainText], { type: 'text/plain' }) |
|
|
|
|