Skip to content

Commit

Permalink
Merge pull request #26 from jpimbert/Story-53-TemplateExcel
Browse files Browse the repository at this point in the history
Story 53 template excel
  • Loading branch information
jpimbert committed Jul 5, 2014
2 parents 19db790 + 73a9144 commit 3773ec4
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 91 deletions.
14 changes: 7 additions & 7 deletions Project/VBAToolKit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@
<name>VBAToolKit</name>
<path>C:\Documents and Settings\Demonn\Application Data\Microsoft\AddIns\VBAToolKit.xlam</path>
</reference>
<configuration cID="c1" refIDs="r1 r2 r3 r4 r5 r6 r7 r8 r9 ">
<configuration cID="c1" refIDs="r1 r2 r3 r4 r5 r6 r7 r8 r9">
<name>VBAToolKit</name>
<path>Delivery\VBAToolKit.xlam</path>
<title>VBAToolKit</title>
<comment>Project VBAToolKit</comment>
<comment>ToolKit for improving VBA development. Add-In for Excel 2007 and above.</comment>
</configuration>
<configuration cID="c2" refIDs="r1 r2 r3 r4 r5 r6 r7 r8 r9 r11 ">
<configuration cID="c2" refIDs="r1 r2 r3 r4 r5 r6 r7 r8 r9 r11">
<name>VBAToolKit_DEV</name>
<path>Project\VBAToolKit_DEV.xlsm</path>
<title>VBAToolKit_DEV</title>
<comment>Project VBAToolKit_DEV</comment>
<comment>Development and Test version for VBAToolKit</comment>
</configuration>
<configuration cID="c3" refIDs="r1 r2 r3 r4 r5 r6 r7 r8 r9 ">
<configuration cID="c3" refIDs="r1 r2 r3 r4 r5 r6 r7 r8 r9">
<name>VBAToolKit_2003</name>
<path>Delivery\VBAToolKit.xla</path>
<title>VBAToolKit_2003</title>
<comment>Project VBAToolKit_2003</comment>
<title>VBAToolKit</title>
<comment>ToolKit for improving VBA development. Add-In for Excel 2003.</comment>
</configuration>
<module mID="m1">
<name>vtkImportExportUtilities</name>
Expand Down
Binary file modified Project/VBAToolKit_DEV.xlsm
Binary file not shown.
3 changes: 3 additions & 0 deletions Source/ConfProd/VtKPathUtilities.bas
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Public Function vtkCreateTreeFolder(rootPath As String)
MkDir rootPath & "\" & "Project"
MkDir rootPath & "\" & "Tests"
MkDir rootPath & "\" & "GitLog"
MkDir rootPath & "\" & "Templates"
MkDir rootPath & "\" & "Source"
MkDir rootPath & "\" & "Source" & "\" & "ConfProd"
MkDir rootPath & "\" & "Source" & "\" & "ConfTest"
Expand Down Expand Up @@ -229,6 +230,8 @@ Public Sub vtkDeleteTreeFolder(rootPath As String)
RmDir rootPath & "\Source\ConfTest"
Kill rootPath & "\Source\VbaUnit\*"
RmDir rootPath & "\Source\VbaUnit"
Kill rootPath & "\Templates\*"
RmDir rootPath & "\Templates"
Kill rootPath & "\GitLog\*"
RmDir rootPath & "\GitLog"
Kill rootPath & "\Tests\*"
Expand Down
16 changes: 16 additions & 0 deletions Source/ConfProd/vtkConfiguration.cls
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ Property Let comment(newComment As String)
m_parent.setConfigurationCommentWithNumber m_number, newComment
End Property

'---------------------------------------------------------------------------------------
' Property : template as string (wrapper on the parent vtkConfigurationManager)
' Author : Jean-Pierre Imbert
' Date : 01/07/2014
' Purpose : The Excel template path for the configuration
'---------------------------------------------------------------------------------------
'
Property Get template() As String
template = m_parent.getConfigurationTemplateWithNumber(m_number)
End Property

Property Let template(newTemplate As String)
On Error Resume Next
m_parent.setConfigurationTemplateWithNumber m_number, newTemplate
End Property

'---------------------------------------------------------------------------------------
' Property : modules as collection (Read Only)
' Author : Jean-Pierre Imbert
Expand Down
109 changes: 87 additions & 22 deletions Source/ConfProd/vtkConfigurationManager.cls
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ Private Const currentVersion As String = "vtkConfigurations v1.1"
Private Const version10 As String = "vtkConfigurations v1.0"
Private m_sheetVersion As String
Private Const nbTitleColumns As Integer = 1
Private Const nameLine = 1
Private Const pathLine = 2
Private Const templateLine = 3
Private Const projectNameLine = 4
Private Const commentLine = 5

Private Sub Class_Initialize()
m_devConfiguration = -1
Expand Down Expand Up @@ -126,6 +131,17 @@ Private Function defaultCommentWithNumber(n As Integer) As String
defaultCommentWithNumber = "Project " & Me.configuration(n)
End Function

'---------------------------------------------------------------------------------------
' Function : defaultTemplateWithNumber as String - Read Only - Private
' Author : Jean-Pierre Imbert
' Date : 01/07/2014
' Purpose : return the default Excel template path of a configuration given its number
'---------------------------------------------------------------------------------------
'
Private Function defaultTemplateWithNumber(n As Integer) As String
defaultTemplateWithNumber = ""
End Function

'---------------------------------------------------------------------------------------
' Property : rootPath as String - Read Only - Public
' Author : Jean-Pierre Imbert
Expand Down Expand Up @@ -182,7 +198,7 @@ End Function
'
Private Function nbTitleRows() As Integer
If m_sheetVersion = version10 Then nbTitleRows = 2
If m_sheetVersion = currentVersion Then nbTitleRows = 4
If m_sheetVersion = currentVersion Then nbTitleRows = 5
End Function

'---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -228,8 +244,9 @@ End Sub
Private Sub initializeConfigurationSheet(ws As Worksheet)
ws.Range("A1") = currentVersion
ws.Range("A2") = ""
ws.Range("A3") = "Path, name and comment"
ws.Range("A4") = "Module Name"
ws.Range("A3") = "Path, template, name and comment"
ws.Range("A4") = ""
ws.Range("A5") = "Module Name"
ws.Range("B1") = vtkProjectForName(projectName).projectName
ws.Range("B2") = vtkProjectForName(projectName).projectStandardRelativePath
ws.Range("C1") = vtkProjectForName(projectName).projectDEVName
Expand All @@ -240,8 +257,8 @@ Private Sub initializeConfigurationSheet(ws As Worksheet)
ws.Columns("A:C").ColumnWidth = 22
ws.Range("A1").Font.Size = 8
ws.Range("A3").HorizontalAlignment = xlCenter
ws.Range("A4").HorizontalAlignment = xlCenter
ws.Range("A4").Font.Bold = True
ws.Range("A5").HorizontalAlignment = xlCenter
ws.Range("A5").Font.Bold = True
ws.Range("B1:C2").HorizontalAlignment = xlCenter
ws.Range("B1:C1").Font.Bold = True
End Sub
Expand All @@ -259,18 +276,19 @@ Public Sub updateConfigurationSheetFormat()
If m_sheetVersion = version10 Then
Set ws = configurationSheet

ws.Rows("3:4").EntireRow.Insert ' Insert new lines for the new format
ws.Rows("3:5").EntireRow.Insert ' Insert new lines for the new format

ws.Range("A1") = currentVersion
ws.Range("A2") = ""
ws.Range("A3") = "Path, name and comment"
ws.Range("A4") = "Module Name"
ws.Range("A3") = "Path, template, name and comment"
ws.Range("A4") = ""
ws.Range("A5") = "Module Name"

ws.Range("A2").Font.Bold = False
ws.Range("A3").Font.Bold = False
ws.Range("A3").HorizontalAlignment = xlCenter
ws.Range("A4").HorizontalAlignment = xlCenter
ws.Range("A4").Font.Bold = True
ws.Range("A5").HorizontalAlignment = xlCenter
ws.Range("A5").Font.Bold = True

m_sheetVersion = currentVersion ' Set the sheetVersion for correct behavior after conversion
End If
Expand Down Expand Up @@ -331,15 +349,16 @@ End Function
' - if the configuration already exists, return minus the configuration number
'---------------------------------------------------------------------------------------
'
Public Function addConfiguration(configuration As String, Optional path As String = "", Optional projectName As String = "", Optional comment As String = "") As Integer
Public Function addConfiguration(configuration As String, Optional path As String = "", Optional template As String = "", Optional projectName As String = "", Optional comment As String = "") As Integer
Dim n As Integer
n = getConfigurationNumber(configuration)
If n = 0 Then ' n = 0 means non-existant configuration
n = configurationCount + 1 ' Set configuration number
configurationSheet.Cells(1, n + nbTitleColumns) = configuration ' Write configuration name
configurationSheet.Cells(2, n + nbTitleColumns) = path ' Write configuration path
configurationSheet.Cells(3, n + nbTitleColumns) = projectName ' Write configuration projectName
configurationSheet.Cells(4, n + nbTitleColumns) = comment ' Write configuration Comment
configurationSheet.Cells(3, n + nbTitleColumns) = template ' Write configuration Excel template path
configurationSheet.Cells(4, n + nbTitleColumns) = projectName ' Write configuration projectName
configurationSheet.Cells(5, n + nbTitleColumns) = comment ' Write configuration Comment
Dim i As Integer
For i = 1 To moduleCount ' For each module
configurationSheet.Cells(i + nbTitleRows, n + nbTitleColumns) = "-" ' Set Default path as not initialized
Expand Down Expand Up @@ -401,7 +420,7 @@ Public Function getConfigurationPathWithNumber(n As Integer) As String
Dim sResult As String
sResult = ""
If n >= 1 And n <= configurationCount Then
sResult = configurationSheet.Cells(2, n + nbTitleColumns)
sResult = configurationSheet.Cells(pathLine, n + nbTitleColumns)
Else
sResult = ""
End If
Expand All @@ -418,7 +437,7 @@ End Function
'
Public Sub setConfigurationPathWithNumber(n As Integer, path As String)
If n >= 1 And n <= configurationCount Then
configurationSheet.Cells(2, n + nbTitleColumns) = path
configurationSheet.Cells(pathLine, n + nbTitleColumns) = path
End If
End Sub

Expand Down Expand Up @@ -461,7 +480,7 @@ Public Function getConfigurationProjectNameWithNumber(n As Integer) As String
sResult = ""
If n >= 1 And n <= configurationCount Then
If m_sheetVersion = currentVersion Then
sResult = configurationSheet.Cells(3, n + nbTitleColumns)
sResult = configurationSheet.Cells(projectNameLine, n + nbTitleColumns)
If sResult = "" Then sResult = defaultProjectNameWithNumber(n)
Else
sResult = defaultProjectNameWithNumber(n)
Expand All @@ -475,7 +494,7 @@ End Function
'---------------------------------------------------------------------------------------
' Procedure : setConfigurationProjectNameWithNumber
' Author : Jean-Pierre Imbert
' Date : 08/06/2013
' Date : 08/06/2014
' Purpose : change the n-th configuration project name of the project, given n as integer
' - does nothing if the configuration is inexistant
' - does nothing and return an error if the configuration sheet is v1.0
Expand All @@ -484,7 +503,7 @@ End Function
Public Sub setConfigurationProjectNameWithNumber(n As Integer, projectName As String)
If n >= 1 And n <= configurationCount Then
If m_sheetVersion = currentVersion Then
configurationSheet.Cells(3, n + nbTitleColumns) = projectName
configurationSheet.Cells(projectNameLine, n + nbTitleColumns) = projectName
Else
Err.Raise VTK_OBSOLETE_CONFIGURATION_SHEET, "vtkConfigurationManager:setConfigurationProjectNameWithNumber", _
"Impossible to set a configuration projectName with this configuration sheet version (project=" & m_projectName & ", " & m_sheetVersion & ")"
Expand All @@ -508,7 +527,7 @@ Public Function getConfigurationCommentWithNumber(n As Integer) As String
sResult = ""
If n >= 1 And n <= configurationCount Then
If m_sheetVersion = currentVersion Then
sResult = configurationSheet.Cells(4, n + nbTitleColumns)
sResult = configurationSheet.Cells(commentLine, n + nbTitleColumns)
If sResult = "" Then sResult = defaultCommentWithNumber(n)
Else
sResult = defaultCommentWithNumber(n)
Expand All @@ -522,7 +541,7 @@ End Function
'---------------------------------------------------------------------------------------
' Procedure : setConfigurationCommentWithNumber
' Author : Jean-Pierre Imbert
' Date : 08/06/2013
' Date : 08/06/2014
' Purpose : change the n-th configuration comment of the project, given n as integer
' - does nothing if the configuration is inexistant
' - does nothing and return an error if the configuration sheet is v1.0
Expand All @@ -531,12 +550,58 @@ End Function
Public Sub setConfigurationCommentWithNumber(n As Integer, comment As String)
If n >= 1 And n <= configurationCount Then
If m_sheetVersion = currentVersion Then
configurationSheet.Cells(4, n + nbTitleColumns) = comment
configurationSheet.Cells(commentLine, n + nbTitleColumns) = comment
Else
Err.Raise VTK_OBSOLETE_CONFIGURATION_SHEET, "vtkConfigurationManager:setConfigurationCommentWithNumber", _
"Impossible to set a configuration comment with this configuration sheet version (project=" & m_projectName & ", " & m_sheetVersion & ")"
End If
configurationSheet.Cells(4, n + nbTitleColumns) = comment
End If
End Sub

'---------------------------------------------------------------------------------------
' Procedure : getConfigurationTemplateWithNumber
' Author : Jean-Pierre Imbert
' Date : 01/07/2014
' Purpose : return the n-th configuration Excel template path of the project, given n as integer
' - return "" if the configuration is inexistant
' - return the default comment if
' - it is not initialized in the configuration sheet v1.1
' - the configuration sheet is v1.0, so there is no comment field
'---------------------------------------------------------------------------------------
'
Public Function getConfigurationTemplateWithNumber(n As Integer) As String
Dim sResult As String
sResult = ""
If n >= 1 And n <= configurationCount Then
If m_sheetVersion = currentVersion Then
sResult = configurationSheet.Cells(templateLine, n + nbTitleColumns)
If sResult = "" Then sResult = defaultTemplateWithNumber(n)
Else
sResult = defaultTemplateWithNumber(n)
End If
Else
sResult = ""
End If
getConfigurationTemplateWithNumber = sResult
End Function

'---------------------------------------------------------------------------------------
' Procedure : setConfigurationTemplateWithNumber
' Author : Jean-Pierre Imbert
' Date : 01/07/2014
' Purpose : change the n-th configuration comment of the project, given n as integer
' - does nothing if the configuration is inexistant
' - does nothing and return an error if the configuration sheet is v1.0
'---------------------------------------------------------------------------------------
'
Public Sub setConfigurationTemplateWithNumber(n As Integer, template As String)
If n >= 1 And n <= configurationCount Then
If m_sheetVersion = currentVersion Then
configurationSheet.Cells(templateLine, n + nbTitleColumns) = template
Else
Err.Raise VTK_OBSOLETE_CONFIGURATION_SHEET, "vtkConfigurationManager:setConfigurationTemplateWithNumber", _
"Impossible to set a configuration template path with this configuration sheet version (project=" & m_projectName & ", " & m_sheetVersion & ")"
End If
End If
End Sub

Expand Down
6 changes: 6 additions & 0 deletions Source/ConfProd/vtkConfigurationManagers.bas
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ End Sub
' - All configuration projectName property is the same as the project name of the configuration
' - All configuration projectName property is the same as the title property of the configuration
' - All configuration comment property is the same as the comment property of the configuration
' - All configuration template path is reachable
' - All modules listed in a configuration description are existing in the configuration
' - All modules really present in a configuration are described in the description with non null path
' - All modules pathes are reachable
Expand Down Expand Up @@ -206,6 +207,11 @@ Sub vtkVerifyConfigurations()
Debug.Print "For configuration " & c.name & ", the comment property (" & c.comment & ") is different of the workbook comment (" & cwb(nbConf).Wb.BuiltinDocumentProperties("Comments").Value & ")."
End If

' Verify workbooks template path
If Not (fso.FileExists(cm.rootPath & "\" & c.template)) Then
Debug.Print "For configuration " & c.name & ", the template path (" & cm.rootPath & "\" & c.template & ") is unreachable."
End If

Else
Debug.Print "Impossible to open Workbook for configuration " & c.name & " (" & s & ")."
End If
Expand Down
1 change: 1 addition & 0 deletions Source/ConfProd/vtkConstants.bas
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Public Const VTK_NO_SOURCE_FILES = 4005
Public Const VTK_OBSOLETE_CONFIGURATION_SHEET = 4006
Public Const VTK_NOTINITIALIZED = 4007
Public Const VTK_INVALID_FIELD = 4008
Public Const VTK_TEMPLATE_NOT_FOUND = 4009

Public Const VTK_UNEXPECTED_CHAR = 5001
Public Const VTK_UNEXPECTED_EOS = 5002
Expand Down
17 changes: 15 additions & 2 deletions Source/ConfProd/vtkImportExportUtilities.bas
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ End Sub
Public Sub vtkRecreateConfiguration(projectName As String, configurationName As String)
Dim cm As vtkConfigurationManager
Dim rootPath As String
Dim wbPath As String
Dim wbPath As String, templatePath As String
Dim Wb As Workbook
Dim tmpWb As Workbook
Dim fso As New FileSystemObject
Expand Down Expand Up @@ -400,7 +400,16 @@ Public Sub vtkRecreateConfiguration(projectName As String, configurationName As
Next

' Create a new Excel file
Set Wb = vtkCreateExcelWorkbook()
templatePath = conf.template
If templatePath = "" Then
Set Wb = vtkCreateExcelWorkbook() ' If there is no template, a new workbook is created
Else
templatePath = rootPath & "\" & templatePath
If Not fso.FileExists(templatePath) Then
Err.Raise VTK_TEMPLATE_NOT_FOUND
End If
Set Wb = Workbooks.Open(fileName:=templatePath, ReadOnly:=True) ' If there is a template, it's open as ReadOnly
End If

' Set the projectName
Wb.VBProject.name = conf.projectName
Expand Down Expand Up @@ -455,6 +464,10 @@ vtkRecreateConfiguration_Error:
Err.Number = VTK_WORKBOOK_ALREADY_OPEN
Err.Description = "The configuration you're trying to create (" & configurationName & ") corresponds to an open workbook. " & _
"Please close it before recreating the configuration."
Case VTK_TEMPLATE_NOT_FOUND
Err.Number = VTK_TEMPLATE_NOT_FOUND
Err.Description = "The configuration you're trying to create (" & configurationName & ") needs an Excel template file (" & templatePath & "). " & _
"This template file is unreachable."
Case VTK_NO_SOURCE_FILES
Err.Number = VTK_NO_SOURCE_FILES
Err.Description = "The configuration you're trying to create (" & configurationName & ") is missing one or several source files." & _
Expand Down
2 changes: 2 additions & 0 deletions Source/ConfProd/vtkXMLUtilities.bas
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Public Sub vtkExportConfigurationsAsXML(projectName As String, filePath As Strin
End If
xmlFile.WriteLine Text:=" <name>" & cf.name & "</name>"
xmlFile.WriteLine Text:=" <path>" & cf.path & "</path>"
If cf.template <> "" Then _
xmlFile.WriteLine Text:=" <templatePath>" & cf.template & "</templatePath>"
xmlFile.WriteLine Text:=" <title>" & cf.projectName & "</title>" ' must be initialized in Workbook with Wb.BuiltinDocumentProperties("Title").Value
xmlFile.WriteLine Text:=" <comment>" & cf.comment & "</comment>" ' must be initialized in Workbook with Wb.BuiltinDocumentProperties("Comments").Value
xmlFile.WriteLine Text:=" </configuration>"
Expand Down
Loading

0 comments on commit 3773ec4

Please sign in to comment.