Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel (.XLSX) files are not displaying properly if file has merge cell and empty cell #204

Open
rajeev-thinksys opened this issue Oct 27, 2021 · 1 comment

Comments

@rajeev-thinksys
Copy link

I have a solution for it and working fine.

Original parse method in /src/components/drivers/xlsx-viewer.jsx:

const dataArr = new Uint8Array(this.props.data);
const arr = [];

for (let i = 0; i !== dataArr.length; i += 1) {
  arr.push(String.fromCharCode(dataArr[i]));
}

const workbook = XLSX.read(arr.join(''), { type: 'binary' });
const names = Object.keys(workbook.Sheets);
const sheets = names.map(name => (
XLSX.utils.sheet_to_csv(workbook.Sheets[name])
));

return { sheets, names, curSheetIndex: 0 };

Instead of converting to .csv, you can use the sheet_to_html function of XLSX and then update the render method of xlsx-viewer driver component to render the content in a div.

Updated parse method of xlsx-viewer driver:

const dataArr = new Uint8Array(this.props.data);
const arr = [];

for (let i = 0; i !== dataArr.length; i += 1) {
  arr.push(String.fromCharCode(dataArr[i]));
}

const workbook = XLSX.read(arr.join(''), { type: 'binary', cellStyles: true, cellDates: true, cellHTML: true });
const names = Object.keys(workbook.Sheets);
const sheets = names.map(name => (
  XLSX.utils.sheet_to_html(workbook.Sheets[name], { blankRows: false, defval: '' })
));

return { sheets, names, curSheetIndex: 0 };

Updated render method of xlsx-viewer driver:

const { sheets, names, curSheetIndex } = this.state;
return (


{this.renderSheetNames(names)}
<div style={{ background: 'white' }} dangerouslySetInnerHTML={{ __html: sheets[curSheetIndex || 0] }} />

);

I think many people are experiencing the same issue. can add this fix for us.

@jack-hub-maker
Copy link

I did what you asked, but it didn't seem to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants