-
Notifications
You must be signed in to change notification settings - Fork 388
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
Help with getting a Table without Headers #1569
Comments
Sorry @NoralK, I have never tried to that nor have I seen it done. I believe you are the first 🎉 |
@dfinke Does this mean you will not look into it? |
@NoralK not for a while. I have other pressing matters. |
Hi @NoralK (CC: @dfinke) Try the following for size:
|
@pauljnav Thank you! for that nudge...I was able to come up with this complete solution: $xlSourcefile = "./theFile.xlsx"
$data = Import-Csv "./SingleColumnOfDataWithHeaderRow.csv"
$data | Export-Excel $xlSourcefile -WorksheetName "theSheet" `
-TableStyle None `
-AutoSize -StartRow 1 -StartColumn 6 `
-TableName "theTable"
$xl = Open-ExcelPackage $xlSourcefile
$ws = $xl.Workbook.Worksheets["theSheet"]
$TableRange = $ws.Tables["theTable"].Address.Address
# Original Range F1:F50
$RangeCells=$ws.cells[$TableRange]
# Define offset range, omitting row 1
# however this gives an extra row that we do not want.
# will product F2:F51
$offsetRange = $RangeCells.Offset(1, 0)
# Need F2:F50 - mash it together
$NewTableRange = "$($offsetRange.Start.Address):$($rangecells.End.Address)"
# Get the cells
$RangeWithoutHeaders = $ws.cells[$NewTableRange]
# Add the named range
# F2:F50
$xl.Workbook.Names.Add("theName", $RangeWithoutHeaders) | Out-Null
# Now I can reference theName[ColumnName] in the entire
# Workbook where theTable[ColumnName] has issues
Close-ExcelPackage $xl |
Glad Thanks all! |
I have look for hours trying to figure out how to get a Table Range back that does not include the table headers so I can add a named reference that has a scope of Workbook. I would use
-RangeName
when creating the Table but two issues with that, 1) the scope of the RangeName is the worksheet only and 2) the Range includes the headers. This is what I have:Please let me know and if there is a better way.
Cheers
The text was updated successfully, but these errors were encountered: