use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- tell the user what the script does and allow to cancel
set theResponse to display dialog "Dieses Script erzeugt einen Report aller Kataloge von NeoFinder in einer neuen Microsoft Excel Tabelle." & return & "Sie benötigen dazu eine aktuelle und lizensierte Version von Excel!" buttons {"OK", "Abbrechen"} default button "Abbrechen" with icon caution
if button returned of theResponse = "Abbrechen" then
	return 0
end if


-- how many catalogs are contained in your NeoFinder LIBRARY?
tell application "NeoFinder"
	set numCatalogs to count Catalogues
end tell

tell application "Microsoft Excel"
	set myWorkbook to make new workbook
	tell myWorkbook
		tell sheet 1
			set value of cell "A1" to "Name"
			set column width of column 1 to 60
			set number format of range ("A1:A" & (numCatalogs + 3) as string) to "@" -- plain text
			
			set value of cell "B1" to "Media Type"
			set column width of column 2 to 26
			set number format of range ("B1:B" & (numCatalogs + 3) as string) to "@"
			
			set value of cell "C1" to "Hardware Serial"
			set column width of column 3 to 20
			set number format of range ("C1:C" & (numCatalogs + 3) as string) to "@"
			
			set value of cell "D1" to "Number of Files"
			set column width of column 4 to 16
			set number format of range ("D1:D" & (numCatalogs + 3) as string) to "# ?/?" -- "Fraction"
			
			set value of cell "E1" to "Number of Folders"
			set column width of column 5 to 16
			set number format of range ("E1:E" & (numCatalogs + 3) as string) to "# ?/?" -- "Fraction"
			
			set value of cell "F1" to "Cataloged Data Size"
			set column width of column 6 to 20
			set number format of range ("F1:F" & (numCatalogs + 3) as string) to "# ?/?" -- "Fraction"
			
			set value of cell "G1" to "Volume Size"
			set column width of column 7 to 20
			set number format of range ("G1:G" & (numCatalogs + 3) as string) to "# ?/?" -- "Fraction"
		end tell
	end tell
end tell


repeat with i from 1 to numCatalogs
	-- get the data from NeoFinder
	tell application "NeoFinder"
		tell Catalogue i
			set catName to name
			set catMediaType to media type
			set catHWSerial to hardware serial
			set catNumFiles to file number
			set catNumFolders to folder number
			set catDataSize to size
			set catVolumeSize to volume size
		end tell
	end tell
	-- and place it in the Excel worksheet
	set currentRow to (2 + i) as string
	tell application "Microsoft Excel"
		tell myWorkbook
			tell sheet 1
				set value of cell ("A" & currentRow) to catName
				set value of cell ("B" & currentRow) to catMediaType
				set value of cell ("C" & currentRow) to catHWSerial
				set value of cell ("D" & currentRow) to catNumFiles
				set value of cell ("E" & currentRow) to catNumFolders
				set value of cell ("F" & currentRow) to catDataSize
				set value of cell ("G" & currentRow) to catVolumeSize
			end tell
		end tell
	end tell
end repeat
