1
- from dataclasses import dataclass
2
- from typing import List
1
+ # generate_xlsx_report.py
3
2
4
- import openpyxl
5
- from openpyxl .styles import Font , PatternFill , Alignment
3
+ from openpyxl import Workbook
4
+ from openpyxl .styles import Font , PatternFill , Alignment , Border , Side
6
5
from openpyxl .utils import get_column_letter
6
+ from typing import List , NamedTuple
7
+ import re
7
8
8
-
9
- @dataclass
10
- class ScanResult :
9
+ class ScanResult (NamedTuple ):
11
10
file_path : str
12
11
line_number : int
13
12
title : str
@@ -27,12 +26,9 @@ def severity_key(result: ScanResult):
27
26
28
27
29
28
def generate_xlsx_report (results : List [ScanResult ], output_file : str ):
30
- # Sort results by severity
31
- results .sort (key = severity_key )
32
-
33
- wb = openpyxl .Workbook ()
29
+ wb = Workbook ()
34
30
ws = wb .active
35
- ws .title = "Scan Results"
31
+ ws .title = "Security Scan Results"
36
32
37
33
# Define styles
38
34
header_font = Font (bold = True , color = "FFFFFF" )
@@ -93,17 +89,12 @@ def generate_xlsx_report(results: List[ScanResult], output_file: str):
93
89
# Save the workbook
94
90
wb .save (output_file )
95
91
96
-
97
- # Example usage
98
92
if __name__ == "__main__" :
99
- # Sample data
93
+ # Example usage
100
94
sample_results = [
101
- ScanResult ("file1.abap" , 10 , "CheckCrossSiteScripting" , "Potential XSS vulnerability" , "High" ),
102
- ScanResult ("file2.abap" , 25 , "CheckHardcodedCredentials" , "Hardcoded password detected" , "Critical" ),
103
- ScanResult ("file1.abap" , 50 , "CheckOSCommandInjection" , "Potential OS command injection" , "High" ),
104
- ScanResult ("file3.abap" , 100 , "CheckWeakCrypto" , "Use of weak cryptographic algorithm" , "Medium" ),
105
- ScanResult ("file4.abap" , 75 , "CheckInfoDisclosure" , "Potential information disclosure" , "Low" ),
95
+ ScanResult ("file1.abap" , 10 , "Potential XSS" , "Unsanitized input" , "High" ),
96
+ ScanResult ("file2.abap" , 25 , "SQL Injection" , "Dynamic SQL query" , "Critical" ),
97
+ # Add more sample results as needed
106
98
]
107
-
108
- generate_xlsx_report (sample_results , "security_scan_report.xlsx" )
109
- print ("XLSX report generated successfully." )
99
+ generate_xlsx_report (sample_results , "sample_security_scan_report.xlsx" )
100
+ print ("Sample report generated: sample_security_scan_report.xlsx" )
0 commit comments