* When calculating the IVs of several Pokémons, now the calculator will reuse a same spreadsheet document, even the same spreadsheet when there is already a spreadsheet for that Pokémon. Previously it will start a new spreadsheet document for each calculation. This helps when calculating a bunch of Pokémons at the same time.

* Advanced to version 0.8.0.
This commit is contained in:
依瑪貓 2017-11-29 00:42:20 +08:00
parent d2b3d26dca
commit 787acb12bf
4 changed files with 363 additions and 133 deletions

View File

@ -54,6 +54,23 @@ Type aFindIVParam
bIsCancelled As Boolean bIsCancelled As Boolean
End Type End Type
Sub subGetPokemonSheet
Dim oDoc As Object
Dim oEnum As Object, oComponent As Object, sTitles As String
oDoc = fnCreateNewSpreadsheetDocument
oDoc.setTitle ("Pokemon GO IV")
oEnum = StarDesktop.getComponents.createEnumeration
Do While oEnum.hasMoreElements
oComponent = oEnum.nextElement
If oComponent.supportsService ("com.sun.star.sheet.SpreadsheetDocument") Then
If oComponent.getTitle = "Pokemon GO IV" Then
Xray oComponent
End If
End If
Loop
End Sub
' subCreateReport: Creates the Pokémon GO IV report. ' subCreateReport: Creates the Pokémon GO IV report.
Sub subCreateReport ( _ Sub subCreateReport ( _
aBaseStats As aStats, aQuery As aFindIVParam, maIVs () As aIV) aBaseStats As aStats, aQuery As aFindIVParam, maIVs () As aIV)
@ -67,13 +84,12 @@ Sub subCreateReport ( _
Dim sColIVAttack As String, sColIVDefense As String Dim sColIVAttack As String, sColIVDefense As String
Dim sColIVStamina As String Dim sColIVStamina As String
Dim sPokemonName As String Dim sPokemonName As String
Dim mData (Ubound (maIVs) + 1) As Variant, mRow () As Variant Dim mLeadHead () As Variant, nStartRow As Integer
Dim mData (0) As Variant, mRow () As Variant
Dim maEvBaseStats () As Variant Dim maEvBaseStats () As Variant
Dim mProps () As New com.sun.star.beans.PropertyValue Dim mProps () As New com.sun.star.beans.PropertyValue
oDoc = StarDesktop.loadComponentFromURL ( _ oSheet = fnFindPokemonGOIVSheet (aQuery.sPokemonName)
"private:factory/scalc", "_default", 0, mProps)
oSheet = oDoc.getSheets.getByIndex (0)
nEvolved = UBound (aBaseStats.mEvolved) + 1 nEvolved = UBound (aBaseStats.mEvolved) + 1
If nEvolved > 0 Then If nEvolved > 0 Then
@ -96,8 +112,8 @@ Sub subCreateReport ( _
' Sorts the IVs ' Sorts the IVs
subSortIVs (aBaseStats, maEvBaseStats, maIVs, fMaxLevel) subSortIVs (aBaseStats, maEvBaseStats, maIVs, fMaxLevel)
' Fills in the report data. ' Gathers the header row.
mRow = Array ( _ mLeadHead = Array ( _
fnGetResString ("ReportNo"), _ fnGetResString ("ReportNo"), _
fnGetResString ("ReportPokemon"), _ fnGetResString ("ReportPokemon"), _
fnGetResString ("ReportCP"), _ fnGetResString ("ReportCP"), _
@ -108,8 +124,10 @@ Sub subCreateReport ( _
fnGetResString ("ReportDefense"), _ fnGetResString ("ReportDefense"), _
fnGetResString ("ReportStamina"), _ fnGetResString ("ReportStamina"), _
fnGetResString ("ReportIVPercent")) fnGetResString ("ReportIVPercent"))
nLeadCols = UBound (mRow) + 1 nLeadCols = UBound (mLeadHead) + 1
' Calculating how many columns do we need to fill in the
' CP of the evolved forms.
nTotalCols = nLeadCols nTotalCols = nLeadCols
If aBaseStats.bIsLastForm Then If aBaseStats.bIsLastForm Then
nTotalCols = nTotalCols + 1 nTotalCols = nTotalCols + 1
@ -121,17 +139,25 @@ Sub subCreateReport ( _
End If End If
Next nJ Next nJ
' Adds the header row if this is a new spreadsheet
oCell = oSheet.getCellByPosition (0, 0)
If oCell.getString = "" Then
' The leading columns of the header row
mRow = mLeadHead
' Fill in the header row with the CP of the evolved forms.
ReDim Preserve mRow (nTotalCols - 1) As Variant ReDim Preserve mRow (nTotalCols - 1) As Variant
nCol = nLeadCols nCol = nLeadCols
If aBaseStats.bIsLastForm Then If aBaseStats.bIsLastForm Then
mRow (nCol) = fnReplace (fnGetResString ("ReportCPPowerUp"), _ mRow (nCol) = fnReplace ( _
fnGetResString ("ReportCPPowerUp"), _
"[Level]", fMaxLevel) "[Level]", fMaxLevel)
nCol = nCol + 1 nCol = nCol + 1
End If End If
For nJ = 0 To nEvolved - 1 For nJ = 0 To nEvolved - 1
sPokemonName = fnGetResString ( _ sPokemonName = fnGetResString ( _
"Pokemon" & aBaseStats.mEvolved (nJ)) "Pokemon" & aBaseStats.mEvolved (nJ))
mRow (nCol) = fnReplace (fnGetResString ("ReportCPEvolve"), _ mRow (nCol) = fnReplace ( _
fnGetResString ("ReportCPEvolve"), _
"[Pokémon]", sPokemonName) "[Pokémon]", sPokemonName)
nCol = nCol + 1 nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then If maEvBaseStats (nJ).bIsLastForm Then
@ -142,111 +168,24 @@ Sub subCreateReport ( _
nCol = nCol + 1 nCol = nCol + 1
End If End If
Next nJ Next nJ
' Fills in the header row
ReDim mData (0) As Variant
mData (0) = mRow mData (0) = mRow
For nI = 0 To UBound (maIVs)
mRow = Array ( _
"", "", "", "", "", _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina, "")
ReDim Preserve mRow (nTotalCols - 1) As Variant
For nJ = nLeadCols To nEvolved - 1
mRow (nJ) = ""
Next nJ
mData (nI + 1) = mRow
Next nI
' Fills the query information at the first row
mData (1) (0) = aBaseStats.sNo
mData (1) (1) = aQuery.sPokemonName
mData (1) (2) = aQuery.nCP
mData (1) (3) = aQuery.nHP
mData (1) (4) = aQuery.nStardust
oRange = oSheet.getCellRangeByPosition ( _ oRange = oSheet.getCellRangeByPosition ( _
0, 0, UBound (mData (0)), UBound (mData)) 0, 0, UBound (mData (0)), UBound (mData))
oRange.setDataArray (mData) oRange.setDataArray (mData)
oRange.setPropertyValue ("VertJustify", _ oRange.setPropertyValue ("VertJustify", _
com.sun.star.table.CellVertJustify.TOP) com.sun.star.table.CellVertJustify.TOP)
' Fills in the CP calculation.
For nI = 0 To UBound (maIVs)
sCPM = fnGetCPMFormula (maIVs (nI).fLevel)
sColIVAttack = "G" & (nI + 2)
sColIVDefense = "H" & (nI + 2)
sColIVStamina = "I" & (nI + 2)
oCell = oSheet.getCellByPosition (nLeadCols - 1, nI + 1)
sFormula = "=(" & sColIVAttack & "+" & sColIVDefense _
& "+" & sColIVStamina & ")/45"
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ("FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ("FormulaLocal", sFormulaLocal)
End If
nCol = nLeadCols
If aBaseStats.bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (aBaseStats, _
sColIVAttack, sColIVDefense, sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ("FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ("FormulaLocal", sFormulaLocal)
End If
nCol = nCol + 1
End If
For nJ = 0 To nEvolved - 1
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, sColIVStamina, sCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ("FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ("FormulaLocal", sFormulaLocal)
End If
nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, _
sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ( _
"FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ( _
"FormulaLocal", sFormulaLocal)
End If
nCol = nCol + 1
End If
Next nJ
Next nI
oRange = oSheet.getCellRangeByPosition ( _
0, 1, 0, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
1, 1, 1, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
2, 1, 2, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
3, 1, 3, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
4, 1, 4, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
9, 1, 9, UBound (mData))
oRange.setPropertyValue ("NumberFormat", 10)
oRange = oSheet.getCellRangeByPosition ( _ oRange = oSheet.getCellRangeByPosition ( _
nLeadCols, 0, nTotalCols - 1, 0) nLeadCols, 0, nTotalCols - 1, 0)
oRange.setPropertyValue ("IsTextWrapped", True) oRange.setPropertyValue ("IsTextWrapped", True)
' Sets the height of the header row
oRows = oSheet.getRows
oRows.getByIndex (0).setPropertyValue ("OptimalHeight", True)
' Sets the widths of the columns
oColumns = oSheet.getColumns oColumns = oSheet.getColumns
oColumns.getByIndex (0).setPropertyValue ("Width", 890) oColumns.getByIndex (0).setPropertyValue ("Width", 890)
oColumns.getByIndex (1).setPropertyValue ("Width", 2310) oColumns.getByIndex (1).setPropertyValue ("Width", 2310)
@ -262,8 +201,120 @@ Sub subCreateReport ( _
oColumns.getByIndex (nJ).setPropertyValue ( _ oColumns.getByIndex (nJ).setPropertyValue ( _
"Width", 2500) "Width", 2500)
Next nJ Next nJ
oRows = oSheet.getRows
oRows.getByIndex (0).setPropertyValue ("OptimalHeight", True) nStartRow = 1
' Append to the end on an existing spreadsheet
Else
nStartRow = 0
Do
nStartRow = nStartRow + 1
oCell = oSheet.getCellByPosition (5, nStartRow)
Loop While oCell.getString <> ""
End If
' Gathers the data rows.
ReDim mData (Ubound (maIVs)) As Variant
For nI = 0 To UBound (maIVs)
mRow = Array ( _
"", "", "", "", "", _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina, "")
ReDim Preserve mRow (nTotalCols - 1) As Variant
For nJ = nLeadCols To nEvolved - 1
mRow (nJ) = ""
Next nJ
mData (nI) = mRow
Next nI
' Fills the query information at the first row
mData (0) (0) = aBaseStats.sNo
mData (0) (1) = aQuery.sPokemonName
mData (0) (2) = aQuery.nCP
mData (0) (3) = aQuery.nHP
mData (0) (4) = aQuery.nStardust
oRange = oSheet.getCellRangeByPosition ( _
0, nStartRow, _
UBound (mData (0)), nStartRow + UBound (mData))
oRange.setDataArray (mData)
oRange.setPropertyValue ("VertJustify", _
com.sun.star.table.CellVertJustify.TOP)
' Fills in the CP calculation.
For nI = 0 To UBound (maIVs)
sCPM = fnGetCPMFormula (maIVs (nI).fLevel)
sColIVAttack = "G" & (nI + 2)
sColIVDefense = "H" & (nI + 2)
sColIVStamina = "I" & (nI + 2)
oCell = oSheet.getCellByPosition (nLeadCols - 1, nStartRow + nI)
sFormula = "=(" & sColIVAttack & "+" & sColIVDefense _
& "+" & sColIVStamina & ")/45"
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ("FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ("FormulaLocal", sFormulaLocal)
End If
nCol = nLeadCols
If aBaseStats.bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nStartRow + nI)
sFormula = fnGetCPFormula (aBaseStats, _
sColIVAttack, sColIVDefense, sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ("FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ("FormulaLocal", sFormulaLocal)
End If
nCol = nCol + 1
End If
For nJ = 0 To nEvolved - 1
oCell = oSheet.getCellByPosition (nCol, nStartRow + nI)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, sColIVStamina, sCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ("FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ("FormulaLocal", sFormulaLocal)
End If
nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nStartRow + nI)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, _
sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ( _
"FormulaLocal")
If sFormulaLocal <> sFormula Then
oCell.setPropertyValue ( _
"FormulaLocal", sFormulaLocal)
End If
nCol = nCol + 1
End If
Next nJ
Next nI
' Merge the lead cells.
oRange = oSheet.getCellRangeByPosition ( _
0, nStartRow, 0, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
1, nStartRow, 1, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
2, nStartRow, 2, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
3, nStartRow, 3, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
4, nStartRow, 4, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
9, nStartRow, 9, nStartRow + UBound (mData))
oRange.setPropertyValue ("NumberFormat", 10)
End Sub End Sub
' subSortIVs: Sorts the IVs ' subSortIVs: Sorts the IVs
@ -400,3 +451,67 @@ Function fnGetCPMFormula (fLevel As Double) As String
& "+POWER(" & mCPM (fLevel + 0.5) & ";2))/2)" & "+POWER(" & mCPM (fLevel + 0.5) & ";2))/2)"
End If End If
End Function End Function
' fnFindPokemonGOIVSheet: Finds the existing sheet for the result.
Function fnFindPokemonGOIVSheet (sPokemon As String) As Object
Dim oDoc As Object, sDocTitle As String
Dim oSheets As Object, nCount As Integer, oSheet As Object
Dim mNames () As String, nI As Integer
Dim mProps () As New com.sun.star.beans.PropertyValue
sDocTitle = "Pokémon GO IV"
oDoc = fnFindDocByTitle (sDocTitle)
If IsNull (oDoc) Then
oDoc = StarDesktop.loadComponentFromURL ( _
"private:factory/scalc", "_default", 0, mProps)
oDoc.setTitle (sDocTitle)
oSheets = oDoc.getSheets
mNames = oSheets.getElementNames
oSheets.insertNewByName (sPokemon, 0)
oSheet = oSheets.getByName (sPokemon)
For nI = 0 To UBound (mNames)
oSheets.removeByName (mNames (nI))
Next nI
Else
oSheet = fnFindSheetByName (oDoc, sPokemon)
If IsNull (oSheet) Then
oSheets = oDoc.getSheets
nCount = oSheets.getCount
oSheets.insertNewByName (sPokemon, nCount)
oSheet = oSheets.getByName (sPokemon)
End If
oDoc.getCurrentController.setActiveSheet (oSheet)
End If
fnFindPokemonGOIVSheet = oSheet
End Function
' fnFindDocByTitle: Finds the document by its title.
Function fnFindDocByTitle (sTitle) As Object
Dim oEnum As Object, oDoc As Object
oEnum = StarDesktop.getComponents.createEnumeration
Do While oEnum.hasMoreElements
oDoc = oEnum.nextElement
If oDoc.supportsService ( _
"com.sun.star.sheet.SpreadsheetDocument") Then
If oDoc.getTitle = sTitle Then
fnFindDocByTitle = oDoc
Exit Function
End If
End If
Loop
End Function
' fnFindSheetByName: Finds the spreadsheet by its name
Function fnFindSheetByName (oDoc As Object, sName As String) As Object
Dim oSheets As Object, mNames () As String, nI As Integer
oSheets = oDoc.getSheets
mNames = oSheets.getElementNames
For nI = 0 To UBound (mNames)
If mNames (nI) = sName Then
fnFindSheetByName = oSheets.getByIndex (nI)
Exit Function
End If
Next nI
End Function

View File

@ -1 +1 @@
0.7.8 0.8.0

View File

@ -2,8 +2,8 @@
<description xmlns="http://openoffice.org/extensions/update/2006" <description xmlns="http://openoffice.org/extensions/update/2006"
xmlns:xlink="http://www.w3.org/1999/xlink"> xmlns:xlink="http://www.w3.org/1999/xlink">
<identifier value="tw.idv.imacat.office.pokemongoiv" /> <identifier value="tw.idv.imacat.office.pokemongoiv" />
<version value="0.7.8" /> <version value="0.8.0" />
<update-download> <update-download>
<src xlink:href="https://sourceforge.net/projects/aoo-extensions/files/18585/26/pokemongoiv.oxt" /> <src xlink:href="https://sourceforge.net/projects/aoo-extensions/files/18585/27/pokemongoiv.oxt" />
</update-download> </update-download>
</description> </description>

View File

@ -56,6 +56,23 @@ Type aFindIVParam
bIsCancelled As Boolean bIsCancelled As Boolean
End Type End Type
Sub subGetPokemonSheet
Dim oDoc As Object
Dim oEnum As Object, oComponent As Object, sTitles As String
oDoc = fnCreateNewSpreadsheetDocument
oDoc.setTitle (&quot;Pokemon GO IV&quot;)
oEnum = StarDesktop.getComponents.createEnumeration
Do While oEnum.hasMoreElements
oComponent = oEnum.nextElement
If oComponent.supportsService (&quot;com.sun.star.sheet.SpreadsheetDocument&quot;) Then
If oComponent.getTitle = &quot;Pokemon GO IV&quot; Then
Xray oComponent
End If
End If
Loop
End Sub
&apos; subCreateReport: Creates the Pokémon GO IV report. &apos; subCreateReport: Creates the Pokémon GO IV report.
Sub subCreateReport ( _ Sub subCreateReport ( _
aBaseStats As aStats, aQuery As aFindIVParam, maIVs () As aIV) aBaseStats As aStats, aQuery As aFindIVParam, maIVs () As aIV)
@ -69,13 +86,12 @@ Sub subCreateReport ( _
Dim sColIVAttack As String, sColIVDefense As String Dim sColIVAttack As String, sColIVDefense As String
Dim sColIVStamina As String Dim sColIVStamina As String
Dim sPokemonName As String Dim sPokemonName As String
Dim mData (Ubound (maIVs) + 1) As Variant, mRow () As Variant Dim mLeadHead () As Variant, nStartRow As Integer
Dim mData (0) As Variant, mRow () As Variant
Dim maEvBaseStats () As Variant Dim maEvBaseStats () As Variant
Dim mProps () As New com.sun.star.beans.PropertyValue Dim mProps () As New com.sun.star.beans.PropertyValue
oDoc = StarDesktop.loadComponentFromURL ( _ oSheet = fnFindPokemonGOIVSheet (aQuery.sPokemonName)
&quot;private:factory/scalc&quot;, &quot;_default&quot;, 0, mProps)
oSheet = oDoc.getSheets.getByIndex (0)
nEvolved = UBound (aBaseStats.mEvolved) + 1 nEvolved = UBound (aBaseStats.mEvolved) + 1
If nEvolved &gt; 0 Then If nEvolved &gt; 0 Then
@ -98,8 +114,8 @@ Sub subCreateReport ( _
&apos; Sorts the IVs &apos; Sorts the IVs
subSortIVs (aBaseStats, maEvBaseStats, maIVs, fMaxLevel) subSortIVs (aBaseStats, maEvBaseStats, maIVs, fMaxLevel)
&apos; Fills in the report data. &apos; Gathers the header row.
mRow = Array ( _ mLeadHead = Array ( _
fnGetResString (&quot;ReportNo&quot;), _ fnGetResString (&quot;ReportNo&quot;), _
fnGetResString (&quot;ReportPokemon&quot;), _ fnGetResString (&quot;ReportPokemon&quot;), _
fnGetResString (&quot;ReportCP&quot;), _ fnGetResString (&quot;ReportCP&quot;), _
@ -110,8 +126,10 @@ Sub subCreateReport ( _
fnGetResString (&quot;ReportDefense&quot;), _ fnGetResString (&quot;ReportDefense&quot;), _
fnGetResString (&quot;ReportStamina&quot;), _ fnGetResString (&quot;ReportStamina&quot;), _
fnGetResString (&quot;ReportIVPercent&quot;)) fnGetResString (&quot;ReportIVPercent&quot;))
nLeadCols = UBound (mRow) + 1 nLeadCols = UBound (mLeadHead) + 1
&apos; Calculating how many columns do we need to fill in the
&apos; CP of the evolved forms.
nTotalCols = nLeadCols nTotalCols = nLeadCols
If aBaseStats.bIsLastForm Then If aBaseStats.bIsLastForm Then
nTotalCols = nTotalCols + 1 nTotalCols = nTotalCols + 1
@ -123,17 +141,25 @@ Sub subCreateReport ( _
End If End If
Next nJ Next nJ
&apos; Adds the header row if this is a new spreadsheet
oCell = oSheet.getCellByPosition (0, 0)
If oCell.getString = &quot;&quot; Then
&apos; The leading columns of the header row
mRow = mLeadHead
&apos; Fill in the header row with the CP of the evolved forms.
ReDim Preserve mRow (nTotalCols - 1) As Variant ReDim Preserve mRow (nTotalCols - 1) As Variant
nCol = nLeadCols nCol = nLeadCols
If aBaseStats.bIsLastForm Then If aBaseStats.bIsLastForm Then
mRow (nCol) = fnReplace (fnGetResString (&quot;ReportCPPowerUp&quot;), _ mRow (nCol) = fnReplace ( _
fnGetResString (&quot;ReportCPPowerUp&quot;), _
&quot;[Level]&quot;, fMaxLevel) &quot;[Level]&quot;, fMaxLevel)
nCol = nCol + 1 nCol = nCol + 1
End If End If
For nJ = 0 To nEvolved - 1 For nJ = 0 To nEvolved - 1
sPokemonName = fnGetResString ( _ sPokemonName = fnGetResString ( _
&quot;Pokemon&quot; &amp; aBaseStats.mEvolved (nJ)) &quot;Pokemon&quot; &amp; aBaseStats.mEvolved (nJ))
mRow (nCol) = fnReplace (fnGetResString (&quot;ReportCPEvolve&quot;), _ mRow (nCol) = fnReplace ( _
fnGetResString (&quot;ReportCPEvolve&quot;), _
&quot;[Pokémon]&quot;, sPokemonName) &quot;[Pokémon]&quot;, sPokemonName)
nCol = nCol + 1 nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then If maEvBaseStats (nJ).bIsLastForm Then
@ -144,111 +170,24 @@ Sub subCreateReport ( _
nCol = nCol + 1 nCol = nCol + 1
End If End If
Next nJ Next nJ
&apos; Fills in the header row
ReDim mData (0) As Variant
mData (0) = mRow mData (0) = mRow
For nI = 0 To UBound (maIVs)
mRow = Array ( _
&quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina, &quot;&quot;)
ReDim Preserve mRow (nTotalCols - 1) As Variant
For nJ = nLeadCols To nEvolved - 1
mRow (nJ) = &quot;&quot;
Next nJ
mData (nI + 1) = mRow
Next nI
&apos; Fills the query information at the first row
mData (1) (0) = aBaseStats.sNo
mData (1) (1) = aQuery.sPokemonName
mData (1) (2) = aQuery.nCP
mData (1) (3) = aQuery.nHP
mData (1) (4) = aQuery.nStardust
oRange = oSheet.getCellRangeByPosition ( _ oRange = oSheet.getCellRangeByPosition ( _
0, 0, UBound (mData (0)), UBound (mData)) 0, 0, UBound (mData (0)), UBound (mData))
oRange.setDataArray (mData) oRange.setDataArray (mData)
oRange.setPropertyValue (&quot;VertJustify&quot;, _ oRange.setPropertyValue (&quot;VertJustify&quot;, _
com.sun.star.table.CellVertJustify.TOP) com.sun.star.table.CellVertJustify.TOP)
&apos; Fills in the CP calculation.
For nI = 0 To UBound (maIVs)
sCPM = fnGetCPMFormula (maIVs (nI).fLevel)
sColIVAttack = &quot;G&quot; &amp; (nI + 2)
sColIVDefense = &quot;H&quot; &amp; (nI + 2)
sColIVStamina = &quot;I&quot; &amp; (nI + 2)
oCell = oSheet.getCellByPosition (nLeadCols - 1, nI + 1)
sFormula = &quot;=(&quot; &amp; sColIVAttack &amp; &quot;+&quot; &amp; sColIVDefense _
&amp; &quot;+&quot; &amp; sColIVStamina &amp; &quot;)/45&quot;
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue (&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue (&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nLeadCols
If aBaseStats.bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (aBaseStats, _
sColIVAttack, sColIVDefense, sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue (&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue (&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nCol + 1
End If
For nJ = 0 To nEvolved - 1
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, sColIVStamina, sCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue (&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue (&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nI + 1)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, _
sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ( _
&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue ( _
&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nCol + 1
End If
Next nJ
Next nI
oRange = oSheet.getCellRangeByPosition ( _
0, 1, 0, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
1, 1, 1, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
2, 1, 2, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
3, 1, 3, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
4, 1, 4, UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
9, 1, 9, UBound (mData))
oRange.setPropertyValue (&quot;NumberFormat&quot;, 10)
oRange = oSheet.getCellRangeByPosition ( _ oRange = oSheet.getCellRangeByPosition ( _
nLeadCols, 0, nTotalCols - 1, 0) nLeadCols, 0, nTotalCols - 1, 0)
oRange.setPropertyValue (&quot;IsTextWrapped&quot;, True) oRange.setPropertyValue (&quot;IsTextWrapped&quot;, True)
&apos; Sets the height of the header row
oRows = oSheet.getRows
oRows.getByIndex (0).setPropertyValue (&quot;OptimalHeight&quot;, True)
&apos; Sets the widths of the columns
oColumns = oSheet.getColumns oColumns = oSheet.getColumns
oColumns.getByIndex (0).setPropertyValue (&quot;Width&quot;, 890) oColumns.getByIndex (0).setPropertyValue (&quot;Width&quot;, 890)
oColumns.getByIndex (1).setPropertyValue (&quot;Width&quot;, 2310) oColumns.getByIndex (1).setPropertyValue (&quot;Width&quot;, 2310)
@ -264,8 +203,120 @@ Sub subCreateReport ( _
oColumns.getByIndex (nJ).setPropertyValue ( _ oColumns.getByIndex (nJ).setPropertyValue ( _
&quot;Width&quot;, 2500) &quot;Width&quot;, 2500)
Next nJ Next nJ
oRows = oSheet.getRows
oRows.getByIndex (0).setPropertyValue (&quot;OptimalHeight&quot;, True) nStartRow = 1
&apos; Append to the end on an existing spreadsheet
Else
nStartRow = 0
Do
nStartRow = nStartRow + 1
oCell = oSheet.getCellByPosition (5, nStartRow)
Loop While oCell.getString &lt;&gt; &quot;&quot;
End If
&apos; Gathers the data rows.
ReDim mData (Ubound (maIVs)) As Variant
For nI = 0 To UBound (maIVs)
mRow = Array ( _
&quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, _
maIVs (nI).fLevel, maIVs (nI).nAttack, _
maIVs (nI).nDefense, maIVs (nI).nStamina, &quot;&quot;)
ReDim Preserve mRow (nTotalCols - 1) As Variant
For nJ = nLeadCols To nEvolved - 1
mRow (nJ) = &quot;&quot;
Next nJ
mData (nI) = mRow
Next nI
&apos; Fills the query information at the first row
mData (0) (0) = aBaseStats.sNo
mData (0) (1) = aQuery.sPokemonName
mData (0) (2) = aQuery.nCP
mData (0) (3) = aQuery.nHP
mData (0) (4) = aQuery.nStardust
oRange = oSheet.getCellRangeByPosition ( _
0, nStartRow, _
UBound (mData (0)), nStartRow + UBound (mData))
oRange.setDataArray (mData)
oRange.setPropertyValue (&quot;VertJustify&quot;, _
com.sun.star.table.CellVertJustify.TOP)
&apos; Fills in the CP calculation.
For nI = 0 To UBound (maIVs)
sCPM = fnGetCPMFormula (maIVs (nI).fLevel)
sColIVAttack = &quot;G&quot; &amp; (nI + 2)
sColIVDefense = &quot;H&quot; &amp; (nI + 2)
sColIVStamina = &quot;I&quot; &amp; (nI + 2)
oCell = oSheet.getCellByPosition (nLeadCols - 1, nStartRow + nI)
sFormula = &quot;=(&quot; &amp; sColIVAttack &amp; &quot;+&quot; &amp; sColIVDefense _
&amp; &quot;+&quot; &amp; sColIVStamina &amp; &quot;)/45&quot;
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue (&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue (&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nLeadCols
If aBaseStats.bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nStartRow + nI)
sFormula = fnGetCPFormula (aBaseStats, _
sColIVAttack, sColIVDefense, sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue (&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue (&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nCol + 1
End If
For nJ = 0 To nEvolved - 1
oCell = oSheet.getCellByPosition (nCol, nStartRow + nI)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, sColIVStamina, sCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue (&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue (&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nCol + 1
If maEvBaseStats (nJ).bIsLastForm Then
oCell = oSheet.getCellByPosition (nCol, nStartRow + nI)
sFormula = fnGetCPFormula (maEvBaseStats (nJ), _
sColIVAttack, sColIVDefense, _
sColIVStamina, sMaxCPM)
oCell.setFormula (sFormula)
sFormulaLocal = oCell.getPropertyValue ( _
&quot;FormulaLocal&quot;)
If sFormulaLocal &lt;&gt; sFormula Then
oCell.setPropertyValue ( _
&quot;FormulaLocal&quot;, sFormulaLocal)
End If
nCol = nCol + 1
End If
Next nJ
Next nI
&apos; Merge the lead cells.
oRange = oSheet.getCellRangeByPosition ( _
0, nStartRow, 0, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
1, nStartRow, 1, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
2, nStartRow, 2, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
3, nStartRow, 3, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
4, nStartRow, 4, nStartRow + UBound (mData))
oRange.merge (True)
oRange = oSheet.getCellRangeByPosition ( _
9, nStartRow, 9, nStartRow + UBound (mData))
oRange.setPropertyValue (&quot;NumberFormat&quot;, 10)
End Sub End Sub
&apos; subSortIVs: Sorts the IVs &apos; subSortIVs: Sorts the IVs
@ -402,4 +453,68 @@ Function fnGetCPMFormula (fLevel As Double) As String
&amp; &quot;+POWER(&quot; &amp; mCPM (fLevel + 0.5) &amp; &quot;;2))/2)&quot; &amp; &quot;+POWER(&quot; &amp; mCPM (fLevel + 0.5) &amp; &quot;;2))/2)&quot;
End If End If
End Function End Function
&apos; fnFindPokemonGOIVSheet: Finds the existing sheet for the result.
Function fnFindPokemonGOIVSheet (sPokemon As String) As Object
Dim oDoc As Object, sDocTitle As String
Dim oSheets As Object, nCount As Integer, oSheet As Object
Dim mNames () As String, nI As Integer
Dim mProps () As New com.sun.star.beans.PropertyValue
sDocTitle = &quot;Pokémon GO IV&quot;
oDoc = fnFindDocByTitle (sDocTitle)
If IsNull (oDoc) Then
oDoc = StarDesktop.loadComponentFromURL ( _
&quot;private:factory/scalc&quot;, &quot;_default&quot;, 0, mProps)
oDoc.setTitle (sDocTitle)
oSheets = oDoc.getSheets
mNames = oSheets.getElementNames
oSheets.insertNewByName (sPokemon, 0)
oSheet = oSheets.getByName (sPokemon)
For nI = 0 To UBound (mNames)
oSheets.removeByName (mNames (nI))
Next nI
Else
oSheet = fnFindSheetByName (oDoc, sPokemon)
If IsNull (oSheet) Then
oSheets = oDoc.getSheets
nCount = oSheets.getCount
oSheets.insertNewByName (sPokemon, nCount)
oSheet = oSheets.getByName (sPokemon)
End If
oDoc.getCurrentController.setActiveSheet (oSheet)
End If
fnFindPokemonGOIVSheet = oSheet
End Function
&apos; fnFindDocByTitle: Finds the document by its title.
Function fnFindDocByTitle (sTitle) As Object
Dim oEnum As Object, oDoc As Object
oEnum = StarDesktop.getComponents.createEnumeration
Do While oEnum.hasMoreElements
oDoc = oEnum.nextElement
If oDoc.supportsService ( _
&quot;com.sun.star.sheet.SpreadsheetDocument&quot;) Then
If oDoc.getTitle = sTitle Then
fnFindDocByTitle = oDoc
Exit Function
End If
End If
Loop
End Function
&apos; fnFindSheetByName: Finds the spreadsheet by its name
Function fnFindSheetByName (oDoc As Object, sName As String) As Object
Dim oSheets As Object, mNames () As String, nI As Integer
oSheets = oDoc.getSheets
mNames = oSheets.getElementNames
For nI = 0 To UBound (mNames)
If mNames (nI) = sName Then
fnFindSheetByName = oSheets.getByIndex (nI)
Exit Function
End If
Next nI
End Function
</script:module> </script:module>