# Omit Excel hidden rows

**URL:** <https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921>\
**Category:** Revit\
**Tags:** excel, dynamo\
**Created:** [November 18, 2024, 12:03pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921 "2024-11-18T12:03:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor01](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Victor01](https://forum.dynamobim.com/u/Victor01)\
**Post date:** [November 18, 2024, 12:03pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/1 "2024-11-18T12:03:53Z")

</div>

Hi all,

is there a way to omit importing hidden rows from an excel file?

Thank you.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [November 18, 2024, 12:29pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/2 "2024-11-18T12:29:49Z")

</div>

Not offhand. Programmatically the data is still there after all - hiding things is just a modification of the display (like hiding Revit elements). This means you’ll need to rely more heavily on the COM interop to attempt this which breaks more often than anyone likes.

So before progressing, can you outline ‘why’ and give some background?

It may be as simple as adding a range to what you return.

---

<div class="post-metadata">

**Author:** ![Victor01](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Victor01](https://forum.dynamobim.com/u/Victor01)\
**Post date:** [November 18, 2024, 12:52pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/3 "2024-11-18T12:52:23Z")

</div>

What i have are some notes in excel that I will import into Revit and I would like to be able to hide/unhide notes when importing. I don’t want to delete them since we might want to add them in the future.

I might try and move them beyond my export range and bring them back after.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [November 18, 2024, 2:24pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/4 "2024-11-18T14:24:31Z")

</div>

Instead of hiding them in excel, add another column for ‘include’ and just store a ‘yes’ or ‘no’ value in it. Setting up a data validation can help immensely here.

Then use that to filter the list in Excel - once marked no it won’t show up, but you can always edit the filters or even sort by ‘yes/no’ status to get to a particular note to toggle.

Then in Dynamo read everything and filter by the ‘yes’ value to get just the notes you want, and use the ‘in’ list to generate your content.

---

<div class="post-metadata">

**Author:** ![Victor01](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Victor01](https://forum.dynamobim.com/u/Victor01)\
**Post date:** [November 18, 2024, 2:26pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/5 "2024-11-18T14:26:26Z")

</div>

yeah, that’s what i’m doing now. will try and filter them by index.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [November 18, 2024, 2:35pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/6 "2024-11-18T14:35:33Z")

</div>

I’d use a boolean mask instead.

Depending on how your data is set up it could be as simple as `List.FilterByBoolMask(notes, include==“yes”)[“in”];`.

---

<div class="post-metadata">

**Author:** ![Victor01](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Victor01](https://forum.dynamobim.com/u/Victor01)\
**Post date:** [November 18, 2024, 2:45pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/7 "2024-11-18T14:45:19Z")

</div>

For some reason i’m getting this error and my filter by bool is not working.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/9/c998e73c732723776fba294a804c995367b22fbb.png)  
I can see it working, very strange

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [November 18, 2024, 3:18pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/8 "2024-11-18T15:18:08Z")

</div>

`null` isn’t valid for boolean comparison. You’ll need to replace the nulls or perhaps try an equality check with the `==` node (not the one with a tolerance, but the exact equality check).

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [November 18, 2024, 4:42pm UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/9 "2024-11-18T16:42:34Z")

</div>

A solution using openpyxl

- Dynamo 2.12 : [python package need to be installed](https://forum.dynamobim.com/t/how-to-install-python-modules-in-dynamo-core-runtime-2-8-0/52922)
- Dynamo 2.16+ : python package is installed by default

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/c/5c033e57d167f23e0ddf2482bf4e1e246182f4b1.png)

```auto
import sys
import clr
from openpyxl import load_workbook

xls_path = IN[0]
sheet_name = IN[1]

wb = load_workbook(xls_path) 
ws = wb[sheet_name]
data = []

for row in ws: 
    if ws.row_dimensions[row[0].row].hidden == False:
      data.append([cell.value for cell in row])
      
OUT = data

```

Another solution if you are comfortable with OpenXml

```auto
import clr
import sys
import System
from System import Array
from System.Collections.Generic import *

clr.AddReference('DocumentFormat.OpenXml')
import DocumentFormat
from DocumentFormat.OpenXml import *
from DocumentFormat.OpenXml.Packaging import *
from DocumentFormat.OpenXml.Spreadsheet import *

def ReadExcel(filepath, sheetName="", read_hidden_rows=True):
    lst_rows = []
    fileStream = System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)
    spreadsheetDoc = SpreadsheetDocument.Open(fileStream, False)
    try:
        workbookPart = spreadsheetDoc.WorkbookPart
        if System.String.IsNullOrEmpty(sheetName):
            sheet = workbookPart.Workbook.Sheets.GetFirstChild[Sheet]()
        else:
            sheet = next((s for s in workbookPart.Workbook.Sheets if s.Name.Value == sheetName), None)
        print(sheet)
        print([s for s in spreadsheetDoc.WorkbookPart.Workbook.Sheets])
        # get all sheet Name
        sheetsName = [s.Name.Value for s in spreadsheetDoc.WorkbookPart.Workbook.Sheets]
        print(sheetsName)
        worksheet = spreadsheetDoc.WorkbookPart.GetPartById(sheet.Id.Value).Worksheet
        #
        rows = worksheet.GetFirstChild[SheetData]().Elements[Row]()
        if read_hidden_rows :
            lst_rows = [row for row in rows]
        else:
            lst_rows = [row for row in rows if not (row.Hidden is not None and row.Hidden.Value)]
    except Exception as ex:
        print(ex)
        lst_rows = []
    finally:
        spreadsheetDoc.Close()
        fileStream.Dispose()
    # REST of code to be completed to read cell values
    # TODO
    # TODO 
    return [x.GetType().ToString() for x in lst_rows]
    
xls_file_path = IN[0]
sheet_name = IN[1]

OUT = ReadExcel(xls_file_path, sheet_name, read_hidden_rows=False)

```

---

<div class="post-metadata">

**Author:** ![Victor01](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Victor01](https://forum.dynamobim.com/u/Victor01)\
**Post date:** [November 19, 2024, 10:19am UTC](https://forum.dynamobim.com/t/omit-excel-hidden-rows/105921/10 "2024-11-19T10:19:07Z")

</div>

Thank you both. I went with “==” since I want other users to understand what’s going on in the script as well 🙂
