ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Redgrave/RelativitySearchReport.py
Revision: 899
Committed: Wed May 28 14:40:34 2025 UTC (9 months, 4 weeks ago) by nino.borges
Content type: text/x-python
File size: 3963 byte(s)
Log Message:
In this version added the final ability to make the table into a formatted table.

File Contents

# Content
1 """
2
3 ATT-RelativitySearchReport
4
5 Created by:
6 Emanuel Borges
7 05.6.2025
8
9 This very simple program will take a Relativity saved search information export and convert it to a more useful report that can be shared with others and contains
10 detail contained in the notes section of the search. This assumes the best practice of notating what the search does in the Notes field.
11
12 """
13
14
15 import os, csv, pathlib
16 from win32com.client import Dispatch
17
18 version = "0.06"
19
20
21 def GenerateSearchReport(rawReportFile, outputFilename, relativityInstancePath, workspaceArtifactID):
22 """test"""
23 headerRow = ["Artifact ID", "Search Name", "Notes"]
24
25 reportMatrix = {}
26
27 with open(rawReportFile,encoding='UTF-8') as csvFile:
28 csvReader = csv.DictReader(csvFile,delimiter=',',quotechar='"')
29 for row in csvReader:
30
31 pathParts = pathlib.Path(row['Path'].replace(row['Name'],''))
32 rowFolderName = "\\".join(pathParts.parts[1:-1])
33
34 if rowFolderName in list(reportMatrix.keys()):
35 reportMatrix[rowFolderName].append((row['Name'],row['Notes'],f"{relativityInstancePath}go?id={workspaceArtifactID}-{row['Artifact ID']}", row['Artifact ID']))
36 else:
37 reportMatrix[rowFolderName] = [(row['Name'],row['Notes'],f"{relativityInstancePath}go?id={workspaceArtifactID}-{row['Artifact ID']}", row['Artifact ID']),]
38 #print(f"{row['Artifact ID']} | {rowFolderName} | {row['Name']} | {row['Notes']} | {relativityInstancePath}go?id={workspaceArtifactID}-{row['Artifact ID']}" )
39
40 folderGroupList = list(reportMatrix.keys())
41 folderGroupList.sort()
42
43
44 xlApp = Dispatch('Excel.Application')
45 xlBook = xlApp.Workbooks.Add()
46 sht = xlBook.Worksheets(1)
47 colNumb = 1
48 for fName in headerRow:
49 sht.Cells(1,colNumb).Value = fName
50 colNumb +=1
51
52 rowNumb = 2
53
54 for folderName in folderGroupList:
55 colNumb = 2
56 print(folderName)
57 sht.Cells(rowNumb,colNumb).Value = folderName
58 sht.Cells(rowNumb,colNumb).Interior.Color = 12632256
59 sht.Cells(rowNumb,colNumb+1).Interior.Color = 12632256
60 folderSearches = reportMatrix[folderName]
61 folderSearches.sort()
62 rowNumb +=1
63 for srch in folderSearches:
64 colNumb = 1
65 print(f"\t{srch}")
66 ## Write the artifact ID
67 sht.Cells(rowNumb,colNumb).Value = srch[-1]
68 colNumb +=1
69 ## Write the search name
70 sht.Cells(rowNumb,colNumb).Value = srch[0]
71 ## Make it a real hyperlink
72 sht.Hyperlinks.Add(sht.Range(f"B{rowNumb}"), Address = srch[2])
73 colNumb +=1
74 ## Write the Notes
75 sht.Cells(rowNumb,colNumb).Value = srch[1]
76 colNumb +=1
77
78 #for value in srch:
79 # sht.Cells(rowNumb,colNumb).Value = value
80 # colNumb +=1
81 rowNumb +=1
82
83 sht.Columns("A:A").Hidden = True
84 sht.Columns("B:B").AutoFit()
85 sht.Columns("C:C").ColumnWidth = 150
86 sht.Columns("C:C").WrapText = True
87
88 lastRow = rowNumb - 1
89 sht.ListObjects.Add(1, sht.Range(f"B1:C{lastRow}"), 0, 1).TableStyle = "TableStyleLight9"
90 for cell in sht.Range(f"B1:C1"):
91 cell.Interior.Color = 6299648 # Dark Teal
92
93 xlBook.SaveAs(outputFilename)
94 xlApp.Quit()
95
96
97 if __name__ == '__main__':
98 rawReportFile = r"C:\Test_Dir\ATT\export_20250522_174604.csv"
99 outputFilename = r"C:\Test_Dir\ATT\export_20250522_174604_OUT2.XLSX"
100
101
102 ## For Lighthouse
103 relativityInstancePath = 'https://relativity4.lighthouseglobal.com/Relativity/'
104
105 ## For shiny
106 #workspaceArtifactID = '1267840'
107 ## For Vermont
108 workspaceArtifactID = '1530226'
109
110
111 GenerateSearchReport(rawReportFile, outputFilename, relativityInstancePath, workspaceArtifactID)