Skip to content

Instantly share code, notes, and snippets.

@MekDrop
Created January 6, 2016 22:10
Show Gist options
  • Save MekDrop/0c505cac8f7ad357edcd to your computer and use it in GitHub Desktop.
Save MekDrop/0c505cac8f7ad357edcd to your computer and use it in GitHub Desktop.
This script can be used to generate HTML content from Sheet. All structure of the result is defined as template.
REM ***** BASIC *****
Function ReplaceString(SearchWhat As String, ReplaceWith AS String, Content as string) as string
len1 = LEN(SearchWhat)
len2 = LEN(Content)
pos = InStr(Content, SearchWhat)
ret = Content
if pos <> 0 then
pos = pos -1
ret = LEFT$(Content, pos) + ReplaceWith + RIGHT$(Content, len2 - pos - len1)
ret = ReplaceString(SearchWhat, ReplaceWith, ret)
end if
ReplaceString = ret
End Function
rem Run This Sub
Sub Main
rem Change this HTML template to what you need
const template = "<div style=""display: flex;""><div style=""width: 4em; text-align: center; overflow: hidden;""><div style=""border-style: solid;width: 40px;height: 40px;border-radius: 50%;border-width: 1px;overflow: hidden; background-image: url('http://www.games.lt/w/user_foto/{id}.gif'),url('http://www.games.lt/w/user_foto/{id}.png'),url('http://www.games.lt/w/user_foto/{id}.jpg'),url('http://www.games.lt/i/profilis/nera_avataro.png'); background-size: cover; display: inline-block;""></div><div style=""font-size: 0.8em;"">{nick}</div></div><div style=""background-color: white; border-style: solid; display: block; width: 90%; border-width: 1px; border-radius: 7px; padding: 1em; margin-left: 1em; position: relative;""><div style=""border-style: solid; width: 1em; height: 1em; display: block; border-width: 1px; -ms-transform: rotate(45deg); -webkit-transform: rotate(45g); transform: rotate(45deg); border-right-style: none; border-top-style: none; left: -0.5em; position: absolute;background-color: white; ""></div><h3 style=""margin: 0;"">{game} (<a href=""{url}"">{platform}</a>)</h3></div></div><p><iframe width=""440"" height=""330"" src=""{video}"" frameborder=""0"" allowfullscreen></iframe></p><p>{content}</p>"
rem You can change sheet number here too
xSheet = ThisComponent.Sheets(1)
DIM ret as String
ret = ""
For I = 2 TO 11
# here goes logic what tags to replace
if xSheet.getCellByPosition(0,I - 1).String <> "" then
content = ReplaceString( "{game}", xSheet.getCellByPosition(0,I - 1).String, template )
content = ReplaceString( "{platform}", xSheet.getCellByPosition(1,I - 1).String, content )
content = ReplaceString( "{video}", xSheet.getCellByPosition(2,I - 1).String, content )
content = ReplaceString( "{content}", xSheet.getCellByPosition(3,I - 1).String, content )
content = ReplaceString( "{id}", xSheet.getCellByPosition(6,I - 1).String, content )
content = ReplaceString( "{url}", xSheet.getCellByPosition(5,I - 1).String, content )
content = ReplaceString( "{nick}", xSheet.getCellByPosition(7,I - 1).String, content )
ret = ret + content
end if
Next
Rem The result will be displayed in message box
MsgBox ret
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment