Click here to Skip to main content
15,067,250 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a csv file and then trying to put it in an existing excel file

While executing getting the below error. it is generating the csv

csv data

"Index"
"=HYPERLINK(""#10.124.0.0_27!A3"",""10.124.0.0_27"")"
"=HYPERLINK(""#10.124.0.32_27!A4"",""10.124.0.32_27"")"
"=HYPERLINK(""#10.124.0.64_27!A5"",""10.124.0.64_27"")"
"=HYPERLINK(""#10.124.1.0_26!A6"",""10.124.1.0_26"")"
"=HYPERLINK(""#10.124.1.128_26!A7"",""10.124.1.128_26"")"
"=HYPERLINK(""#10.124.1.192_26!A8"",""10.124.1.192_26"")"


Add-Worksheet : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its 
properties do not match any of the parameters that take pipeline input.
At C:\Program Files\WindowsPowerShell\Modules\ImportExcel\7.2.2\Public\Export-Excel.ps1:129 char:26
+             $ws = $pkg | Add-Worksheet @params
+                          ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (OfficeOpenXml.ExcelPackage:PSObject) [Add-Worksheet], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Add-Worksheet
 
Could not get worksheet Index
At C:\Program Files\WindowsPowerShell\Modules\ImportExcel\7.2.2\Public\Export-Excel.ps1:135 char:16
+         catch {throw "Could not get worksheet $WorksheetName"}
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Could not get worksheet Index:String) [], RuntimeException
    + FullyQualifiedErrorId : Could not get worksheet Index


Please let me know what is the issue with this line

PowerShell
Import-Csv -Path "E:\Index.csv" | Export-Excel -Path "E:\ipaddress.xlsx" -WorkSheetname 'Index' -MoveToStart


What I have tried:

PowerShell
foreach($data in $WorkSheetNames)
{
    $obj = New-Object PSObject
    $final_data ="=HYPERLINK(`"#" + $data + "!A" +$count + """"+ "," + """" + "$data" + """)"

    if($final_data -match "Index")
    {
    }
    else
    {
    Add-Member -InputObject $obj -MemberType NoteProperty -Name "Index" -Value $final_data
    }
    $table +=$obj
    $count++
    
}
$table | Export-Csv -Path "E:\Index.csv" -Append -NoTypeInformation
#=HYPERLINK("#10.124.0.0_27!A2","10.124.0.0_27")
Import-Csv -Path "E:\Index.csv" | Export-Excel -Path "E:\ipaddress.xlsx" -WorkSheetname 'Index' -MoveToStart
Posted
Comments
Richard MacCutchan 13-Aug-21 9:40am
   
The error message suggests a parameter is missing. Check the documentation or help for both the Import-Csv and Export-Excel cmdlets.
Empty Coder 13-Aug-21 11:42am
   
That's what i am not able to figure it out what is missing. it worked previously but suddenly stopped working. havn't done any changes
Richard MacCutchan 13-Aug-21 11:55am
   
Sorry, I have not used that package, so have no idea what parameters, or what format data, it requires.
You could try just running the Import-Csv cmdlet to see if the data is in the correct format
Empty Coder 13-Aug-21 12:00pm
   
Import-csv is fine. it is generating the data as mentioned in the question. issue is with the Export-Excel part.
Richard MacCutchan 13-Aug-21 12:32pm
   
Is there a home site for it that might help?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900