I have the below script to compare two reports and generate output to excel, this is generating the output but just takes report 1 minus report 2 and generating the data with differences in Report2 and it doesn't generate with header. `
# Load the Excel COM object
$excel = New-Object -ComObject Excel.Application
# Disable alerts and screen updating for improved performance
$excel.DisplayAlerts = $false
$excel.ScreenUpdating = $false
# Open the two Excel sheets to compare
$originalWorkbook = $excel.Workbooks.Open("C:\Users\Conversion\Response_V2.csv")
$modifiedWorkbook = $excel.Workbooks.Open("C:\Users\Conversion\Response_V22.csv")
# Get the worksheets to compare
$originalWorksheet = $originalWorkbook.Worksheets.Item(1)
$modifiedWorksheet = $modifiedWorkbook.Worksheets.Item(1)
# Get the range of cells to compare (adjust the range as needed)
" $originalRange = $originalWorksheet.Range("A1:AE10")
" $modifiedRange = $modifiedWorksheet.Range("A1:AE10")
# Create a new Excel workbook to store the comparison results
" $resultsWorkbook = $excel.Workbooks.Add()
" $resultsWorksheet = $resultsWorkbook.Worksheets.Item(1)
# Compare the cells and copy the results to the new worksheet
" for ($row = 1; $row -le $originalRange.Rows.Count; $row++)
{
for ($col = 1; $col -le $originalRange.Columns.Count; $col++)
{
$originalValue = $originalRange.Item($row, $col).Value2
$modifiedValue = $modifiedRange.Item($row, $col).Value2
if ($originalValue -ne $modifiedValue)
{
$resultsWorksheet.Cells.Item($row, $col).Value2 = "$modifiedValue"
}
}
}
# Save the comparison results to a new Excel file
" $resultsWorkbook.SaveAs("C:\Users\Conversion\Response_V99.xlsx")
# Close all Excel workbooks and quit Excel
" $originalWorkbook.Close($false)
" $modifiedWorkbook.Close($false)
" $resultsWorkbook.Close($true)
"`your text` $excel.Quit()
Can you help to modify the code to generate report with the variance from both the files and with header?