@@ -64,55 +64,55 @@ Func _Example()
6464 WEnd
6565
6666 _NetWebView2_CleanUp($oWebV2M , $oJSBridge )
67- EndFunc ; ==>Main
67+ EndFunc ; ==>_Example
6868
6969#Region ; === UTILS ===
7070Func _Web_CSVViewer(ByRef $oWeb , $sFileData = " " )
71- ; 1. CSS - Dark Theme
72- Local $sCSS = " body { background-color: #2b2b2b; color: white; font-family: 'Segoe UI', sans-serif; margin: 0; padding: 0; }" & _
73- " .container { width: 100%; padding: 20px; box-sizing: border-box; }" & _
74- " h1 { font-size: 1.5rem; margin-bottom: 20px; color: #00CCFF; text-align: center; }" & _
75- " table { border-collapse: collapse; width: 100%; background: #333; box-shadow: 0 4px 8px rgba(0,0,0,0.5); }" & _
76- " th, td { border: 1px solid #444; padding: 12px 8px; text-align: left; }" & _
77- " th { background-color: #444; color: #00CCFF; position: sticky; top: 0; }" & _
78- " tr:nth-child(even) { background-color: #383838; }" & _
79- " tr:hover { background-color: #4a4a4a; }"
80-
81- ; 2. JavaScript - Preparing data for safe insertion into JS
82- Local $sSafeData = StringReplace ($sFileData , " \" , " \\" )
83- $sSafeData = StringReplace ($sSafeData , " '" , " \'" )
84- $sSafeData = StringReplace ($sSafeData , @CRLF , " \n" )
85- $sSafeData = StringReplace ($sSafeData , @LF , " \n" )
86-
87- Local $sJS = " const table = document.getElementById('table');" & @CRLF & _
88- " function renderCSV(csvData) {" & @CRLF & _
89- " if (!csvData) return;" & @CRLF & _
90- " const rows = csvData.split(/\n/);" & @CRLF & _
91- " let html = '';" & @CRLF & _
92- " rows.forEach((row, index) => {" & @CRLF & _
93- " if (row.trim() === '') return;" & @CRLF & _
94- " const cells = row.split(',');" & @CRLF & _
95- " html += '<tr>';" & @CRLF & _
96- " cells.forEach(cell => {" & @CRLF & _
97- " const tag = index === 0 ? 'th' : 'td';" & @CRLF & _
98- " html += `<${tag}>${cell.trim()}</${tag}>`;" & @CRLF & _
99- " });" & @CRLF & _
100- " html += '</tr>';" & @CRLF & _
101- " });" & @CRLF & _
102- " table.innerHTML = html;" & @CRLF & _
103- " }" & @CRLF & _
104- " if ('" & $sSafeData & " ' !== '') { renderCSV('" & $sSafeData & " '); }"
105-
106- ; 3. HTML Structure
107- Local $sHTML = " <html><head><meta charset='UTF-8'><style>" & $sCSS & " </style></head><body>" & _
108- " <div class='container'>" & _
109- " <table id='table'></table>" & _
110- " </div>" & _
111- " <script>" & $sJS & " </script>" & _
112- " </body></html>"
113-
114- ; 4. Loading - using NavigateToString to refresh all the content
115- $oWeb .NavigateToString($sHTML )
116- EndFunc
71+ ; 1. CSS - Dark Theme
72+ Local $sCSS = " body { background-color: #2b2b2b; color: white; font-family: 'Segoe UI', sans-serif; margin: 0; padding: 0; }" & _
73+ " .container { width: 100%; padding: 20px; box-sizing: border-box; }" & _
74+ " h1 { font-size: 1.5rem; margin-bottom: 20px; color: #00CCFF; text-align: center; }" & _
75+ " table { border-collapse: collapse; width: 100%; background: #333; box-shadow: 0 4px 8px rgba(0,0,0,0.5); }" & _
76+ " th, td { border: 1px solid #444; padding: 12px 8px; text-align: left; }" & _
77+ " th { background-color: #444; color: #00CCFF; position: sticky; top: 0; }" & _
78+ " tr:nth-child(even) { background-color: #383838; }" & _
79+ " tr:hover { background-color: #4a4a4a; }"
80+
81+ ; 2. JavaScript - Preparing data for safe insertion into JS
82+ Local $sSafeData = StringReplace ($sFileData , " \" , " \\" )
83+ $sSafeData = StringReplace ($sSafeData , " '" , " \'" )
84+ $sSafeData = StringReplace ($sSafeData , @CRLF , " \n" )
85+ $sSafeData = StringReplace ($sSafeData , @LF , " \n" )
86+
87+ Local $sJS = " const table = document.getElementById('table');" & @CRLF & _
88+ " function renderCSV(csvData) {" & @CRLF & _
89+ " if (!csvData) return;" & @CRLF & _
90+ " const rows = csvData.split(/\n/);" & @CRLF & _
91+ " let html = '';" & @CRLF & _
92+ " rows.forEach((row, index) => {" & @CRLF & _
93+ " if (row.trim() === '') return;" & @CRLF & _
94+ " const cells = row.split(',');" & @CRLF & _
95+ " html += '<tr>';" & @CRLF & _
96+ " cells.forEach(cell => {" & @CRLF & _
97+ " const tag = index === 0 ? 'th' : 'td';" & @CRLF & _
98+ " html += `<${tag}>${cell.trim()}</${tag}>`;" & @CRLF & _
99+ " });" & @CRLF & _
100+ " html += '</tr>';" & @CRLF & _
101+ " });" & @CRLF & _
102+ " table.innerHTML = html;" & @CRLF & _
103+ " }" & @CRLF & _
104+ " if ('" & $sSafeData & " ' !== '') { renderCSV('" & $sSafeData & " '); }"
105+
106+ ; 3. HTML Structure
107+ Local $sHTML = " <html><head><meta charset='UTF-8'><style>" & $sCSS & " </style></head><body>" & _
108+ " <div class='container'>" & _
109+ " <table id='table'></table>" & _
110+ " </div>" & _
111+ " <script>" & $sJS & " </script>" & _
112+ " </body></html>"
113+
114+ ; 4. Loading - using NavigateToString to refresh all the content
115+ $oWeb .NavigateToString($sHTML )
116+ EndFunc ; ==>_Web_CSVViewer
117117#EndRegion ; === UTILS ===
118118#EndRegion ; UDF TESTING EXAMPLE
0 commit comments