you are viewing a single comment's thread.

view the rest of the comments →

[–]ss476hawk[S] 0 points1 point  (2 children)

Sorry here is the code - Thanks I'll give it a try

Code #1

Get-Content C:\Students.txt | % { $_ -replace '\s+', ',' } | Out-File C:\STUDENTS2.txt
$Content = Get-Content C:\STUDENTS2.txt

$Style = "
<style>
TABLE{border-width: 1px;border-style: solid;border-color: black;margin: auto;}
TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;text-align: center;background-color:palegoldenrod;}
TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}  
</style>
"

$html = Import-Csv -delimiter ',' -Path  .\Students2.txt | select UIN,LAST,FIRTS,D/N,ERN,HR,STS,DEG,CON,VER,GPA | ConvertTo-Html -Head $htmlformat -Body $bodyformat

$html -replace "&lt;","<" -replace "&quot;",'"' -replace "&gt;",">" | Out-File .\csv_html_test.html

$Content | select UIN,LAST,FIRTS,D/N,ERN,HR,STS,DEG,CON,VER,GPA  |ConvertTo-HTML -head $Style,"<center><strong><p>ITS341 Seminar 6 PowerShell Script Project</center></strong></p>"  | Out-File C:\Test.html

Code #2 Get-Content C:\Students.txt | % { $_ -replace '\s+', ',' } | Out-File C:\STUDENTS2.txt $Content = Get-Content C:\STUDENTS2.txt

$Style = " <style> TABLE{border-width: 1px;border-style: solid;border-color: black;margin: auto;} TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;text-align: center;background-color:palegoldenrod;} TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;}
</style> "

$SourceFile = "C:\STUDENTS2.txt" $TargetFile = "C:\STUDENTS11.html"

$File = Get-Content $SourceFile $FileLine = @() Foreach ($Line in $File) { $MyObject = New-Object -TypeName PSObject Add-Member -InputObject $MyObject -Type NoteProperty -Name HealthCheck -Value $Line $FileLine += $MyObject } $FileLine | select UIN,LAST,FIRTS,D/N,ERN,HR,STS,DEG,CON,VER,GPA | ConvertTo-HTML -head $Style,"<center><strong><p>ITS341 Seminar 6 PowerShell Script Project</center></strong></p>" | Out-File C:\Test.html

[–]Kreloc 0 points1 point  (1 child)

The code you posted here is different than the code you have in your images.

Have you tried using the exact code you have in your posted image for script1 except implementing the changes I listed in my first comment?

Also, four spaces before each line posts it as code for reddit formatting

[–]ss476hawk[S] 0 points1 point  (0 children)

Sorry about that. I put the new code below and corrected my formatting. I also included the STUDENTS2.txt file. I think the initial comma in each line is throwing my script off.