• Announcements

Sign in to follow this  
Followers 0

_GUICtrlListView_SaveHTML() - Exports the details of a ListView to a .html file.

41 posts in this topic

Posted (edited) · Report post

For those who enjoy using ListViews and wish to export the data to a HTML file, then this Function is for you. Feel free to edit the style between the tags ; Start of StyleSheet & ; End of StyleSheet, plus please post if you have a better style to share :)

How it would look:
2191dnb.png

Function without Array:
Function with Array: - It uses another Function of mine called _GUICtrlListView_CreateArray()
Example use of Function without Array:
Download the ZIP file to obtain all exporting Examples. [attachment=41508:ListView Export.zip]

Update: 17/08/2011 - Added new theme. Thanks to tproli for the original HTML syntax with modifications by Lupo73.

Other Examples for exporting ListView data are: _GUICtrlListView_SaveCSV(), _GUICtrlListView_SaveTxt() & _GUICtrlListView_SaveXML()

If you want to create an array from the HTML file generated by _GUICtrlListView_SaveHTML() then use _GUICtrlListView_HTMLToArray(). Edited by guinness

Share this post


Link to post
Share on other sites



Posted · Report post

Hi guiness,

That's clever idea, I will have to test this out with thousands of items !!!

Thanks for sharing,

hench

Share this post


Link to post
Share on other sites

Posted · Report post

No, problem it works with how many items are in the ListView :) If you understand CSS and want to jazz it up then by all means! But please post the style here ;) Because currently the style is a little bland.

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

This might be what I'm looking for... Genius guinness

Is there any way to reverse it and load the data from the html? Edited by strikeraid

Share this post


Link to post
Share on other sites

Posted · Report post

This might be what I'm looking for... Genius guinness

Wow, thanks, Didn't realise anyone was going to use this.

Is there any way to reverse it and load the data from the html?

Should be easy enough to do with SRE etc. Might have a look in the next couple of days!

Share this post


Link to post
Share on other sites

Posted · Report post

Thanks! I bookmarked this page just in case. (: Glad I did. Saving to HTML would add variety; handy indeed.

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

I just updated the OP with a new and improved version of _GUICtrlListView_SaveHTML() which was previously called _GUICtrlListView_PrintOut(). Any suggestions for colour schemes would be much appreciated. Thanks. Edited by guinness

Share this post


Link to post
Share on other sites

Posted · Report post

Nice.
I think _GUICtrlListView_SaveHTML() would be more apropriate name.

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

True, I was just going with the same naming convention as my _GUICtrlListView_CreateArray(), but I will change it :huh2: Thanks Zedna. Edited by guinness

Share this post


Link to post
Share on other sites

Posted · Report post

Nice job. Why not make an array version of the conversion routines instead? You can just link to _GUICtrlListView_CreateArray(), or include it somehow.. seems a much nicer way to go, plus gives those of us with arrays an easier option. Would be pretty nice combined with my _DLLStructDisplay(). Hmm.. I think I'll take my advice and return an array as an option with that UDF.. *walks away muttering to self*

Share this post


Link to post
Share on other sites

Posted · Report post

I was planning in the next couple of days to create another version using _GUICtrlListView_CreateArray() which is what I normally do, but I know some people can be a little funny when they have to use alot of Functions in their Script. OR you can do what you muttered :huh2:

Share this post


Link to post
Share on other sites

Posted · Report post

You forgot to make seperate threads for XML, YAML, JSON, etc.etc.

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

You forgot to make seperate threads for XML, YAML, JSON, etc.etc.

XML! Nice suggestion, I will have a look at adding more formats in the following days. Thanks Manadar.

Also I didn't realise that I should have posted these under the same thread. I did it only for searching purposes. If Mod feels I have abused the Example Forum, then by all means consolidate these into a single thread. My intention wasn't to annoy anyone at all only provide productive examples and give back to the community :huh2: Edited by guinness

Share this post


Link to post
Share on other sites

Posted · Report post

XML! Nice suggestion, I will have a look at adding more formats in the following days. Thanks Manadar.

Should have left it at that. I can understand the desire to optimize for SEO.

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

OK! I genuinely thought I had abused/misread the rules of the Example Forum when it comes to posting related topics. Edited by guinness

Share this post


Link to post
Share on other sites

Posted · Report post

If you have your TXT,CSV versions of this function in separate topics
then add links to it in this topic so if somebody wants to see/download
all 3 HTML/TXT/CSV functions then he can do it simple.
Also add links to all functions to these other (TXT,CSV) topics.

Share this post


Link to post
Share on other sites

Posted · Report post

So after much feedback I've now released new versions across the "Export Series" that also uses my Function _GUICtrlListView_CreateArray(). (Thanks to Ascend4nt for the suggestion.) I've also attached a ZIP in all of the posts that includes both of the Examples (Array & non-Array) as well as all the various Export types in the series..

As Mat suggested I could create a large Function & using a "Flag" to determine which Export style should be used & of course I will probably do that very soon, but I want users to have a fair amount of choices with these Examples.

Note: I haven't updated the other sub-forums because I don't feel it's necessary this time :huh2:

Share this post


Link to post
Share on other sites

Posted · Report post

I didn't think I would need to update this, but after tproli created a wonderful theme using only CSS & HTML, I felt it was only right to upload. The HTML syntax is thanks to tproli with modifications by Lupo73. Enjoy! :mellow:

This is the default theme:
Posted Image

Share this post


Link to post
Share on other sites

Posted · Report post

If you want to create an array from the HTML file generated by _GUICtrlListView_SaveHTML() then use the following:

_GUICtrlListView_HTMLToArray:
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <Array.au3>

Global $aArray

$aArray = _GUICtrlListView_HTMLToArray("Export.html")
_ArrayDisplay($aArray)

Func _GUICtrlListView_HTMLToArray($sFile, $sDelimeter = "|")
	Local $aReturn[1][2] = [[0, 2]], $hFileOpen, $iColumnNumber = 0, $iColumnNumbers, $iDim = 0, $iOffSet, $iUbound, $sColumns, $sData

	$hFileOpen = FileOpen($sFile, 0)
	If $hFileOpen = -1 Then
		Return SetError(1, 0, $aReturn)
	EndIf
	$sData = FileRead($hFileOpen)
	FileClose($hFileOpen)

	$aArray = StringRegExp($sData, '(?s)(?i)<th>(.*?)</th>', 3)
	If @error Then
		Return SetError(1, 0, $aReturn)
	EndIf
	$iColumnNumbers = UBound($aArray, 1)
	For $A = 1 To $iColumnNumbers - 2
		$sColumns &= $aArray[$A] & $sDelimeter
	Next
	$sColumns = StringTrimRight($sColumns, StringLen($sDelimeter))

	$aArray = StringRegExp($sData, '(?s)(?i)<td>(.*?)</td>', 3)
	If @error Then
		Return SetError(1, 0, $aReturn)
	EndIf
	$iUbound = UBound($aArray, 1)

	$aReturn[0][1] = $iColumnNumbers - 1
	If $iColumnNumbers < 3 Then
		$aReturn[0][1] = 3
		$iDim = 3 - ($iColumnNumbers - 1)
	EndIf
	ReDim $aReturn[$iUbound][($iColumnNumbers - 1) + $iDim]

	$iOffSet = $iColumnNumbers - 2
	For $A = 0 To $iUbound - 1
		$aReturn[0][0] += 1

		$A += 1
		$iColumnNumber = 0
		For $B = $A To ($A + ($iOffSet))
			$aReturn[$aReturn[0][0]][$iColumnNumber] = $aArray[$B]
			$iColumnNumber += 1
		Next
		$A += $iOffSet
	Next
	$aReturn[0][2] = $sColumns
	ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]]
	Return $aReturn
EndFunc   ;==>_GUICtrlListView_HTMLToArray

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

When I try the function _GUICtrlListView_SaveHTML(), I get the folowwing error:

"String missing closing quote."

Even If I try the examples.
Any idea what's going wrong? Edited by azerty

Share this post


Link to post
Share on other sites

Posted · Report post

No idea the examples work for me. What version of AutoIt are you using?

Share this post


Link to post
Share on other sites

Posted · Report post

Lines 367 through 370 in the example posted gives me an error

"AutoItScriptstest_3.au3(367,20) : ERROR: syntax error (illegal character)
@TAB & '
~~~~~~~~~~~~~^
"

	$sHTMLFooter = '' & @CRLF & _
			'<table cellspacing="0" cellpadding="0"><tbody></tbody></table>' & @CRLF & _
			@CRLF & _
			'<div class="footer">' & @CRLF & _
			'<p>' & @CRLF & _
			$sCreatedText & ' <a href="' & $sURL & '" target="_blank">' & $sScriptName & '</a>' & @CRLF & _
			@TAB & '<span class="italic"></span>' & @CRLF & _
			@TAB & '
' & @CRLF & _
			@TAB & '
' & @CRLF & _
			@TAB & '<a href="#" class="top">' & $sTopText & '</a>' & @CRLF & _
			@TAB & '</p>' & @CRLF & _
			'</div>' & @CRLF & _
			@CRLF & _
			'' & @CRLF & _
			'' & @CRLF

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

OK, in the ZIP file there is no error, appears the forum did something to the code in the AutoIt box as <br /> should be there.

Use the ZIP file for now. Edited by guinness

Share this post


Link to post
Share on other sites

Posted · Report post

It's right that the forum did something to the code. When I paste the code from the forum I have an other error. That's the reason that I tryed the examples. But both functions, _GUICtrlListView_SaveHTML with Array and _GUICtrlListView_SaveHTML without Array, gives me the same error. You can see the whole error message below. The code is executed with AutoIt SciTE script editor. The AutoIt version is v3. Thanks for the support.

>"C:Program FilesAutoIt3SciTE..autoit3.exe" /ErrorStdOut "aiBestandenserveruzhomemapelemaDownloads_GUICtrlListView_SaveHTMLExample _GUICtrlListView_SaveHTML without Array.au3"   
aiBestandenserveruzhomemapelemaDownloads_GUICtrlListView_SaveHTMLExample _GUICtrlListView_SaveHTML without Array.au3 (204) : ==> String missing closing quote.:
$sHTMLHeader &= 'table {' & @CRLF & @TAB & 'border: 1px solid #FFF;' & @CRLF & @TAB & 'border-spacing: 0;' & @CRLF & @CRLF & @TAB & '-o-box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @TAB & '-moz-box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @TAB & '-webkit-box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @TAB & 'box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @CRLF & @TAB & '-o-background-clip: padding-box;' & @CRLF & @TAB & '-ms-background-clip: padding-box;' & @CRLF & @TAB & '-moz-background-clip: padding-box;' & @CRLF & @TAB & '-webkit-background-clip: padding-box;' & @CRLF & @TAB & 'background-clip: padding-box;' & @CRLF & @CRLF & @TAB & 'background-color: #FFF;' & @CRLF & @CRLF & @TAB & '-o-border-radius: 4px;' & @CRLF & @TAB & '-ms-border-radius: 4px;' & @CRLF & @TAB & '-moz-border-radius: 4px;' & @CRLF & @TAB & '-webkit-border-radius: 4px;' & @CRLF & @TAB & 'border-radius: 4px;' & @CRLF & '}' & @CRLF & @CRLF & 'table th, table td {' & @CRLF & @TAB & 'padding: 2px 12px;' & @CRLF & '}' & @CRLF & @CRLF & 'table th {' & @CRLF & @TAB & 'text-transform: uppercase;' & @CRLF & @TAB & 'color: #FFF;' & @CRLF & @TAB & 'font-size: 11px;' & @CRLF & @TAB & 'text-align: left;' & @CRLF & @TAB & 'padding-top: 4px;' & @CRLF & @TAB & 'height: 22px;' & @CRLF & @TAB & 'line-height: 22px;' & @CRLF & @CRLF & @TAB & 'background: rgb(59,103,158); /* Old browsers */' & @CRLF & @TAB & 'background: -moz-linear-gradient(top, rgba(59,103,158,1) 0%, rgba(43,136,217,1) 50%, rgba(32,124,202,1) 51%, rgba(125,185,232,1) 100%); /* FF3.6+ */' & @CRLF & @TAB & 'background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(59,103,158,1)), color-stop(50%,rgba(43,136,217,1)), color-stop(51%,rgba(32,124,202,1)), color-stop(100%,rgba(125,185,232,1))); /* Chrome, Safari4+ */' & @CRLF & @TAB & 'background: -webkit-linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* Chrome10+, Safari5.1+ */' & @CRLF & @TAB & 'background: -o-linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* Opera11.10+ */' & @CRLF & @TAB & 'background: -ms-linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* IE10+ */' & @CRLF & @TAB & 'background: linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* W3C */' & @CRLF & @CRLF & @TAB & 'text-shadow: -1px -1px #3A68A0;' & @CRLF & @TAB & 'border-bottom: 1px solid #3A68A0;' & @CRLF & '}' & @CRLF & @CRLF & 'table td:first-child {' & @CRLF & @TAB & 'text-align: right;' & @CRLF & '}' & @CRLF & @CRLF & 'table th:first-child {' & @CRLF & @TAB & 'text-align: right;' & @CRLF & '}' & @CRLF & @CRLF & 'table th:first-child {' & @CRLF & @TAB & '-o-border-top-left-radius: 4px;' & @CRLF & @TAB & '-ms-border-top-left-radius: 4px;' & @CRLF & @TAB & '-webkit-border-top-left-radius: 4px;' & @CRLF & @TAB & '-moz-border-radius-topleft: 4px;' & @CRLF & @TAB & 'border-top-left-radius: 4px;' & @CRLF & '}' & @CRLF & @CRLF & 'table th:last-child {' & @CRLF & @TAB & '-o-border-top-right-radius: 4px;' & @CRLF & @TAB & '-ms-border-top-right-radius: 4px;' & @CRLF & @TAB & '-webkit-border-top-right-radius: 4px;' & @CRLF & @TAB & '-moz-border-radius-topright: 4px;' & @CRLF & @TAB & 'border-top-right-radius: 4px;' & @CRLF & '}' & @CRLF & @CRLF & 'table td {' & @CRLF & @TAB & 'height: 23px;' & @CRLF & @TAB & 'line-height: 23px;' & @CRLF & @TAB & 'border-bottom: 1px solid #D9EBEB;' & @CRLF & '}' & @CRLF & @CRLF & 'table tr:last-child td {' & @CRLF & @TAB & 'border-bottom: none;' & @CRLF & '}' & @CRLF & @CRLF & 'table tr.even {' & @CRLF & @TAB & 'background-color: #F2F9FD;' & @CRLF & '}' & @CRLF & @CRLF & 'table tr:hover {' & @CRLF & @TAB & 'background: #DEF4FA; /* Old browsers */' & @CRLF & @TAB & 'background: -moz-linear-gradient(top, #DEF4FA 0%, #D5F2F9 50%, #C9EEF7 51%, #FFFEFD 100%); /* FF3.6+ */' & @CRLF & @TAB & 'background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#DEF4FA), color-sto
$sHTMLHeader &= 'table {' & @CRLF & @TAB & 'border: 1px solid #FFF;' & @CRLF & @TAB & 'border-spacing: 0;' & @CRLF & @CRLF & @TAB & '-o-box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @TAB & '-moz-box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @TAB & '-webkit-box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @TAB & 'box-shadow: 0px 0px 10px #BCD2EB;' & @CRLF & @CRLF & @TAB & '-o-background-clip: padding-box;' & @CRLF & @TAB & '-ms-background-clip: padding-box;' & @CRLF & @TAB & '-moz-background-clip: padding-box;' & @CRLF & @TAB & '-webkit-background-clip: padding-box;' & @CRLF & @TAB & 'background-clip: padding-box;' & @CRLF & @CRLF & @TAB & 'background-color: #FFF;' & @CRLF & @CRLF & @TAB & '-o-border-radius: 4px;' & @CRLF & @TAB & '-ms-border-radius: 4px;' & @CRLF & @TAB & '-moz-border-radius: 4px;' & @CRLF & @TAB & '-webkit-border-radius: 4px;' & @CRLF & @TAB & 'border-radius: 4px;' & @CRLF & '}' & @CRLF & @CRLF & 'table th, table td {' & @CRLF & @TAB & 'padding: 2px 12px;' & @CRLF & '}' & @CRLF & @CRLF & 'table th {' & @CRLF & @TAB & 'text-transform: uppercase;' & @CRLF & @TAB & 'color: #FFF;' & @CRLF & @TAB & 'font-size: 11px;' & @CRLF & @TAB & 'text-align: left;' & @CRLF & @TAB & 'padding-top: 4px;' & @CRLF & @TAB & 'height: 22px;' & @CRLF & @TAB & 'line-height: 22px;' & @CRLF & @CRLF & @TAB & 'background: rgb(59,103,158); /* Old browsers */' & @CRLF & @TAB & 'background: -moz-linear-gradient(top, rgba(59,103,158,1) 0%, rgba(43,136,217,1) 50%, rgba(32,124,202,1) 51%, rgba(125,185,232,1) 100%); /* FF3.6+ */' & @CRLF & @TAB & 'background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(59,103,158,1)), color-stop(50%,rgba(43,136,217,1)), color-stop(51%,rgba(32,124,202,1)), color-stop(100%,rgba(125,185,232,1))); /* Chrome, Safari4+ */' & @CRLF & @TAB & 'background: -webkit-linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* Chrome10+, Safari5.1+ */' & @CRLF & @TAB & 'background: -o-linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* Opera11.10+ */' & @CRLF & @TAB & 'background: -ms-linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* IE10+ */' & @CRLF & @TAB & 'background: linear-gradient(top, rgba(59,103,158,1) 0%,rgba(43,136,217,1) 50%,rgba(32,124,202,1) 51%,rgba(125,185,232,1) 100%); /* W3C */' & @CRLF & @CRLF & @TAB & 'text-shadow: -1px -1px #3A68A0;' & @CRLF & @TAB & 'border-bottom: 1px solid #3A68A0;' & @CRLF & '}' & @CRLF & @CRLF & 'table td:first-child {' & @CRLF & @TAB & 'text-align: right;' & @CRLF & '}' & @CRLF & @CRLF & 'table th:first-child {' & @CRLF & @TAB & 'text-align: right;' & @CRLF & '}' & @CRLF & @CRLF & 'table th:first-child {' & @CRLF & @TAB & '-o-border-top-left-radius: 4px;' & @CRLF & @TAB & '-ms-border-top-left-radius: 4px;' & @CRLF & @TAB & '-webkit-border-top-left-radius: 4px;' & @CRLF & @TAB & '-moz-border-radius-topleft: 4px;' & @CRLF & @TAB & 'border-top-left-radius: 4px;' & @CRLF & '}' & @CRLF & @CRLF & 'table th:last-child {' & @CRLF & @TAB & '-o-border-top-right-radius: 4px;' & @CRLF & @TAB & '-ms-border-top-right-radius: 4px;' & @CRLF & @TAB & '-webkit-border-top-right-radius: 4px;' & @CRLF & @TAB & '-moz-border-radius-topright: 4px;' & @CRLF & @TAB & 'border-top-right-radius: 4px;' & @CRLF & '}' & @CRLF & @CRLF & 'table td {' & @CRLF & @TAB & 'height: 23px;' & @CRLF & @TAB & 'line-height: 23px;' & @CRLF & @TAB & 'border-bottom: 1px solid #D9EBEB;' & @CRLF & '}' & @CRLF & @CRLF & 'table tr:last-child td {' & @CRLF & @TAB & 'border-bottom: none;' & @CRLF & '}' & @CRLF & @CRLF & 'table tr.even {' & @CRLF & @TAB & 'background-color: #F2F9FD;' & @CRLF & '}' & @CRLF & @CRLF & 'table tr:hover {' & @CRLF & @TAB & 'background: #DEF4FA; /* Old browsers */' & @CRLF & @TAB & 'background: -moz-linear-gradient(top, #DEF4FA 0%, #D5F2F9 50%, #C9EEF7 51%, #FFFEFD 100%); /* FF3.6+ */' & @CRLF & @TAB & ^ ERROR
>Exit code: 1    Time: 0.826

Share this post


Link to post
Share on other sites

Posted · Report post

But the ZIP is OK and as to having V3, the proceeding values are important to know for any future problem you might encounter.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0