Question : I need to turn this PHP file into a spreadsheet

I've played around with some different approaches, but none are producing the kind of results I'm needing.

For example, take a look at http://hihatwebdesign.com/Rainmaker/adm/report_student.php?id=1/report_student.xls. I want to turn that into a spreadsheet that has the same kind of colors and fonts.

How?

Right now I'm using fp (code is attached) and while I can get the data to show up, I've had a hard time when I doing loops within other queries and the aesthetics are less than what I'm going for.

Suggestions?

Answer : I need to turn this PHP file into a spreadsheet

LOL! I thought you might ask that.  So I had a re-look at my code, and I have now made it much more dynamic, where you only need to specify the drive letters you want in arrDrives.  You can add or subtract as many drive letters as you wish.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
strInputFile = "computers.txt"
strOutputFile = "hard_disk_space.csv"
Dim arrDrives
arrDrives = Array("C","D","E","F")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1

Const adVarChar = 200
Const MaxCharacters = 255


Dim DataList
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Server", adVarChar, MaxCharacters
For Each strDrive In arrDrives
	DataList.Fields.Append strDrive & " Size", adVarChar, MaxCharacters
	DataList.Fields.Append strDrive & " Free Space", adVarChar, MaxCharacters
	DataList.Fields.Append strDrive & " Percent Free", adVarChar, MaxCharacters
Next
DataList.Open

Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading)
While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	Get_Free_Space_Details(strComputer)
Wend

Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
strHeader = """SERVER"""
For Each strDrive In arrDrives
	strHeader = strHeader & ",""" & strDrive & " SIZE"",""" & strDrive & " FREE SPACE"",""" & strDrive & " PERCENT FREE"""
Next
objOutputFile.WriteLine strHeader
DataList.MoveFirst
While Not DataList.EOF
	strLine = """" & DataList("Server") & """"
	For Each strDrive In arrDrives
		strLine = strLine & ",""" & DataList(strDrive & " Size") & """,""" & DataList(strDrive & " Free Space") & """,""" & DataList(strDrive & " Percent Free") & """"
	Next
	objOutputFile.WriteLine strLine
	DataList.MoveNext
Wend
DataList.Close
objOutputFile.Close

MsgBox "Done. Please see " & strOutputFile
'==============

Sub Get_Free_Space_Details(strComputer)

	DataList.AddNew
	DataList("Server") = strComputer
	If Ping(strComputer) = True Then 
		On Error Resume Next
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		If Err.Number = 0 Then
			Err.Clear
			On Error GoTo 0
			For Each strDrive In arrDrives
				Set colDisks = objWMIService.ExecQuery("Select FreeSpace,Size From Win32_LogicalDisk Where DriveType = 3 And DeviceID = '" & strDrive & ":'")
				For Each objDisk In colDisks
					intFreeSpace = objDisk.FreeSpace
					intTotalSpace = objDisk.Size
					pctFreeSpace = intFreeSpace / intTotalSpace
					DataList(strDrive & " Size") = Round(intTotalSpace / 1024 / 1024 / 1024, 2) & " GB"
					DataList(strDrive & " Free Space") = Round(intFreeSpace / 1024 / 1024 / 1024, 2) & " GB"
					DataList(strDrive & " Percent Free") = FormatPercent(pctFreeSpace)
				Next
			Next			
			Set objDisk = Nothing
			Set colDisks = Nothing
			Set objWMIService = Nothing
		Else
			For Each strDrive In arrDrives
				DataList(strDrive & " Size") = "WMI ERROR"
				DataList(strDrive & " Free Space") = "WMI ERROR"
				DataList(strDrive & " Percent Free") = "WMI ERROR"
			Next
		End If
	Else
		For Each strDrive In arrDrives
			DataList(strDrive & " Size") = "OFFLINE"
			DataList(strDrive & " Free Space") = "OFFLINE"
			DataList(strDrive & " Percent Free") = "OFFLINE"
		Next
	End If
	DataList.Update
End Sub

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function
Random Solutions  
 
programming4us programming4us