question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Borders on empty cells

See original GitHub issue

I’m trying to add borders on all cells, including empty ones. Here is the code I tried to use:

var borderStyles = {
  top: { style: "thin" },
  left: { style: "thin" },
  bottom: { style: "thin" },
  right: { style: "thin" }
};

worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
  row.eachCell({ includeEmpty: true }, function(cell, colNumber) {
    cell.border = borderStyles;
  });
});

I thought that using { includeEmpty: true } would do this for me, but it doesn’t seem to work, as you can see here:

screen shot 2016-03-11 at 9 00 02 pm

I want the gaps in between the sections to have borders as well. I made those gaps by doing addRow and passing it an empty object {}, could that be causing an issue?

Or is there any other way to get borders to appear on all cells?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

2reactions
HankMcCoycommented, Jun 9, 2016

I managed to get this working by tweaking the code locally. I hope to get a PR open by mid next week.

The basic problem is that there are several places in the codebase where it checks to see if a cell has a type of Enum.ValueType.Null and if it does, it doesn’t include it in the final render, presumably as an optimization. This is, of course, problematic when that cell still have styles applied to it, despite being empty.

The short summary of my local changes is that I:

  • Removed the if (cell.type != Enum.ValueType.Null) check in the get model() accessor in row.js
  • Removed the spans="<%=row.min%>:<%=row.max"> attribute in the row section of sheet.xml since I had a hard time getting the min and max there to actually work (spans is an optional optimization attribute anyway).
  • Added a default: case to the switch (cell.type) statement in xlsx.js to do the same thing it was already doing for case Enums.ValueType.Merge.
1reaction
edongashicommented, Mar 20, 2016

I am facing the same problem… I found a workaround by placing empty strings to force values on cells. It works this way, although it’s causing me trouble with cell merging in MS Excel

if (!cell.value) { cell.value = ‘’; }

Read more comments on GitHub >

github_iconTop Results From Across the Web

empty-cells - CSS: Cascading Style Sheets - MDN Web Docs
The empty-cells CSS property sets whether borders and backgrounds appear around cells that have no visible content.
Read more >
CSS Empty-cells Property - W3Schools
The empty-cells property sets whether or not to display borders on empty cells in a table. Note: This property has no effect if...
Read more >
empty-cells - CSS-Tricks
The empty-cells property in CSS selects empty table cells for the purpose of specifying whether or not to display borders and backgrounds on ......
Read more >
How to hide border and background on empty cells in a table ...
In this article, we will learn how to hide borders and backgrounds on empty cells in a table using CSS. The empty-cells property...
Read more >
Apply or remove cell borders on a worksheet - Microsoft Support
On a worksheet, select the cell or range of cells that you want to add a border to, change the border style on,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found