Restructured the project directory: Moved the sources into a subdirectory. Added build.xml, LICENSE, VERSION for distribution.
This commit is contained in:
		
							
								
								
									
										331
									
								
								StatTool/1CorRel.vb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										331
									
								
								StatTool/1CorRel.vb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,331 @@
 | 
			
		||||
' Copyright (c) 2016 imacat.
 | 
			
		||||
' 
 | 
			
		||||
' Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
' you may not use this file except in compliance with the License.
 | 
			
		||||
' You may obtain a copy of the License at
 | 
			
		||||
' 
 | 
			
		||||
'     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
' 
 | 
			
		||||
' Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
' distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
' See the License for the specific language governing permissions and
 | 
			
		||||
' limitations under the License.
 | 
			
		||||
 | 
			
		||||
' 1CorRel: The macros to for generating the report of the Pearson’s correlation coefficient
 | 
			
		||||
'   by imacat <imacat@mail.imacat.idv.tw>, 2016-08-10
 | 
			
		||||
 | 
			
		||||
Option Explicit
 | 
			
		||||
 | 
			
		||||
' subRunCorrelation: Runs the Pearson’s correlation coefficient.
 | 
			
		||||
Sub subRunCorrelation As Object
 | 
			
		||||
	Dim oRange As Object
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim oSheet As Object, mRanges As Object
 | 
			
		||||
	Dim sExisted As String, nResult As Integer
 | 
			
		||||
	
 | 
			
		||||
	DialogLibraries.loadLibrary "StatTool"
 | 
			
		||||
	
 | 
			
		||||
	' Asks the user for the data range
 | 
			
		||||
	oRange = fnAskDataRange (ThisComponent)
 | 
			
		||||
	If IsNull (oRange) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Specifies the data
 | 
			
		||||
	mRanges = fnSpecifyData (oRange, _
 | 
			
		||||
		"&3.Dlg2SpecData.txtPrompt1.Label1CorRel", _
 | 
			
		||||
		"&6.Dlg2SpecData.txtPrompt2.Label1CorRel")
 | 
			
		||||
	If IsNull (mRanges) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Checks the existing report
 | 
			
		||||
	oSheets = ThisComponent.getSheets
 | 
			
		||||
	sSheetName = oRange.getSpreadsheet.getName
 | 
			
		||||
	If oSheets.hasByName (sSheetName & "_correl") Then
 | 
			
		||||
		sExisted = "Spreadsheet """ & sSheetName & "_correl"" exists.  Overwrite?"
 | 
			
		||||
		nResult = MsgBox (sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
 | 
			
		||||
		If nResult = IDNO Then
 | 
			
		||||
			Exit Sub
 | 
			
		||||
		End If
 | 
			
		||||
		' Drops the existing report
 | 
			
		||||
		oSheets.removeByname (sSheetName & "_correl")
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Reports the paired T-test.
 | 
			
		||||
	subReportCorrelation (ThisComponent, mRanges (0), mRanges (1))
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_correl")
 | 
			
		||||
	
 | 
			
		||||
	' Adds an X-Y diagram.
 | 
			
		||||
	subAddChart (oSheet, mRanges (0), mRanges (1))
 | 
			
		||||
	
 | 
			
		||||
	' Makes the report sheet active.
 | 
			
		||||
	ThisComponent.getCurrentController.setActiveSheet (oSheet)
 | 
			
		||||
End Sub
 | 
			
		||||
 | 
			
		||||
' subAddChart: Adds a chart for the data
 | 
			
		||||
Sub subAddChart (oSheet As Object, oDataXRange As Object, oDataYRange As Object)
 | 
			
		||||
	Dim oCharts As Object, oChart As Object
 | 
			
		||||
	Dim oChartDoc As Object, oDiagram As Object
 | 
			
		||||
	Dim aPos As New com.sun.star.awt.Rectangle
 | 
			
		||||
	Dim mAddrs (1) As New com.sun.star.table.CellRangeAddress
 | 
			
		||||
	Dim sTitle As String
 | 
			
		||||
	Dim oProvider As Object, oData As Object
 | 
			
		||||
	Dim sRange As String, mData () As Object
 | 
			
		||||
	
 | 
			
		||||
	' Adds the chart
 | 
			
		||||
	With aPos
 | 
			
		||||
		.X = 0
 | 
			
		||||
		.Y = 3510
 | 
			
		||||
		.Width = 10000
 | 
			
		||||
		.Height = 10000
 | 
			
		||||
	End With
 | 
			
		||||
	mAddrs (0) = oDataXRange.getRangeAddress
 | 
			
		||||
	mAddrs (1) = oDataYRange.getRangeAddress
 | 
			
		||||
	oCharts = oSheet.getCharts
 | 
			
		||||
	oCharts.addNewByName (oSheet.getName, aPos, mAddrs, True, False)
 | 
			
		||||
	oChart = oCharts.getByName (oSheet.getName)
 | 
			
		||||
	oChartDoc = oChart.getEmbeddedObject
 | 
			
		||||
	
 | 
			
		||||
	BasicLibraries.loadLibrary "XrayTool"
 | 
			
		||||
	oDiagram = oChartDoc.createInstance ( _
 | 
			
		||||
		"com.sun.star.chart.XYDiagram")
 | 
			
		||||
	oDiagram.setPropertyValue ("Lines", False)
 | 
			
		||||
	oDiagram.setPropertyValue ("HasXAxisGrid", False)
 | 
			
		||||
	oDiagram.setPropertyValue ("HasYAxisGrid", False)
 | 
			
		||||
	sTitle = oDataXRange.getCellByPosition (0, 0).getString
 | 
			
		||||
	oDiagram.getXAxisTitle.setPropertyValue ("String", sTitle)
 | 
			
		||||
	sTitle = oDataYRange.getCellByPosition (0, 0).getString
 | 
			
		||||
	oDiagram.getYAxisTitle.setPropertyValue ("String", sTitle)
 | 
			
		||||
	oDiagram.getXAxis.setPropertyValue ("Min", 0)
 | 
			
		||||
	oDiagram.getYAxis.setPropertyValue ("Min", 0)
 | 
			
		||||
	oChartDoc.setDiagram (oDiagram)
 | 
			
		||||
	
 | 
			
		||||
	oProvider = oChartDoc.getDataProvider
 | 
			
		||||
	mData = oChartDoc.getDataSequences
 | 
			
		||||
	sRange = oDataXRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	mData (0).setLabel (oData)
 | 
			
		||||
	sRange = oDataXRange.getCellRangeByPosition(0, 1, 0, oDataXRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	oData.Role = "values-x"
 | 
			
		||||
	mData (0).setValues (oData)
 | 
			
		||||
	sRange = oDataYRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	mData (1).setLabel (oData)
 | 
			
		||||
	sRange = oDataYRange.getCellRangeByPosition(0, 1, 0, oDataYRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	oData.Role = "values-y"
 | 
			
		||||
	mData (1).setValues (oData)
 | 
			
		||||
	
 | 
			
		||||
	oChartDoc.setPropertyValue ("HasLegend", False)
 | 
			
		||||
End Sub
 | 
			
		||||
 | 
			
		||||
' subReportCorrelation: Reports the Pearson’s correlation coefficient
 | 
			
		||||
Sub subReportCorrelation (oDoc As Object, oDataXRange As Object, oDataYRange As Object)
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim mNames () As String, nI As Integer, nSheetIndex As Integer
 | 
			
		||||
	Dim oSheet As Object, oColumns As Object, nRow As Integer
 | 
			
		||||
	Dim oCell As Object, oCells As Object, oCursor As Object
 | 
			
		||||
	Dim nN As Integer, sFormula As String
 | 
			
		||||
	Dim sNotes As String, nPos As Integer
 | 
			
		||||
	Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer
 | 
			
		||||
	Dim aBorderSingle As New com.sun.star.table.BorderLine
 | 
			
		||||
	Dim aBorderDouble As New com.sun.star.table.BorderLine
 | 
			
		||||
	Dim sCellXLabel As String, sCellsXData As String
 | 
			
		||||
	Dim sCellYLabel As String, sCellsYData As String
 | 
			
		||||
	Dim sCellN As String, sCellR As String
 | 
			
		||||
	
 | 
			
		||||
	oSheets = oDoc.getSheets
 | 
			
		||||
	sSheetName = oDataXRange.getSpreadsheet.getName
 | 
			
		||||
	mNames = oSheets.getElementNames
 | 
			
		||||
	For nI = 0 To UBound (mNames)
 | 
			
		||||
		If mNames (nI) = sSheetName Then
 | 
			
		||||
			nSheetIndex = nI
 | 
			
		||||
		End If
 | 
			
		||||
	Next nI
 | 
			
		||||
	oSheets.insertNewByName (sSheetName & "_correl", nSheetIndex + 1)
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_correl")
 | 
			
		||||
	
 | 
			
		||||
	nN = oDataXRange.getRows.getCount - 1
 | 
			
		||||
	sCellXLabel = fnGetRangeName (oDataXRange.getCellByPosition (0, 0))
 | 
			
		||||
	sCellsXData = fnGetRangeName (oDataXRange.getCellRangeByPosition (0, 1, 0, nN))
 | 
			
		||||
	sCellYLabel = fnGetRangeName (oDataYRange.getCellByPosition (0, 0))
 | 
			
		||||
	sCellsYData = fnGetRangeName (oDataYRange.getCellRangeByPosition (0, 1, 0, nN))
 | 
			
		||||
	
 | 
			
		||||
	' Obtains the format parameters for the report.
 | 
			
		||||
	nFormatN = fnQueryFormat (oDoc, "#,##0")
 | 
			
		||||
	nFormatF = fnQueryFormat (oDoc, "#,###.000")
 | 
			
		||||
	nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000")
 | 
			
		||||
	
 | 
			
		||||
	aBorderSingle.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.InnerLineWidth = 2
 | 
			
		||||
	aBorderDouble.LineDistance = 2
 | 
			
		||||
	
 | 
			
		||||
	' Sets the column widths of the report.
 | 
			
		||||
	oColumns = oSheet.getColumns
 | 
			
		||||
	oColumns.getByIndex (0).setPropertyValue ("Width", 3060)
 | 
			
		||||
	oColumns.getByIndex (1).setPropertyValue ("Width", 3060)
 | 
			
		||||
	oColumns.getByIndex (2).setPropertyValue ("Width", 2080)
 | 
			
		||||
	oColumns.getByIndex (3).setPropertyValue ("Width", 2080)
 | 
			
		||||
	oColumns.getByIndex (4).setPropertyValue ("Width", 2080)
 | 
			
		||||
	
 | 
			
		||||
	nRow = -2
 | 
			
		||||
	
 | 
			
		||||
	' Correlation
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Pearson’s Correlation")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("X")
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	oCell.setString ("Y")
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("N")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	oCell.setString ("r")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	oCell.setString ("p")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	
 | 
			
		||||
	' The test result.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = "=" & sCellYLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=COUNT(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCellN = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=CORREL(" & sCellsXData & ";" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCellR = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=TDIST(" & sCellR & "*SQRT((" & sCellN & "-2)/(1-" & sCellR & "*" & sCellR & "))" & ";" & sCellN & "-2;2)"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
	
 | 
			
		||||
	' The foot notes of the test.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _
 | 
			
		||||
		"H0: ρ=0 (the populations of the two groups are irrelavent)." & Chr (10) & _
 | 
			
		||||
		"H1: ρ≠0 (the populations of the two groups are relevant) if the probability (p) is small enough.")
 | 
			
		||||
	oCell.setPropertyValue ("IsTextWrapped", True)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	sNotes = oCell.getString
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	nPos = InStr (sNotes, "p<")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "(p)")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (sNotes, "ρ")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "ρ")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "H0")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	nPos = InStr (sNotes, "H1")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (1, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (2, nRow - 2, 4, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (1, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 4, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
End Sub
 | 
			
		||||
							
								
								
									
										645
									
								
								StatTool/2PTTest.vb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										645
									
								
								StatTool/2PTTest.vb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,645 @@
 | 
			
		||||
' Copyright (c) 2016 imacat.
 | 
			
		||||
' 
 | 
			
		||||
' Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
' you may not use this file except in compliance with the License.
 | 
			
		||||
' You may obtain a copy of the License at
 | 
			
		||||
' 
 | 
			
		||||
'     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
' 
 | 
			
		||||
' Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
' distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
' See the License for the specific language governing permissions and
 | 
			
		||||
' limitations under the License.
 | 
			
		||||
 | 
			
		||||
' 2PTTest: The macros to for generating the report of paired T-Test
 | 
			
		||||
'   by imacat <imacat@mail.imacat.idv.tw>, 2016-08-11
 | 
			
		||||
 | 
			
		||||
Option Explicit
 | 
			
		||||
 | 
			
		||||
' subRunPairedTTest: Runs the paired T-test.
 | 
			
		||||
Sub subRunPairedTTest As Object
 | 
			
		||||
	Dim oRange As Object
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim oSheet As Object, mRanges As Object
 | 
			
		||||
	Dim sExisted As String, nResult As Integer
 | 
			
		||||
	
 | 
			
		||||
	DialogLibraries.loadLibrary "StatTool"
 | 
			
		||||
	
 | 
			
		||||
	' Asks the user for the data range
 | 
			
		||||
	oRange = fnAskDataRange (ThisComponent)
 | 
			
		||||
	If IsNull (oRange) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Specifies the data
 | 
			
		||||
	mRanges = fnSpecifyData (oRange, _
 | 
			
		||||
		"&3.Dlg2SpecData.txtPrompt1.Label1CorRel", _
 | 
			
		||||
		"&6.Dlg2SpecData.txtPrompt2.Label1CorRel")
 | 
			
		||||
	If IsNull (mRanges) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Checks the existing report
 | 
			
		||||
	oSheets = ThisComponent.getSheets
 | 
			
		||||
	sSheetName = oRange.getSpreadsheet.getName
 | 
			
		||||
	If oSheets.hasByName (sSheetName & "_ttest") Then
 | 
			
		||||
		sExisted = "Spreadsheet """ & sSheetName & "_ttest"" exists.  Overwrite?"
 | 
			
		||||
		nResult = MsgBox (sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
 | 
			
		||||
		If nResult = IDNO Then
 | 
			
		||||
			Exit Sub
 | 
			
		||||
		End If
 | 
			
		||||
		' Drops the existing report
 | 
			
		||||
		oSheets.removeByname (sSheetName & "_ttest")
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Reports the paired T-test.
 | 
			
		||||
	subReportPairedTTest (ThisComponent, mRanges (0), mRanges (1))
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_ttest")
 | 
			
		||||
	
 | 
			
		||||
	' Adds an X-Y diagram.
 | 
			
		||||
	subAddChart (oSheet, mRanges (0), mRanges (1))
 | 
			
		||||
	
 | 
			
		||||
	' Makes the report sheet active.
 | 
			
		||||
	ThisComponent.getCurrentController.setActiveSheet (oSheet)
 | 
			
		||||
End Sub
 | 
			
		||||
 | 
			
		||||
' subAddChart: Adds a chart for the data
 | 
			
		||||
Sub subAddChart (oSheet As Object, oDataXRange As Object, oDataYRange As Object)
 | 
			
		||||
	Dim oCharts As Object, oChart As Object
 | 
			
		||||
	Dim oChartDoc As Object, oDiagram As Object
 | 
			
		||||
	Dim aPos As New com.sun.star.awt.Rectangle
 | 
			
		||||
	Dim mAddrs (1) As New com.sun.star.table.CellRangeAddress
 | 
			
		||||
	Dim sTitle As String
 | 
			
		||||
	Dim oProvider As Object, oData As Object
 | 
			
		||||
	Dim sRange As String, mData () As Object
 | 
			
		||||
	
 | 
			
		||||
	' Adds the chart
 | 
			
		||||
	With aPos
 | 
			
		||||
		.X = 0
 | 
			
		||||
		.Y = 10000
 | 
			
		||||
		.Width = 10000
 | 
			
		||||
		.Height = 10000
 | 
			
		||||
	End With
 | 
			
		||||
	mAddrs (0) = oDataXRange.getRangeAddress
 | 
			
		||||
	mAddrs (1) = oDataYRange.getRangeAddress
 | 
			
		||||
	oCharts = oSheet.getCharts
 | 
			
		||||
	oCharts.addNewByName (oSheet.getName, aPos, mAddrs, True, False)
 | 
			
		||||
	oChart = oCharts.getByName (oSheet.getName)
 | 
			
		||||
	oChartDoc = oChart.getEmbeddedObject
 | 
			
		||||
	
 | 
			
		||||
	BasicLibraries.loadLibrary "XrayTool"
 | 
			
		||||
	oDiagram = oChartDoc.createInstance ( _
 | 
			
		||||
		"com.sun.star.chart.XYDiagram")
 | 
			
		||||
	oDiagram.setPropertyValue ("Lines", False)
 | 
			
		||||
	oDiagram.setPropertyValue ("HasXAxisGrid", False)
 | 
			
		||||
	oDiagram.setPropertyValue ("HasYAxisGrid", False)
 | 
			
		||||
	sTitle = oDataXRange.getCellByPosition (0, 0).getString
 | 
			
		||||
	oDiagram.getXAxisTitle.setPropertyValue ("String", sTitle)
 | 
			
		||||
	sTitle = oDataYRange.getCellByPosition (0, 0).getString
 | 
			
		||||
	oDiagram.getYAxisTitle.setPropertyValue ("String", sTitle)
 | 
			
		||||
	oDiagram.getXAxis.setPropertyValue ("Min", 0)
 | 
			
		||||
	oDiagram.getYAxis.setPropertyValue ("Min", 0)
 | 
			
		||||
	oChartDoc.setDiagram (oDiagram)
 | 
			
		||||
	
 | 
			
		||||
	oProvider = oChartDoc.getDataProvider
 | 
			
		||||
	mData = oChartDoc.getDataSequences
 | 
			
		||||
	sRange = oDataXRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	mData (0).setLabel (oData)
 | 
			
		||||
	sRange = oDataXRange.getCellRangeByPosition(0, 1, 0, oDataXRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	oData.Role = "values-x"
 | 
			
		||||
	mData (0).setValues (oData)
 | 
			
		||||
	sRange = oDataYRange.getCellByPosition(0, 0).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	mData (1).setLabel (oData)
 | 
			
		||||
	sRange = oDataYRange.getCellRangeByPosition(0, 1, 0, oDataYRange.getRows.getCount - 1).getPropertyValue ("AbsoluteName")
 | 
			
		||||
	oData = oProvider.createDataSequenceByRangeRepresentation (sRange)
 | 
			
		||||
	oData.Role = "values-y"
 | 
			
		||||
	mData (1).setValues (oData)
 | 
			
		||||
	
 | 
			
		||||
	oChartDoc.setPropertyValue ("HasLegend", False)
 | 
			
		||||
End Sub
 | 
			
		||||
 | 
			
		||||
' subReportPairedTTest: Reports the paired T-test
 | 
			
		||||
Sub subReportPairedTTest (oDoc As Object, oDataXRange As Object, oDataYRange As Object)
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim mNames () As String, nI As Integer, nSheetIndex As Integer
 | 
			
		||||
	Dim oSheet As Object, oColumns As Object, nRow As Integer
 | 
			
		||||
	Dim oCell As Object, oCells As Object, oCursor As Object
 | 
			
		||||
	Dim nN As Integer, sFormula As String
 | 
			
		||||
	Dim sNotes As String, nPos As Integer
 | 
			
		||||
	Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer
 | 
			
		||||
	Dim aBorderSingle As New com.sun.star.table.BorderLine
 | 
			
		||||
	Dim aBorderDouble As New com.sun.star.table.BorderLine
 | 
			
		||||
	Dim sCellXLabel As String, sCellsXData As String
 | 
			
		||||
	Dim sCellXN As String, sCellXMean As String, sCellXS As String
 | 
			
		||||
	Dim sCellYLabel As String, sCellsYData As String
 | 
			
		||||
	Dim sCellYN As String, sCellYMean As String, sCellYS As String
 | 
			
		||||
	Dim sCellN As String, sCellXYS As String, sCellR As String
 | 
			
		||||
	
 | 
			
		||||
	oSheets = oDoc.getSheets
 | 
			
		||||
	sSheetName = oDataXRange.getSpreadsheet.getName
 | 
			
		||||
	mNames = oSheets.getElementNames
 | 
			
		||||
	For nI = 0 To UBound (mNames)
 | 
			
		||||
		If mNames (nI) = sSheetName Then
 | 
			
		||||
			nSheetIndex = nI
 | 
			
		||||
		End If
 | 
			
		||||
	Next nI
 | 
			
		||||
	oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1)
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_ttest")
 | 
			
		||||
	
 | 
			
		||||
	nN = oDataXRange.getRows.getCount - 1
 | 
			
		||||
	sCellXLabel = fnGetRangeName (oDataXRange.getCellByPosition (0, 0))
 | 
			
		||||
	sCellsXData = fnGetRangeName (oDataXRange.getCellRangeByPosition (0, 1, 0, nN))
 | 
			
		||||
	sCellYLabel = fnGetRangeName (oDataYRange.getCellByPosition (0, 0))
 | 
			
		||||
	sCellsYData = fnGetRangeName (oDataYRange.getCellRangeByPosition (0, 1, 0, nN))
 | 
			
		||||
	
 | 
			
		||||
	' Obtains the format parameters for the report.
 | 
			
		||||
	nFormatN = fnQueryFormat (oDoc, "#,##0")
 | 
			
		||||
	nFormatF = fnQueryFormat (oDoc, "#,###.000")
 | 
			
		||||
	nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000")
 | 
			
		||||
	
 | 
			
		||||
	aBorderSingle.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.InnerLineWidth = 2
 | 
			
		||||
	aBorderDouble.LineDistance = 2
 | 
			
		||||
	
 | 
			
		||||
	' Sets the column widths of the report.
 | 
			
		||||
	oColumns = oSheet.getColumns
 | 
			
		||||
	oColumns.getByIndex (0).setPropertyValue ("Width", 3060)
 | 
			
		||||
	oColumns.getByIndex (1).setPropertyValue ("Width", 3060)
 | 
			
		||||
	oColumns.getByIndex (2).setPropertyValue ("Width", 2080)
 | 
			
		||||
	oColumns.getByIndex (3).setPropertyValue ("Width", 2080)
 | 
			
		||||
	oColumns.getByIndex (4).setPropertyValue ("Width", 2080)
 | 
			
		||||
	
 | 
			
		||||
	nRow = -2
 | 
			
		||||
	' Group description
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Sample Description")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 5, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Sample")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("N")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	oCell.setString ("X")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	oCell.setString ("s")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (5, nRow)
 | 
			
		||||
	oCell.setString ("sX")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE)
 | 
			
		||||
	
 | 
			
		||||
	' The first group
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=COUNT(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	sCellXN = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellXMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=STDEV(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellXS = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (5, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXS & "/SQRT(" & sCellXN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	
 | 
			
		||||
	' The second group
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=" & sCellYLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=COUNT(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	sCellYN = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellYMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=STDEV(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellYS = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (5, nRow)
 | 
			
		||||
	sFormula = "=" & sCellYS & "/SQRT(" & sCellYN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	
 | 
			
		||||
	' The difference between the two groups
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=""(""&" & sCellXLabel & "&""-""&" & sCellYLabel & "&"")"""
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 1, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXN
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	sCellN = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXMean & "-" & sCellYMean
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=SQRT(" & sCellXS & "*" & sCellXS & "-2*SUMPRODUCT(" & sCellsXData & ";" & sCellsYData & ")/(" & sCellN & "-1)+2*" & sCellXMean & "*" & sCellYMean & "*" & sCellN & "/(" & sCellN & "-1)+" & sCellYS & "*" & sCellYS & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellXYS = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (5, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXYS & "/SQRT(" & sCellN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 3)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 3, 5, nRow - 3)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow - 2, 0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow, 5, nRow)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	
 | 
			
		||||
	' Correlation
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Pearson’s Correlation")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 3, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("X1")
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	oCell.setString ("X2")
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("r")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	oCell.setString ("p")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	
 | 
			
		||||
	' The test result.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = "=" & sCellYLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=CORREL(" & sCellsXData & ";" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellR = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=TDIST(ABS(" & sCellR & ")*SQRT((" & sCellN & "-2)/(1-" & sCellR & "*" & sCellR & "))" & ";" & sCellN & "-2;2)"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
	
 | 
			
		||||
	' The foot notes of the test.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _
 | 
			
		||||
		"H0: ρ=0 (the populations of the two samples are irrelavent)." & Chr (10) & _
 | 
			
		||||
		"H1: ρ≠0 (the populations of the two samples are relevant) if the probability (p) is small enough.")
 | 
			
		||||
	oCell.setPropertyValue ("IsTextWrapped", True)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 3, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	sNotes = oCell.getString
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	nPos = InStr (sNotes, "p<")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "(p)")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (sNotes, "ρ")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "H0")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	nPos = InStr (sNotes, "H1")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (1, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (2, nRow - 2, 3, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (1, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 3, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	
 | 
			
		||||
	' Paired-samples T-test
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Paired-Samples T-test")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("X1")
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	oCell.setString ("X2")
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("t")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	oCell.setString ("df")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	oCell.setString ("p")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	
 | 
			
		||||
	' The test result.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = "=" & sCellYLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=(" & sCellXMean & "-" & sCellYMean & ")/SQRT((" & sCellXS & "*" & sCellXS & "+" & sCellYS & "*" & sCellYS & "-2*" & sCellR & "*" & sCellXS & "*" & sCellYS & ")/" & sCellN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=" & sCellN & "-1"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=TTEST(" & sCellsXData & ";" & sCellsYData & ";2;1)"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
	
 | 
			
		||||
	' The foot notes of the test.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _
 | 
			
		||||
		"H0: μ1=μ2 (the populations of the two samples have the same means)." & Chr (10) & _
 | 
			
		||||
		"H1: μ1≠μ2 (the populations of the two samples have different means) if the probability (p) is small enough.")
 | 
			
		||||
	oCell.setPropertyValue ("IsTextWrapped", True)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	sNotes = oCell.getString
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	nPos = InStr (sNotes, "p<")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "(p)")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (sNotes, "μ")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "μ")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "H0")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	nPos = InStr (sNotes, "H1")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (1, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (2, nRow - 2, 4, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (1, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 4, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
End Sub
 | 
			
		||||
							
								
								
									
										808
									
								
								StatTool/3ITTest.vb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										808
									
								
								StatTool/3ITTest.vb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,808 @@
 | 
			
		||||
' Copyright (c) 2016 imacat.
 | 
			
		||||
' 
 | 
			
		||||
' Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
' you may not use this file except in compliance with the License.
 | 
			
		||||
' You may obtain a copy of the License at
 | 
			
		||||
' 
 | 
			
		||||
'     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
' 
 | 
			
		||||
' Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
' distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
' See the License for the specific language governing permissions and
 | 
			
		||||
' limitations under the License.
 | 
			
		||||
 | 
			
		||||
' 3ITTest: The macros to for generating the report of independent T-Test
 | 
			
		||||
'   by imacat <imacat@mail.imacat.idv.tw>, 2016-08-24
 | 
			
		||||
 | 
			
		||||
Option Explicit
 | 
			
		||||
 | 
			
		||||
' subRunIndependentTTest: Runs the independent T-test.
 | 
			
		||||
Sub subRunIndependentTTest As Object
 | 
			
		||||
	Dim oRange As Object
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim oSheet As Object, mRanges As Object
 | 
			
		||||
	Dim sExisted As String, nResult As Integer
 | 
			
		||||
	
 | 
			
		||||
	DialogLibraries.loadLibrary "StatTool"
 | 
			
		||||
	
 | 
			
		||||
	' Asks the user for the data range
 | 
			
		||||
	oRange = fnAskDataRange (ThisComponent)
 | 
			
		||||
	If IsNull (oRange) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Specifies the data
 | 
			
		||||
	mRanges = fnSpecifyData (oRange, _
 | 
			
		||||
		"&10.Dlg2SpecData.txtPrompt1.Label3ITTest", _
 | 
			
		||||
		"&11.Dlg2SpecData.txtPrompt2.Label3ITTest")
 | 
			
		||||
	If IsNull (mRanges) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Checks the existing report
 | 
			
		||||
	oSheets = ThisComponent.getSheets
 | 
			
		||||
	sSheetName = oRange.getSpreadsheet.getName
 | 
			
		||||
	sExisted = ""
 | 
			
		||||
	If oSheets.hasByName (sSheetName & "_ttest") Then
 | 
			
		||||
		sExisted = sExisted & ", """ & sSheetName & "_ttest"""
 | 
			
		||||
	End If
 | 
			
		||||
	If oSheets.hasByName (sSheetName & "_ttesttmp") Then
 | 
			
		||||
		sExisted = sExisted & ", """ & sSheetName & "_ttesttmp"""
 | 
			
		||||
	End If
 | 
			
		||||
	If sExisted <> "" Then
 | 
			
		||||
		sExisted = Right (sExisted, Len (sExisted) - 2)
 | 
			
		||||
		If InStr (sExisted, ",") > 0 Then
 | 
			
		||||
			sExisted = "Spreadsheets " & sExisted & " exist.  Overwrite?"
 | 
			
		||||
		Else
 | 
			
		||||
			sExisted = "Spreadsheet " & sExisted & " exists.  Overwrite?"
 | 
			
		||||
		End If
 | 
			
		||||
		nResult = MsgBox (sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
 | 
			
		||||
		If nResult = IDNO Then
 | 
			
		||||
			Exit Sub
 | 
			
		||||
		End If
 | 
			
		||||
		' Drops the existing report
 | 
			
		||||
		If oSheets.hasByName (sSheetName & "_ttest") Then
 | 
			
		||||
			oSheets.removeByname (sSheetName & "_ttest")
 | 
			
		||||
		End If
 | 
			
		||||
		If oSheets.hasByName (sSheetName & "_ttesttmp") Then
 | 
			
		||||
			oSheets.removeByname (sSheetName & "_ttesttmp")
 | 
			
		||||
		End If
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Reports the independent T-test.
 | 
			
		||||
	subReportIndependentTTest (ThisComponent, mRanges (0), mRanges (1))
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_ttest")
 | 
			
		||||
	
 | 
			
		||||
	' Makes the report sheet active.
 | 
			
		||||
	ThisComponent.getCurrentController.setActiveSheet (oSheet)
 | 
			
		||||
End Sub
 | 
			
		||||
 | 
			
		||||
' subReportIndependentTTest: Reports the independent T-test
 | 
			
		||||
Sub subReportIndependentTTest (oDoc As Object, oLabelColumn As Object, oScoreColumn As Object)
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim mNames () As String, nI As Integer, nSheetIndex As Integer
 | 
			
		||||
	Dim oSheet As Object, oColumns As Object, nRow As Integer
 | 
			
		||||
	Dim oCell As Object, oCells As Object, oCursor As Object, oTempDataRange As Object
 | 
			
		||||
	Dim nN As Integer, sFormula As String, sSP2 As String
 | 
			
		||||
	Dim sNotes As String, nPos As Integer
 | 
			
		||||
	Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer
 | 
			
		||||
	Dim aBorderSingle As New com.sun.star.table.BorderLine
 | 
			
		||||
	Dim aBorderDouble As New com.sun.star.table.BorderLine
 | 
			
		||||
	Dim sCellXLabel As String, sCellsXData As String
 | 
			
		||||
	Dim sCellXN As String, sCellXMean As String, sCellXS As String
 | 
			
		||||
	Dim sCellYLabel As String, sCellsYData As String
 | 
			
		||||
	Dim sCellYN As String, sCellYMean As String, sCellYS As String
 | 
			
		||||
	Dim sCellF As String, sCellsN As String, sCellN As String
 | 
			
		||||
	
 | 
			
		||||
	oSheets = oDoc.getSheets
 | 
			
		||||
	sSheetName = oLabelColumn.getSpreadsheet.getName
 | 
			
		||||
	mNames = oSheets.getElementNames
 | 
			
		||||
	For nI = 0 To UBound (mNames)
 | 
			
		||||
		If mNames (nI) = sSheetName Then
 | 
			
		||||
			nSheetIndex = nI
 | 
			
		||||
		End If
 | 
			
		||||
	Next nI
 | 
			
		||||
	
 | 
			
		||||
	oSheets.insertNewByName (sSheetName & "_ttesttmp", nSheetIndex + 1)
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_ttesttmp")
 | 
			
		||||
	oTempDataRange = fnCollectIndependentTTestData (oSheet, oLabelColumn, oScoreColumn)
 | 
			
		||||
	
 | 
			
		||||
	oSheets.insertNewByName (sSheetName & "_ttest", nSheetIndex + 1)
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_ttest")
 | 
			
		||||
	
 | 
			
		||||
	sCellXLabel = fnGetRangeName (oTempDataRange.getCellByPosition (0, 0))
 | 
			
		||||
	nN = oTempDataRange.getCellByPosition (0, oTempDataRange.getRows.getCount - 3).getValue
 | 
			
		||||
	oCells = oTempDataRange.getCellRangeByPosition (0, 1, 0, nN)
 | 
			
		||||
	sCellsXData = fnGetRangeName (oCells)
 | 
			
		||||
	sCellYLabel = fnGetRangeName (oTempDataRange.getCellByPosition (1, 0))
 | 
			
		||||
	nN = oTempDataRange.getCellByPosition (1, oTempDataRange.getRows.getCount - 3).getValue
 | 
			
		||||
	oCells = oTempDataRange.getCellRangeByPosition (1, 1, 1, nN)
 | 
			
		||||
	sCellsYData = fnGetRangeName (oCells)
 | 
			
		||||
	
 | 
			
		||||
	' Obtains the format parameters for the report.
 | 
			
		||||
	nFormatN = fnQueryFormat (oDoc, "#,##0")
 | 
			
		||||
	nFormatF = fnQueryFormat (oDoc, "#,###.000")
 | 
			
		||||
	nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000")
 | 
			
		||||
	
 | 
			
		||||
	aBorderSingle.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.InnerLineWidth = 2
 | 
			
		||||
	aBorderDouble.LineDistance = 2
 | 
			
		||||
	
 | 
			
		||||
	' Sets the column widths of the report.
 | 
			
		||||
	oColumns = oSheet.getColumns
 | 
			
		||||
	oColumns.getByIndex (0).setPropertyValue ("Width", 3060)
 | 
			
		||||
	oColumns.getByIndex (1).setPropertyValue ("Width", 2080)
 | 
			
		||||
	oColumns.getByIndex (2).setPropertyValue ("Width", 2080)
 | 
			
		||||
	oColumns.getByIndex (3).setPropertyValue ("Width", 2080)
 | 
			
		||||
	oColumns.getByIndex (4).setPropertyValue ("Width", 2080)
 | 
			
		||||
	
 | 
			
		||||
	nRow = -2
 | 
			
		||||
	
 | 
			
		||||
	' Group description
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Group Description")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Group")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	oCell.setString ("N")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("X")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	oCell.setString ("s")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	oCell.setString ("sX")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE)
 | 
			
		||||
	
 | 
			
		||||
	' The first group
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = "=COUNT(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	sCellXN = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellXMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=STDEV(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellXS = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=" & sCellXS & "/SQRT(" & sCellXN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	
 | 
			
		||||
	' The second group
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	sFormula = "=" & sCellYLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = "=COUNT(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	sCellYN = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellYMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=STDEV(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellYS = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=" & sCellYS & "/SQRT(" & sCellYN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 2, 4, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow, 4, nRow)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	
 | 
			
		||||
	' Levene's test for homogeneity of variances
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Test for Homogeneity of Variances")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Test")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	oCell.setString ("F")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("p")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	
 | 
			
		||||
	' The test result.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Levene’s Test")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = "=" & fnGetLeveneTest (oTempDataRange)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellF = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sCellsN = fnGetRangeName (oTempDataRange.getCellRangeByPosition (0, oTempDataRange.getRows.getCount - 3, 1, oTempDataRange.getRows.getCount - 3))
 | 
			
		||||
	sCellN = fnGetRangeName (oTempDataRange.getCellByPosition (4, oTempDataRange.getRows.getCount - 3))
 | 
			
		||||
	sFormula = "=FDIST(" & sCellF & ";COUNT(" & sCellsN & ")-1;" & sCellN & "-COUNT(" & sCellsN & "))"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
	
 | 
			
		||||
	' The foot notes of the test.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _
 | 
			
		||||
		"H0: σ1=σ2 (homogeneity; the populations of the two groups have the same variances)." & Chr (10) & _
 | 
			
		||||
		"H1: σ1≠σ2 (heterogeneity; the populations of the two groups have different variances) if the probability (p) is small enough.")
 | 
			
		||||
	oCell.setPropertyValue ("IsTextWrapped", True)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	sNotes = oCell.getString
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	nPos = InStr (sNotes, "p<")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "(p)")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (sNotes, "σ")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "σ")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "H0")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	nPos = InStr (sNotes, "H1")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 2, 2, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 1, 2, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	
 | 
			
		||||
	' The independent samples T-test
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Independent Samples T-Test")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Type")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	oCell.setString ("t")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("df")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	oCell.setString ("p")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	oCell.setString ("X1-X2")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharOverline", com.sun.star.awt.FontUnderline.SINGLE)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' The test of the homogeneity of variances.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Homogeneity")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sSP2 = "((SUMPRODUCT(" & sCellsXData & ";" & sCellsXData & ")-POWER(SUM(" & sCellsXData & ");2)/" & sCellXN & "+SUMPRODUCT(" & sCellsYData & ";" & sCellsYData & ")-POWER(SUM(" & sCellsYData & ");2)/" & sCellYN & ")/(" & sCellXN & "+" & sCellYN & "-2))"
 | 
			
		||||
	sFormula = "=(" & sCellXMean & "-" & sCellYMean & ")/SQRT(" & sSP2 & "*(1/" & sCellXN & "+1/" & sCellYN & "))"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=" &  sCellXN & "+" & sCellYN & "-2"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=TTEST(" &  sCellsXData & ";" & sCellsYData & ";2;2)"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=" &  sCellXMean & "-" & sCellYMean
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	
 | 
			
		||||
	' The test of the heterogeneity of variances.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Heterogeneity")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = "=(" & sCellXMean & "-" & sCellYMean & ")/SQRT(POWER(" & sCellXS & ";2)/" & sCellXN & "+POWER(" & sCellYS & ";2)/" & sCellYN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=POWER(POWER(" & sCellXS & ";2)/" & sCellXN & "+POWER(" & sCellYS & ";2)/" & sCellYN & ";2)/(POWER(" & sCellXS & ";4)/(POWER(" & sCellXN & ";2)*(" & sCellXN & "-1))+POWER(" & sCellYS & ";4)/(POWER(" & sCellYN & ";2)*(" & sCellYN & "-1)))"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=TTEST(" &  sCellsXData & ";" & sCellsYData & ";2;3)"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
	sFormula = "=" &  sCellXMean & "-" & sCellYMean
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	
 | 
			
		||||
	' The foot notes of the test.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _
 | 
			
		||||
		"H0: μ1=μ2 (the populations of the two groups have the same means)." & Chr (10) & _
 | 
			
		||||
		"H1: μ1≠μ2 (the populations of the two groups have different means) if the probability (p) is small enough.")
 | 
			
		||||
	oCell.setPropertyValue ("IsTextWrapped", True)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	sNotes = oCell.getString
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	nPos = InStr (sNotes, "p<")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "(p)")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (sNotes, "μ")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "μ")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "H0")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	nPos = InStr (sNotes, "H1")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 3)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 3, 4, nRow - 3)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 1, 4, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
End Sub
 | 
			
		||||
 | 
			
		||||
' fnCollectIndependentTTestData: Collects the data for the independent T-test.
 | 
			
		||||
Function fnCollectIndependentTTestData (oReportSheet As Object, oLabelColumn As Object, oScoreColumn As Object) As Object
 | 
			
		||||
	Dim nRow As Integer, nNRow As Integer, sCellZMean As String, sCellsN As String
 | 
			
		||||
	Dim oCell As Object, oCells As Object, oCursor As Object
 | 
			
		||||
	Dim sCell As String, sLabel As String, sFormula As String
 | 
			
		||||
	Dim sCellXLabel As String, sCellsXData As String, sCellXMean As String
 | 
			
		||||
	Dim sXLabel As String, nNX As Integer
 | 
			
		||||
	Dim sCellsXZData As String, sCellXZMean As String
 | 
			
		||||
	Dim sCellYLabel As String, sCellsYData As String, sCellYMean As String
 | 
			
		||||
	Dim sYLabel As String, nNY As Integer
 | 
			
		||||
	Dim sCellsYZData As String, sCellYZMean As String
 | 
			
		||||
	
 | 
			
		||||
	sCellXLabel = ""
 | 
			
		||||
	sCellYLabel = ""
 | 
			
		||||
	For nRow = 1 To oLabelColumn.getRows.getCount - 1
 | 
			
		||||
		oCell = oLabelColumn.getCellByPosition (0, nRow)
 | 
			
		||||
		sLabel = oCell.getString
 | 
			
		||||
		If sLabel <> "" Then
 | 
			
		||||
			If sCellXLabel = "" Then
 | 
			
		||||
				sCellXLabel = fnGetRangeName (oCell)
 | 
			
		||||
				sXLabel = sLabel
 | 
			
		||||
			Else
 | 
			
		||||
				If sLabel <> sXLabel And sCellYLabel = "" Then
 | 
			
		||||
					sCellYLabel = fnGetRangeName (oCell)
 | 
			
		||||
					sYLabel = sLabel
 | 
			
		||||
					nRow = oLabelColumn.getRows.getCount - 1
 | 
			
		||||
				End If
 | 
			
		||||
			End If
 | 
			
		||||
		End If
 | 
			
		||||
	Next nRow
 | 
			
		||||
	
 | 
			
		||||
	' The data labels
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (0, 0)
 | 
			
		||||
	sFormula = "=" & sCellXLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (1, 0)
 | 
			
		||||
	sFormula = "=" & sCellYLabel
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	
 | 
			
		||||
	' The data
 | 
			
		||||
	nNX = 0
 | 
			
		||||
	nNY = 0
 | 
			
		||||
	For nRow = 1 To oLabelColumn.getRows.getCount - 1
 | 
			
		||||
		If oLabelColumn.getCellByPosition (0, nRow).getString = sXLabel Then
 | 
			
		||||
			nNX = nNX + 1
 | 
			
		||||
			sFormula = "=" & fnGetRangeName (oScoreColumn.getCellByPosition (0, nRow))
 | 
			
		||||
			oReportSheet.getCellByPosition (0, nNX).setFormula (sFormula)
 | 
			
		||||
		Else
 | 
			
		||||
			If oLabelColumn.getCellByPosition (0, nRow).getString = sYLabel Then
 | 
			
		||||
				nNY = nNY + 1
 | 
			
		||||
				sFormula = "=" & fnGetRangeName (oScoreColumn.getCellByPosition (0, nRow))
 | 
			
		||||
				oReportSheet.getCellByPosition (1, nNY).setFormula (sFormula)
 | 
			
		||||
			End If
 | 
			
		||||
		End If
 | 
			
		||||
	Next nRow
 | 
			
		||||
	
 | 
			
		||||
	' Collects the data
 | 
			
		||||
	sCellsXData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (0, 1, 0, nNX))
 | 
			
		||||
	sCellsYData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (1, 1, 1, nNY))
 | 
			
		||||
	If nNX > nNY Then
 | 
			
		||||
		nNRow = nNX + 1
 | 
			
		||||
	Else
 | 
			
		||||
		nNRow = nNY + 1
 | 
			
		||||
	End If
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (0, nNRow)
 | 
			
		||||
	sFormula = "=COUNT(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (1, nNRow)
 | 
			
		||||
	sFormula = "=COUNT(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (0, nNRow + 1)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsXData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCellXMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (1, nNRow + 1)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsYData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCellYMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCells = oReportSheet.getCellRangeByPosition (0, nNRow, 1, nNRow)
 | 
			
		||||
	sCellsN = fnGetLocalRangeName (oCells)
 | 
			
		||||
	
 | 
			
		||||
	' Calculates the Z values
 | 
			
		||||
	sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (0, 0))
 | 
			
		||||
	sFormula = "=""Z""&" & sCell
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (2, 0)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	For nRow = 1 To nNX
 | 
			
		||||
		sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (0, nRow))
 | 
			
		||||
		sFormula = "=ABS(" & sCell & "-" & sCellXMean & ")"
 | 
			
		||||
		oCell = oReportSheet.getCellByPosition (2, nRow)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
	Next nRow
 | 
			
		||||
	sCellsXZData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (2, 1, 2, nNX))
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (2, nNRow + 1)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsXZData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCellXZMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	
 | 
			
		||||
	sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (1, 0))
 | 
			
		||||
	sFormula = "=""Z""&" & sCell
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (3, 0)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	For nRow = 1 To nNY
 | 
			
		||||
		sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (1, nRow))
 | 
			
		||||
		sFormula = "=ABS(" & sCell & "-" & sCellYMean & ")"
 | 
			
		||||
		oCell = oReportSheet.getCellByPosition (3, nRow)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
	Next nRow
 | 
			
		||||
	sCellsYZData = fnGetLocalRangeName (oReportSheet.getCellRangeByPosition (3, 1, 3, nNY))
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (3, nNRow + 1)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsYZData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCellYZMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	
 | 
			
		||||
	' Calculates the total average
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (4, nNRow)
 | 
			
		||||
	sFormula = "=SUM(" & sCellsN & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (4, nNRow + 1)
 | 
			
		||||
	sFormula = "=AVERAGE(" & sCellsXZData & ";" & sCellsYZData & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCellZMean = fnGetLocalRangeName (oCell)
 | 
			
		||||
	
 | 
			
		||||
	' Calculates the difference of the Z values to their means
 | 
			
		||||
	sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (0, 0))
 | 
			
		||||
	sFormula = "=""dZ""&" & sCell
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (4, 0)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -44)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 34)
 | 
			
		||||
	For nRow = 1 To nNX
 | 
			
		||||
		sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (2, nRow))
 | 
			
		||||
		sFormula = "=" & sCell & "-" & sCellXZMean
 | 
			
		||||
		oCell = oReportSheet.getCellByPosition (4, nRow)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
	Next nRow
 | 
			
		||||
	
 | 
			
		||||
	sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (1, 0))
 | 
			
		||||
	sFormula = "=""dZ""&" & sCell
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (5, 0)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -44)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 34)
 | 
			
		||||
	For nRow = 1 To nNY
 | 
			
		||||
		sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (3, nRow))
 | 
			
		||||
		sFormula = "=" & sCell & "-" & sCellYZMean
 | 
			
		||||
		oCell = oReportSheet.getCellByPosition (5, nRow)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
	Next nRow
 | 
			
		||||
	
 | 
			
		||||
	' Calculates the difference of the Z means to the total mean
 | 
			
		||||
	sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (2, nNRow + 1))
 | 
			
		||||
	sFormula = "=" & sCell & "-" & sCellZMean
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (2, nNRow + 2)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	sCell = fnGetLocalRangeName (oReportSheet.getCellByPosition (3, nNRow + 1))
 | 
			
		||||
	sFormula = "=" & sCell & "-" & sCellZMean
 | 
			
		||||
	oCell = oReportSheet.getCellByPosition (3, nNRow + 2)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	
 | 
			
		||||
	fnCollectIndependentTTestData = oReportSheet.getCellRangeByPosition (0, 0, 5, nNRow + 2)
 | 
			
		||||
End Function
 | 
			
		||||
 | 
			
		||||
' fnGetLeveneTest: Returns the Levene's test result.
 | 
			
		||||
Function fnGetLeveneTest (oZDataRange As Object) As String
 | 
			
		||||
	Dim nK As Integer, nRows As Integer
 | 
			
		||||
	Dim oCell As Object, oCells As Object
 | 
			
		||||
	Dim sCellN As String, sCellsN As String
 | 
			
		||||
	Dim sCellsDZMean As String, sCellsDZData As String
 | 
			
		||||
	
 | 
			
		||||
	nRows = oZDataRange.getRows.getCount
 | 
			
		||||
	nK = oZDataRange.getColumns.getCount / 3
 | 
			
		||||
	oCell = oZDataRange.getCellByPosition (nK * 2, nRows - 3)
 | 
			
		||||
	sCellN = fnGetRangeName (oCell)
 | 
			
		||||
	oCells = oZDataRange.getCellRangeByPosition (0, nRows - 3, nK - 1, nRows - 3)
 | 
			
		||||
	sCellsN = fnGetRangeName (oCells)
 | 
			
		||||
	oCells = oZDataRange.getCellRangeByPosition (nK, nRows - 1, nK * 2 - 1, nRows - 1)
 | 
			
		||||
	sCellsDZMean = fnGetRangeName (oCells)
 | 
			
		||||
	oCells = oZDataRange.getCellRangeByPosition (nK * 2, 1, nK * 3 - 1, nRows - 4)
 | 
			
		||||
	sCellsDZData = fnGetRangeName (oCells)
 | 
			
		||||
	fnGetLeveneTest = "((" & sCellN & "-COUNT(" & sCellsN & "))/(COUNT(" & sCellsN & ")-1))*(SUMPRODUCT(" & sCellsN & ";" & sCellsDZMean & ";" & sCellsDZMean & ")/SUMPRODUCT(" & sCellsDZData & ";" & sCellsDZData & "))"
 | 
			
		||||
End Function
 | 
			
		||||
							
								
								
									
										1072
									
								
								StatTool/4ANOVA.vb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1072
									
								
								StatTool/4ANOVA.vb
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										862
									
								
								StatTool/5Chi2GoF.vb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										862
									
								
								StatTool/5Chi2GoF.vb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,862 @@
 | 
			
		||||
' Copyright (c) 2016 imacat.
 | 
			
		||||
' 
 | 
			
		||||
' Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
' you may not use this file except in compliance with the License.
 | 
			
		||||
' You may obtain a copy of the License at
 | 
			
		||||
' 
 | 
			
		||||
'     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
' 
 | 
			
		||||
' Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
' distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
' See the License for the specific language governing permissions and
 | 
			
		||||
' limitations under the License.
 | 
			
		||||
 | 
			
		||||
' 5Chi2GoF: The macros to for generating the report of Chi-square goodness of fit
 | 
			
		||||
'   by imacat <imacat@mail.imacat.idv.tw>, 2016-09-05
 | 
			
		||||
 | 
			
		||||
Option Explicit
 | 
			
		||||
 | 
			
		||||
' subRunChi2GoodnessOfFit: Runs the chi-square goodness of fit.
 | 
			
		||||
Sub subRunChi2GoodnessOfFit As Object
 | 
			
		||||
	Dim oRange As Object
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim oSheet As Object, mRanges As Object
 | 
			
		||||
	Dim sExisted As String, nResult As Integer
 | 
			
		||||
	
 | 
			
		||||
	DialogLibraries.loadLibrary "StatTool"
 | 
			
		||||
	
 | 
			
		||||
	' Asks the user for the data range
 | 
			
		||||
	oRange = fnAskDataRange (ThisComponent)
 | 
			
		||||
	If IsNull (oRange) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Specifies the data
 | 
			
		||||
	mRanges = fnSpecifyData (oRange, _
 | 
			
		||||
		"&12.Dlg2SpecData.txtPrompt1.Label5Chi2GoF", _
 | 
			
		||||
		"&13.Dlg2SpecData.txtPrompt2.Label5Chi2GoF")
 | 
			
		||||
	If IsNull (mRanges) Then
 | 
			
		||||
		Exit Sub
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Checks the existing report
 | 
			
		||||
	oSheets = ThisComponent.getSheets
 | 
			
		||||
	sSheetName = oRange.getSpreadsheet.getName
 | 
			
		||||
	If oSheets.hasByName (sSheetName & "_chi2") Then
 | 
			
		||||
		sExisted = "Spreadsheet """ & sSheetName & "_chi2"" exists.  Overwrite?"
 | 
			
		||||
		nResult = MsgBox (sExisted, MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION)
 | 
			
		||||
		If nResult = IDNO Then
 | 
			
		||||
			Exit Sub
 | 
			
		||||
		End If
 | 
			
		||||
		' Drops the existing report
 | 
			
		||||
		oSheets.removeByname (sSheetName & "_chi2")
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Reports the chi-square goodness of fit
 | 
			
		||||
	subReportChi2GoodnessOfFit (ThisComponent, mRanges (0), mRanges (1))
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_chi2")
 | 
			
		||||
	
 | 
			
		||||
	' Makes the report sheet active.
 | 
			
		||||
	ThisComponent.getCurrentController.setActiveSheet (oSheet)
 | 
			
		||||
End Sub
 | 
			
		||||
 | 
			
		||||
' subReportChi2GoodnessOfFit: Reports the chi-square goodness of fit
 | 
			
		||||
Sub subReportChi2GoodnessOfFit (oDoc As Object, oColumnColumn As Object, oRowColumn As Object)
 | 
			
		||||
	Dim oSheets As Object, sSheetName As String
 | 
			
		||||
	Dim nI As Integer, nJ As Integer, nJ1 As Integer, nJ2 As Integer
 | 
			
		||||
	Dim mNames () As String, nSheetIndex As Integer
 | 
			
		||||
	Dim oSheet As Object, oColumns As Object, nRow As Integer, nStartRow As Integer
 | 
			
		||||
	Dim oCell As Object, oCells As Object, oCursor As Object
 | 
			
		||||
	Dim nN As Integer, sFormula As String
 | 
			
		||||
	Dim sNotes As String, nPos As Integer
 | 
			
		||||
	Dim nFormatN As Integer, nFormatF As Integer, nFormatP As Integer, nFormatPct As Integer
 | 
			
		||||
	Dim aBorderSingle As New com.sun.star.table.BorderLine
 | 
			
		||||
	Dim aBorderDouble As New com.sun.star.table.BorderLine
 | 
			
		||||
	
 | 
			
		||||
	Dim sCellsJData As String, sCellsIData As String
 | 
			
		||||
	Dim sLabel As String, sLabelsColumn As String, sLabelsRow As String
 | 
			
		||||
	Dim nGroups As Integer, nEvents As Integer
 | 
			
		||||
	Dim mCellLabelColomn () As String, mCellLabelRow () As String
 | 
			
		||||
	Dim mCellNJ () As String, mCellNI () As String, mCellPI () As String
 | 
			
		||||
	Dim mCellFrequency (0, 0) As String, mCellProportion (0, 0) As String
 | 
			
		||||
	Dim sCellN As String
 | 
			
		||||
	
 | 
			
		||||
	Dim sCell As String, sCells As String
 | 
			
		||||
	Dim sCellsRow As String, sCellsColumn As String
 | 
			
		||||
	Dim sCellChi2 As String, sCellDF As String
 | 
			
		||||
	Dim sSE2 AS String, nTotalColumns As Integer
 | 
			
		||||
	
 | 
			
		||||
	oSheets = oDoc.getSheets
 | 
			
		||||
	sSheetName = oColumnColumn.getSpreadsheet.getName
 | 
			
		||||
	mNames = oSheets.getElementNames
 | 
			
		||||
	For nI = 0 To UBound (mNames)
 | 
			
		||||
		If mNames (nI) = sSheetName Then
 | 
			
		||||
			nSheetIndex = nI
 | 
			
		||||
		End If
 | 
			
		||||
	Next nI
 | 
			
		||||
	oSheets.insertNewByName (sSheetName & "_chi2", nSheetIndex + 1)
 | 
			
		||||
	oSheet = oSheets.getByName (sSheetName & "_chi2")
 | 
			
		||||
	
 | 
			
		||||
	sCellsJData = fnGetRangeName (oColumnColumn.getCellRangeByPosition (0, 1, 0, oColumnColumn.getRows.getCount - 1))
 | 
			
		||||
	sCellsIData = fnGetRangeName (oRowColumn.getCellRangeByPosition (0, 1, 0, oRowColumn.getRows.getCount - 1))
 | 
			
		||||
	
 | 
			
		||||
	' Counts the number of groups and events
 | 
			
		||||
	sLabelsColumn = " "
 | 
			
		||||
	sLabelsRow = " "
 | 
			
		||||
	nGroups = 0
 | 
			
		||||
	nEvents = 0
 | 
			
		||||
	For nRow = 1 To oColumnColumn.getRows.getCount - 1
 | 
			
		||||
		sLabel = oColumnColumn.getCellByPosition (0, nRow).getString
 | 
			
		||||
		If InStr (sLabelsColumn, " " & sLabel & " ") = 0 Then
 | 
			
		||||
			sLabelsColumn = sLabelsColumn & sLabel & " "
 | 
			
		||||
			nGroups = nGroups + 1
 | 
			
		||||
		End If
 | 
			
		||||
		sLabel = oRowColumn.getCellByPosition (0, nRow).getString
 | 
			
		||||
		If InStr (sLabelsRow, " " & sLabel & " ") = 0 Then
 | 
			
		||||
			sLabelsRow = sLabelsRow & sLabel & " "
 | 
			
		||||
			nEvents = nEvents + 1
 | 
			
		||||
		End If
 | 
			
		||||
	Next nRow
 | 
			
		||||
	
 | 
			
		||||
	ReDim mCellLabelColomn (nGroups - 1) As String, mCellLabelRow (nEvents - 1) As String
 | 
			
		||||
	ReDim mCellNJ (nGroups - 1) As String, mCellNI (nEvents - 1) As String
 | 
			
		||||
	ReDim mCellPI (nEvents - 1) As String
 | 
			
		||||
	ReDim mCellFrequency (nGroups - 1, nEvents - 1) As String
 | 
			
		||||
	ReDim mCellProportion (nGroups - 1, nEvents - 1) As String
 | 
			
		||||
	
 | 
			
		||||
	' Collects the group and event labels
 | 
			
		||||
	sLabelsColumn = " "
 | 
			
		||||
	sLabelsRow = " "
 | 
			
		||||
	nJ = 0
 | 
			
		||||
	nI = 0
 | 
			
		||||
	For nRow = 1 To oColumnColumn.getRows.getCount - 1
 | 
			
		||||
		oCell = oColumnColumn.getCellByPosition (0, nRow)
 | 
			
		||||
		sLabel = oCell.getString
 | 
			
		||||
		If InStr (sLabelsColumn, " " & sLabel & " ") = 0 Then
 | 
			
		||||
			sLabelsColumn = sLabelsColumn & sLabel & " "
 | 
			
		||||
			mCellLabelColomn (nJ) = fnGetRangeName (oCell)
 | 
			
		||||
			nJ = nJ + 1
 | 
			
		||||
		End If
 | 
			
		||||
		oCell = oRowColumn.getCellByPosition (0, nRow)
 | 
			
		||||
		sLabel = oCell.getString
 | 
			
		||||
		If InStr (sLabelsRow, " " & sLabel & " ") = 0 Then
 | 
			
		||||
			sLabelsRow = sLabelsRow & sLabel & " "
 | 
			
		||||
			mCellLabelRow (nI) = fnGetRangeName (oCell)
 | 
			
		||||
			nI = nI + 1
 | 
			
		||||
		End If
 | 
			
		||||
	Next nRow
 | 
			
		||||
	
 | 
			
		||||
	' Obtains the format parameters for the report.
 | 
			
		||||
	nFormatN = fnQueryFormat (oDoc, "#,##0")
 | 
			
		||||
	nFormatF = fnQueryFormat (oDoc, "#,###.000")
 | 
			
		||||
	nFormatP = fnQueryFormat (oDoc, "[<0.01]#.000""**"";[<0.05]#.000""*"";#.000")
 | 
			
		||||
	nFormatPct = fnQueryFormat (oDoc, "0.0%")
 | 
			
		||||
	
 | 
			
		||||
	aBorderSingle.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.OuterLineWidth = 2
 | 
			
		||||
	aBorderDouble.InnerLineWidth = 2
 | 
			
		||||
	aBorderDouble.LineDistance = 2
 | 
			
		||||
	
 | 
			
		||||
	' Sets the column widths of the report.
 | 
			
		||||
	nTotalColumns = nGroups + 2
 | 
			
		||||
	If nEvents = 2 Then
 | 
			
		||||
		If nTotalColumns < 5 Then
 | 
			
		||||
			nTotalColumns = 5
 | 
			
		||||
		End If
 | 
			
		||||
	Else
 | 
			
		||||
		If nTotalColumns < 6 Then
 | 
			
		||||
			nTotalColumns = 6
 | 
			
		||||
		End If
 | 
			
		||||
	End If
 | 
			
		||||
	oColumns = oSheet.getColumns
 | 
			
		||||
	For nJ = 0 To nTotalColumns - 1
 | 
			
		||||
		oColumns.getByIndex (nJ).setPropertyValue ("Width", 3060)
 | 
			
		||||
	Next nJ
 | 
			
		||||
	
 | 
			
		||||
	nRow = -2
 | 
			
		||||
	
 | 
			
		||||
	' Group description
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Crosstabulation")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, nGroups + 1, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Event")
 | 
			
		||||
	For nJ = 0 To nGroups - 1
 | 
			
		||||
		oCell = oSheet.getCellByPosition (nJ + 1, nRow)
 | 
			
		||||
		sFormula = "=" & mCellLabelColomn (nJ)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
		mCellLabelColomn (nJ) = fnGetLocalRangeName (oCell)
 | 
			
		||||
	Next nJ
 | 
			
		||||
	oCell = oSheet.getCellByPosition (nGroups + 1, nRow)
 | 
			
		||||
	oCell.setString ("Total")
 | 
			
		||||
	
 | 
			
		||||
	' Shows each event
 | 
			
		||||
	nRow = nRow - 1
 | 
			
		||||
	For nI = 0 To nEvents - 1
 | 
			
		||||
		nRow = nRow + 2
 | 
			
		||||
		oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
		sFormula = "=" & mCellLabelRow (nI)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
		oCell.setPropertyValue ("VertJustify", com.sun.star.table.CellVertJustify.TOP)
 | 
			
		||||
		mCellLabelRow (nI) = fnGetLocalRangeName (oCell)
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (0, nRow, 0, nRow + 1)
 | 
			
		||||
		oCells.merge (True)
 | 
			
		||||
		For nJ = 0 To nGroups - 1
 | 
			
		||||
			oCell = oSheet.getCellByPosition (1 + nJ, nRow)
 | 
			
		||||
		    sFormula = "=COUNTIFS(" & sCellsJData & ";" & mCellLabelColomn (nJ) & ";" & sCellsIData & ";" & mCellLabelRow (nI) & ")"
 | 
			
		||||
		    oCell.setFormula (sFormula)
 | 
			
		||||
			oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
			mCellFrequency (nJ, nI) = fnGetLocalRangeName (oCell)
 | 
			
		||||
		Next nJ
 | 
			
		||||
		oCell = oSheet.getCellByPosition (1 + nGroups, nRow)
 | 
			
		||||
		sCells = fnGetLocalRangeName (oSheet.getCellRangeByPosition (1, nRow, nGroups, nRow))
 | 
			
		||||
		sFormula = "=SUM(" & sCells & ")"
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
		oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
		mCellNI (nI) = fnGetLocalRangeName (oCell)
 | 
			
		||||
	Next nI
 | 
			
		||||
	' Shows the total
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Total")
 | 
			
		||||
	oCell.setPropertyValue ("VertJustify", com.sun.star.table.CellVertJustify.TOP)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 0, nRow + 1)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	For nJ = 0 To nGroups - 1
 | 
			
		||||
		oCell = oSheet.getCellByPosition (1 + nJ, nRow)
 | 
			
		||||
		sFormula = ""
 | 
			
		||||
		For nI = 0 To nEvents - 1
 | 
			
		||||
		    sFormula = sFormula & "+" & mCellFrequency (nJ, nI)
 | 
			
		||||
		Next nI
 | 
			
		||||
		sFormula = "=" & Right (sFormula, Len (sFormula) - 1)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
		oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
		mCellNJ (nJ) = fnGetLocalRangeName (oCell)
 | 
			
		||||
	Next nJ
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1 + nGroups, nRow)
 | 
			
		||||
	sCells = fnGetLocalRangeName (oSheet.getCellRangeByPosition (1, nRow, nGroups, nRow))
 | 
			
		||||
	sFormula = ""
 | 
			
		||||
	For nI = 0 To nEvents - 1
 | 
			
		||||
	    sFormula = sFormula & "+" & mCellNI (nI)
 | 
			
		||||
	Next nI
 | 
			
		||||
	sFormula = "=" & Right (sFormula, Len (sFormula) - 1)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	sCellN = fnGetLocalRangeName (oCell)
 | 
			
		||||
	' Shows the proportions
 | 
			
		||||
	nRow = nRow - nEvents * 2 - 1
 | 
			
		||||
	For nI = 0 To nEvents - 1
 | 
			
		||||
	    nRow = nRow + 2
 | 
			
		||||
        For nJ = 0 To nGroups - 1
 | 
			
		||||
			oCell = oSheet.getCellByPosition (1 + nJ, nRow)
 | 
			
		||||
		    sFormula = "=" & mCellFrequency (nJ, nI) & "/" & mCellNJ (nJ)
 | 
			
		||||
		    oCell.setFormula (sFormula)
 | 
			
		||||
			oCell.setPropertyValue ("NumberFormat", nFormatPct)
 | 
			
		||||
			mCellProportion (nJ, nI) = fnGetLocalRangeName (oCell)
 | 
			
		||||
		Next nJ
 | 
			
		||||
		oCell = oSheet.getCellByPosition (1 + nGroups, nRow)
 | 
			
		||||
	    sFormula = "=" & mCellNI (nI) & "/" & sCellN
 | 
			
		||||
	    oCell.setFormula (sFormula)
 | 
			
		||||
		oCell.setPropertyValue ("NumberFormat", nFormatPct)
 | 
			
		||||
		mCellPI (nI) = fnGetLocalRangeName (oCell)
 | 
			
		||||
	Next nI
 | 
			
		||||
	' Shows the total
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	For nJ = 0 To nGroups - 1
 | 
			
		||||
		oCell = oSheet.getCellByPosition (1 + nJ, nRow)
 | 
			
		||||
		sFormula = ""
 | 
			
		||||
		For nI = 0 To nEvents - 1
 | 
			
		||||
		    sFormula = sFormula & "+" & mCellProportion (nJ, nI)
 | 
			
		||||
		Next nI
 | 
			
		||||
		sFormula = "=" & Right (sFormula, Len (sFormula) - 1)
 | 
			
		||||
		oCell.setFormula (sFormula)
 | 
			
		||||
		oCell.setPropertyValue ("NumberFormat", nFormatPct)
 | 
			
		||||
	Next nJ
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1 + nGroups, nRow)
 | 
			
		||||
	sCells = fnGetLocalRangeName (oSheet.getCellRangeByPosition (1, nRow, nGroups, nRow))
 | 
			
		||||
	sFormula = ""
 | 
			
		||||
	For nI = 0 To nEvents - 1
 | 
			
		||||
	    sFormula = sFormula & "+" & mCellPI (nI)
 | 
			
		||||
	Next nI
 | 
			
		||||
	sFormula = "=" & Right (sFormula, Len (sFormula) - 1)
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatPct)
 | 
			
		||||
	
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - nEvents * 2 - 1, nGroups, nRow - nEvents * 2 - 1)
 | 
			
		||||
	sCellsRow = fnGetLocalRangeName (oCells)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - nEvents * 2 - 1, 1, nRow - 2)
 | 
			
		||||
	sCellsColumn = fnGetLocalRangeName (oCells)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - nEvents * 2 - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow  - nEvents * 2 - 2, nGroups + 1, nRow - nEvents * 2 - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow - nEvents * 2 - 1, 0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 1, nGroups + 1, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow, nGroups + 1, nRow)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	
 | 
			
		||||
	' The Chi-square test
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Chi-Square Test")
 | 
			
		||||
	oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 3, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Test")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	oCell.setString ("χ2")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", 33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	oCell.setString ("df")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	oCell.setString ("p")
 | 
			
		||||
	oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.gotoEnd (True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	
 | 
			
		||||
	' The test result.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Pearson’s Chi-Square")
 | 
			
		||||
	oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
	sFormula = ""
 | 
			
		||||
	For nI = 0 To nEvents - 1
 | 
			
		||||
	    For nJ = 0 To nGroups - 1
 | 
			
		||||
	        sFormula = sFormula & "+POWER(" & mCellFrequency (nJ, nI) & ";2)/(" & mCellNI (nI) & "*" & mCellNJ (nJ) & ")"
 | 
			
		||||
	    Next nJ
 | 
			
		||||
	Next nI
 | 
			
		||||
	sFormula = "=" & sCellN & "*(" & Right (sFormula, Len (sFormula) - 1) & "-1)"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
	sCellChi2 = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
	sFormula = "=(COUNT(" & sCellsRow & ")-1)*(COUNT(" & sCellsColumn & ")/2-1)"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatN)
 | 
			
		||||
	sCellDF = fnGetLocalRangeName (oCell)
 | 
			
		||||
	oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
	sFormula = "=CHIDIST(" & sCellChi2 & ";" & sCellDF & ")"
 | 
			
		||||
	oCell.setFormula (sFormula)
 | 
			
		||||
	oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
	
 | 
			
		||||
	' The foot notes of the test.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _
 | 
			
		||||
		"H0: P1=P2=…PN=P (the proportions of the events in each group are the same)." & Chr (10) & _
 | 
			
		||||
		"H1: The above is false (the proportions of the events in each group are different) if the probability (p) is small enough.")
 | 
			
		||||
	oCell.setPropertyValue ("IsTextWrapped", True)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (0, nRow, 3, nRow)
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	sNotes = oCell.getString
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	nPos = InStr (sNotes, "p<")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "(p)")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (1, sNotes, "P", 0)
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		If oCursor.getString <> " " Then
 | 
			
		||||
			oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
			oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		End If
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "P", 0)
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "PN")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (sNotes, "H0")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	nPos = InStr (sNotes, "H1")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 2, 3, nRow - 2)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
	oCells = oSheet.getCellByPosition (0, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	oCells = oSheet.getCellRangeByPosition (1, nRow - 1, 3, nRow - 1)
 | 
			
		||||
	oCells.setPropertyValue ("TopBorder", aBorderSingle)
 | 
			
		||||
	oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	
 | 
			
		||||
	' The posteriori comparison
 | 
			
		||||
	nRow = nRow + 2
 | 
			
		||||
	If nEvents = 2 Then
 | 
			
		||||
		oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
		oCell.setString ("Posteriori Comparison")
 | 
			
		||||
		oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
		oCells.merge (True)
 | 
			
		||||
		nRow = nRow + 1
 | 
			
		||||
		oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
		oCell.setString ("j1")
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
		oCell.setString ("j2")
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
		oCell.setString ("Pj1-Pj2")
 | 
			
		||||
		oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -52)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 34)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -52)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 34)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
		oCell.setString ("χ2")
 | 
			
		||||
		oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.gotoEnd (True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", 33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
		oCell.setString ("p")
 | 
			
		||||
		oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.gotoEnd (True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	Else
 | 
			
		||||
		oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
		oCell.setString ("Posteriori Comparison")
 | 
			
		||||
		oCell.setPropertyValue ("CellStyle", "Result2")
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (0, nRow, 5, nRow)
 | 
			
		||||
		oCells.merge (True)
 | 
			
		||||
		nRow = nRow + 1
 | 
			
		||||
		oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
		oCell.setString ("Event")
 | 
			
		||||
		oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
		oCell.setString ("j1")
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
		oCell.setString ("j2")
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
		oCell.setString ("Pj1-Pj2")
 | 
			
		||||
		oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -52)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 34)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -52)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 34)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
		oCell.setString ("χ2")
 | 
			
		||||
		oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.gotoEnd (True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", 33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCell = oSheet.getCellByPosition (5, nRow)
 | 
			
		||||
		oCell.setString ("p")
 | 
			
		||||
		oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
		oCursor = oCell.createTextCursor
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.gotoEnd (True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' The comparison between groups
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	If nEvents = 2 Then
 | 
			
		||||
		For nJ1 = 0 To nGroups - 1
 | 
			
		||||
			oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
			sFormula = "=" & mCellLabelColomn (nJ1)
 | 
			
		||||
			oCell.setFormula (sFormula)
 | 
			
		||||
			oCell.setPropertyValue ("VertJustify", com.sun.star.table.CellVertJustify.TOP)
 | 
			
		||||
			oCells = oSheet.getCellRangeByPosition (0, nRow, 0, nRow + (nGroups - 1) - 1)
 | 
			
		||||
			oCells.merge (True)
 | 
			
		||||
			For nJ2 = 0 To nGroups - 1
 | 
			
		||||
				If nJ1 <> nJ2 Then
 | 
			
		||||
					oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
					sFormula = "=" & mCellLabelColomn (nJ2)
 | 
			
		||||
					oCell.setFormula (sFormula)
 | 
			
		||||
					oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
					sFormula = "=" & mCellProportion (nJ1, 0) & "-" & mCellProportion (nJ2, 0)
 | 
			
		||||
					oCell.setFormula (sFormula)
 | 
			
		||||
					oCell.setPropertyValue ("NumberFormat", nFormatPct)
 | 
			
		||||
					sCell = fnGetLocalRangeName (oCell)
 | 
			
		||||
					sSE2 = "(" & mCellProportion (nJ1, 0) & "*(1-" & mCellProportion (nJ1, 0) & "))/" & mCellNJ (nJ1) & _
 | 
			
		||||
						"+(" & mCellProportion (nJ2, 0) & "*(1-" & mCellProportion (nJ2, 0) & "))/" & mCellNJ (nJ2)
 | 
			
		||||
					oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
					sFormula = "=IF(" & sSE2 & "=0;""(N/A)"";POWER(" & sCell & ";2)/(" & sSE2 & "))"
 | 
			
		||||
					oCell.setFormula (sFormula)
 | 
			
		||||
					oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
					oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
					sCellChi2 = fnGetLocalRangeName (oCell)
 | 
			
		||||
					oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
					sFormula = "=IF(" & sSE2 & "=0;""(N/A)"";CHIDIST(" & sCellChi2 & ";" & sCellDF & "))"
 | 
			
		||||
					oCell.setFormula (sFormula)
 | 
			
		||||
					oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
					oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
					nRow = nRow + 1
 | 
			
		||||
				End If
 | 
			
		||||
			Next nJ2
 | 
			
		||||
		Next nJ1
 | 
			
		||||
	Else
 | 
			
		||||
		For nI = 0 To nEvents - 1
 | 
			
		||||
			oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
			sFormula = "=" & mCellLabelRow (nI)
 | 
			
		||||
			oCell.setFormula (sFormula)
 | 
			
		||||
			oCell.setPropertyValue ("VertJustify", com.sun.star.table.CellVertJustify.TOP)
 | 
			
		||||
			oCells = oSheet.getCellRangeByPosition (0, nRow, 0, nRow + nGroups * (nGroups - 1) - 1)
 | 
			
		||||
			oCells.merge (True)
 | 
			
		||||
			For nJ1 = 0 To nGroups - 1
 | 
			
		||||
				oCell = oSheet.getCellByPosition (1, nRow)
 | 
			
		||||
				sFormula = "=" & mCellLabelColomn (nJ1)
 | 
			
		||||
				oCell.setFormula (sFormula)
 | 
			
		||||
				oCell.setPropertyValue ("VertJustify", com.sun.star.table.CellVertJustify.TOP)
 | 
			
		||||
				oCells = oSheet.getCellRangeByPosition (1, nRow, 1, nRow + (nGroups - 1) - 1)
 | 
			
		||||
				oCells.merge (True)
 | 
			
		||||
				For nJ2 = 0 To nGroups - 1
 | 
			
		||||
					If nJ1 <> nJ2 Then
 | 
			
		||||
						oCell = oSheet.getCellByPosition (2, nRow)
 | 
			
		||||
						sFormula = "=" & mCellLabelColomn (nJ2)
 | 
			
		||||
						oCell.setFormula (sFormula)
 | 
			
		||||
						oCell = oSheet.getCellByPosition (3, nRow)
 | 
			
		||||
						sFormula = "=" & mCellProportion (nJ1, nI) & "-" & mCellProportion (nJ2, nI)
 | 
			
		||||
						oCell.setFormula (sFormula)
 | 
			
		||||
						oCell.setPropertyValue ("NumberFormat", nFormatPct)
 | 
			
		||||
						sCell = fnGetLocalRangeName (oCell)
 | 
			
		||||
						sSE2 = "(" & mCellProportion (nJ1, nI) & "*(1-" & mCellProportion (nJ1, nI) & "))/" & mCellNJ (nJ1) & _
 | 
			
		||||
							"+(" & mCellProportion (nJ2, nI) & "*(1-" & mCellProportion (nJ2, nI) & "))/" & mCellNJ (nJ2)
 | 
			
		||||
						oCell = oSheet.getCellByPosition (4, nRow)
 | 
			
		||||
						sFormula = "=IF(" & sSE2 & "=0;""(N/A)"";POWER(" & sCell & ";2)/(" & sSE2 & "))"
 | 
			
		||||
						oCell.setFormula (sFormula)
 | 
			
		||||
						oCell.setPropertyValue ("NumberFormat", nFormatF)
 | 
			
		||||
						oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
						sCellChi2 = fnGetLocalRangeName (oCell)
 | 
			
		||||
						oCell = oSheet.getCellByPosition (5, nRow)
 | 
			
		||||
						sFormula = "=IF(" & sSE2 & "=0;""(N/A)"";CHIDIST(" & sCellChi2 & ";" & sCellDF & "))"
 | 
			
		||||
						oCell.setFormula (sFormula)
 | 
			
		||||
						oCell.setPropertyValue ("NumberFormat", nFormatP)
 | 
			
		||||
						oCell.setPropertyValue ("ParaAdjust", com.sun.star.style.ParagraphAdjust.RIGHT)
 | 
			
		||||
						nRow = nRow + 1
 | 
			
		||||
					End If
 | 
			
		||||
				Next nJ2
 | 
			
		||||
			Next nJ1
 | 
			
		||||
		Next nI
 | 
			
		||||
	End If
 | 
			
		||||
	nRow = nRow - 1
 | 
			
		||||
	
 | 
			
		||||
	' The foot notes of the test.
 | 
			
		||||
	nRow = nRow + 1
 | 
			
		||||
	oCell = oSheet.getCellByPosition (0, nRow)
 | 
			
		||||
	oCell.setString ("Note: *: p<.05, **: p<.01" & Chr (10) & _
 | 
			
		||||
		"H0: Pj1=Pj2 (the proportions of the event in the two groups are the same)." & Chr (10) & _
 | 
			
		||||
		"H1: Pj1≠Pj2 (the proportions of the event in the two groups are different) if the probability (p) is small enough.")
 | 
			
		||||
	oCell.setPropertyValue ("IsTextWrapped", True)
 | 
			
		||||
	If nEvents = 2 Then
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (0, nRow, 4, nRow)
 | 
			
		||||
	Else
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (0, nRow, 5, nRow)
 | 
			
		||||
	End If
 | 
			
		||||
	oCells.merge (True)
 | 
			
		||||
	sNotes = oCell.getString
 | 
			
		||||
	oCursor = oCell.createTextCursor
 | 
			
		||||
	nPos = InStr (sNotes, "p<")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "p<")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "(p)")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	nPos = InStr (sNotes, "Pj")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		oCursor.gotoStart (False)
 | 
			
		||||
		oCursor.goRight (nPos - 1, False)
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
		oCursor.collapseToEnd
 | 
			
		||||
		oCursor.goRight (1, True)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapement", -52)
 | 
			
		||||
		oCursor.setPropertyValue ("CharEscapementHeight", 34)
 | 
			
		||||
		nPos = InStr (nPos + 1, sNotes, "Pj")
 | 
			
		||||
	Loop
 | 
			
		||||
	nPos = InStr (sNotes, "H0")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	nPos = InStr (sNotes, "H1")
 | 
			
		||||
	oCursor.gotoStart (False)
 | 
			
		||||
	oCursor.goRight (nPos - 1, False)
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPosture", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureAsian", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.setPropertyValue ("CharPostureComplex", com.sun.star.awt.FontSlant.ITALIC)
 | 
			
		||||
	oCursor.collapseToEnd
 | 
			
		||||
	oCursor.goRight (1, True)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapement", -33)
 | 
			
		||||
	oCursor.setPropertyValue ("CharEscapementHeight", 58)
 | 
			
		||||
	
 | 
			
		||||
	' Draws the table borders.
 | 
			
		||||
	If nEvents = 2 Then
 | 
			
		||||
		nStartRow = nRow - nGroups * (nGroups - 1) - 1
 | 
			
		||||
		oCells = oSheet.getCellByPosition (0, nStartRow)
 | 
			
		||||
		oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellByPosition (1, nStartRow)
 | 
			
		||||
		oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
		oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (2, nStartRow, 4, nStartRow)
 | 
			
		||||
		oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (1, nStartRow + 1, 1, nRow - 2)
 | 
			
		||||
		oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellByPosition (0, nRow - 1 - (nGroups - 1) + 1)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
		oCells = oSheet.getCellByPosition (1, nRow - 1)
 | 
			
		||||
		oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (2, nRow - 1, 4, nRow - 1)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	Else
 | 
			
		||||
		nStartRow = nRow - nEvents * nGroups * (nGroups - 1) - 1
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (0, nStartRow, 1, nStartRow)
 | 
			
		||||
		oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellByPosition (2, nStartRow)
 | 
			
		||||
		oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
		oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (3, nStartRow, 5, nStartRow)
 | 
			
		||||
		oCells.setPropertyValue ("TopBorder", aBorderDouble)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (2, nStartRow + 1, 2, nRow - 2)
 | 
			
		||||
		oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
		oCells = oSheet.getCellByPosition (0, nRow - 1 - nGroups * (nGroups - 1) + 1)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
		oCells = oSheet.getCellByPosition (1, nRow - 1 - (nGroups - 1) + 1)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
		oCells = oSheet.getCellByPosition (2, nRow - 1)
 | 
			
		||||
		oCells.setPropertyValue ("RightBorder", aBorderSingle)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
		oCells = oSheet.getCellRangeByPosition (3, nRow - 1, 5, nRow - 1)
 | 
			
		||||
		oCells.setPropertyValue ("BottomBorder", aBorderDouble)
 | 
			
		||||
	End If
 | 
			
		||||
End Sub
 | 
			
		||||
							
								
								
									
										222
									
								
								StatTool/9Utils.vb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								StatTool/9Utils.vb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,222 @@
 | 
			
		||||
' Copyright (c) 2016 imacat.
 | 
			
		||||
' 
 | 
			
		||||
' Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
' you may not use this file except in compliance with the License.
 | 
			
		||||
' You may obtain a copy of the License at
 | 
			
		||||
' 
 | 
			
		||||
'     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
' 
 | 
			
		||||
' Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
' distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
' See the License for the specific language governing permissions and
 | 
			
		||||
' limitations under the License.
 | 
			
		||||
 | 
			
		||||
' 9Utils: The utility macros.
 | 
			
		||||
'   by imacat <imacat@mail.imacat.idv.tw>, 2016-08-10
 | 
			
		||||
 | 
			
		||||
Option Explicit
 | 
			
		||||
 | 
			
		||||
' fnCheckRangeName: Checks the range name and returns the range when
 | 
			
		||||
'                   found, or null when not found.
 | 
			
		||||
Function fnCheckRangeName (oDoc As Object, sRangeName As String) As Object
 | 
			
		||||
	On Error Goto ErrorHandler
 | 
			
		||||
	Dim oController As Object, oSheet As Object
 | 
			
		||||
	Dim nPos As Integer, sSheetName As String, oRange As Object
 | 
			
		||||
	
 | 
			
		||||
	oController = oDoc.getCurrentController
 | 
			
		||||
	nPos = InStr (sRangeName, ".")
 | 
			
		||||
	If nPos = 0 Then
 | 
			
		||||
		oSheet = oController.getActiveSheet
 | 
			
		||||
	Else
 | 
			
		||||
		sSheetName = Left (sRangeName, nPos - 1)
 | 
			
		||||
		If Left (sSheetName, 1) = "$" Then
 | 
			
		||||
			sSheetName = Right (sSheetName, Len (sSheetName) - 1)
 | 
			
		||||
		End If
 | 
			
		||||
		oSheet = oDoc.getSheets.getByName (sSheetName)
 | 
			
		||||
	End If
 | 
			
		||||
	fnCheckRangeName = oSheet.getCellRangeByName (sRangeName)
 | 
			
		||||
	
 | 
			
		||||
	ErrorHandler:
 | 
			
		||||
End Function
 | 
			
		||||
 | 
			
		||||
' fnQueryFormat: Returns the index of the number format, and creates
 | 
			
		||||
'                the number format if required.
 | 
			
		||||
Function fnQueryFormat (oDoc As Object, sFormat As String) As Integer
 | 
			
		||||
	Dim oFormats As Object, nIndex As Integer
 | 
			
		||||
	Dim aLocale As New com.sun.star.lang.Locale
 | 
			
		||||
	
 | 
			
		||||
	oFormats = oDoc.getNumberFormats
 | 
			
		||||
	nIndex = oFormats.queryKey (sFormat, aLocale, True)
 | 
			
		||||
	If nIndex = -1 Then
 | 
			
		||||
		oFormats.addNew (sFormat, aLocale)
 | 
			
		||||
		nIndex = oFormats.queryKey (sFormat, aLocale, True)
 | 
			
		||||
	End If
 | 
			
		||||
	fnQueryFormat = nIndex
 | 
			
		||||
End Function
 | 
			
		||||
 | 
			
		||||
' fnGetRangeName: Obtains the name of a spreadsheet cell range
 | 
			
		||||
Function fnGetRangeName (oRange As Object) As String
 | 
			
		||||
	Dim nPos As Integer, sName As String
 | 
			
		||||
	
 | 
			
		||||
	sName = oRange.getPropertyValue ("AbsoluteName")
 | 
			
		||||
	nPos = InStr (sName, "$")
 | 
			
		||||
	Do While nPos <> 0
 | 
			
		||||
		sName = Left (sName, nPos - 1) & Right (sName, Len (sName) - nPos)
 | 
			
		||||
		nPos = InStr (sName, "$")
 | 
			
		||||
	Loop
 | 
			
		||||
	fnGetRangeName = sName
 | 
			
		||||
End Function
 | 
			
		||||
 | 
			
		||||
' fnGetLocalRangeName: Obtains the name of a local spreadsheet cell range
 | 
			
		||||
Function fnGetLocalRangeName (oRange As Object) As String
 | 
			
		||||
	Dim nPos As Integer, sName As String
 | 
			
		||||
	
 | 
			
		||||
	sName = fnGetRangeName (oRange)
 | 
			
		||||
	nPos = InStr (sName, ".")
 | 
			
		||||
	If nPos <> 0 Then
 | 
			
		||||
		sName = Right (sName, Len (sName) - nPos)
 | 
			
		||||
	End If
 | 
			
		||||
	fnGetLocalRangeName = sName
 | 
			
		||||
End Function
 | 
			
		||||
 | 
			
		||||
' fnSpecifyData: Specifies the data
 | 
			
		||||
Function fnSpecifyData (oRange As Object, sPrompt1 As String, sPrompt2 As String) As Object
 | 
			
		||||
	Dim mLabels (oRange.getColumns.getCount - 1) As String
 | 
			
		||||
	Dim nI As Integer, mSelected (0) As Integer
 | 
			
		||||
	Dim oDialog As Object, oTextModel As Object
 | 
			
		||||
	Dim oListModel1 As object, oListModel2 As Object
 | 
			
		||||
	Dim nResult As Integer, nColumn As Integer, mRanges (1) As Object
 | 
			
		||||
	
 | 
			
		||||
	For nI = 0 To oRange.getColumns.getCount - 1
 | 
			
		||||
		mLabels (nI) = oRange.getCellByPosition (nI, 0).getString
 | 
			
		||||
	Next nI
 | 
			
		||||
	
 | 
			
		||||
	' Runs the dialog
 | 
			
		||||
	oDialog = CreateUnoDialog (DialogLibraries.StatTool.Dlg2SpecData)
 | 
			
		||||
	oTextModel = oDialog.getControl ("txtPrompt1").getModel
 | 
			
		||||
	oTextModel.setPropertyValue ("Label", sPrompt1)
 | 
			
		||||
	oListModel1 = oDialog.getControl ("lstData1").getModel
 | 
			
		||||
	oListModel1.setPropertyValue ("StringItemList", mLabels)
 | 
			
		||||
	mSelected (0) = 0
 | 
			
		||||
	oListModel1.setPropertyValue ("SelectedItems", mSelected)
 | 
			
		||||
	oTextModel = oDialog.getControl ("txtPrompt2").getModel
 | 
			
		||||
	oTextModel.setPropertyValue ("Label", sPrompt2)
 | 
			
		||||
	oListModel2 = oDialog.getControl ("lstData2").getModel
 | 
			
		||||
	oListModel2.setPropertyValue ("StringItemList", mLabels)
 | 
			
		||||
	mSelected (0) = 1
 | 
			
		||||
	oListModel2.setPropertyValue ("SelectedItems", mSelected)
 | 
			
		||||
	
 | 
			
		||||
	nResult = oDialog.execute
 | 
			
		||||
	oDialog.dispose
 | 
			
		||||
	
 | 
			
		||||
	' Cancelled
 | 
			
		||||
	If nResult = 0 Then
 | 
			
		||||
		Exit Function
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	nColumn = oListModel1.getPropertyValue ("SelectedItems") (0)
 | 
			
		||||
	mRanges (0) = oRange.getCellRangeByPosition ( _
 | 
			
		||||
		nColumn, 0, nColumn, oRange.getRows.getCount - 1)
 | 
			
		||||
	nColumn = oListModel2.getPropertyValue ("SelectedItems") (0)
 | 
			
		||||
	mRanges (1) = oRange.getCellRangeByPosition ( _
 | 
			
		||||
		nColumn, 0, nColumn, oRange.getRows.getCount - 1)
 | 
			
		||||
	fnSpecifyData = mRanges
 | 
			
		||||
End Function
 | 
			
		||||
 | 
			
		||||
' fnAskDataRange: Asks the user for the data range, or null when
 | 
			
		||||
'                 the user cancelled
 | 
			
		||||
Function fnAskDataRange (oDoc As Object) As Object
 | 
			
		||||
	Dim oRange As Object
 | 
			
		||||
	Dim oDialog As Object, nResult As Integer
 | 
			
		||||
	Dim oTextModel As Object, oEditModel As Object
 | 
			
		||||
	Dim sPrompt As String, sCellsData As String
 | 
			
		||||
	
 | 
			
		||||
	oRange = fnFindActiveDataRange (oDoc)
 | 
			
		||||
	If IsNull (oRange) Then
 | 
			
		||||
		sCellsData = ""
 | 
			
		||||
	Else
 | 
			
		||||
		sCellsData = oRange.getPropertyValue ("AbsoluteName")
 | 
			
		||||
	End If
 | 
			
		||||
	sPrompt = "&27.Dlg1AskRange.txtPrompt.Label"
 | 
			
		||||
	
 | 
			
		||||
	' Loop until we finds good data
 | 
			
		||||
	Do While sPrompt <> ""
 | 
			
		||||
		' Runs the dialog
 | 
			
		||||
		oDialog = CreateUnoDialog (DialogLibraries.StatTool.Dlg1AskRange)
 | 
			
		||||
		oTextModel = oDialog.getControl ("txtPrompt").getModel
 | 
			
		||||
		oTextModel.setPropertyValue ("Label", sPrompt)
 | 
			
		||||
		oEditModel = oDialog.getControl ("edtCellsData").getModel
 | 
			
		||||
		oEditModel.setPropertyValue ("Text", sCellsData)
 | 
			
		||||
		
 | 
			
		||||
		nResult = oDialog.execute
 | 
			
		||||
		oDialog.dispose
 | 
			
		||||
		
 | 
			
		||||
		' Cancelled
 | 
			
		||||
		If nResult = 0 Then
 | 
			
		||||
			Exit Function
 | 
			
		||||
		End If
 | 
			
		||||
		
 | 
			
		||||
		sCellsData = oEditModel.getPropertyValue ("Text")
 | 
			
		||||
		If sCellsData = "" Then
 | 
			
		||||
			sPrompt = "&27.Dlg1AskRange.txtPrompt.Label"
 | 
			
		||||
		Else
 | 
			
		||||
			oRange = fnCheckRangeName (oDoc, sCellsData)
 | 
			
		||||
			If IsNull (oRange) Then
 | 
			
		||||
				sPrompt = "&35.Dlg1AskRange.txtPrompt.LabelNotExists"
 | 
			
		||||
			Else
 | 
			
		||||
				If oRange.getRows.getCount < 2 Or oRange.getColumns.getCount < 2 Then
 | 
			
		||||
					sPrompt = "&36.Dlg1AskRange.txtPrompt.LabelTooSmall"
 | 
			
		||||
				Else
 | 
			
		||||
					sPrompt = ""
 | 
			
		||||
					oDoc.getCurrentController.select (oRange)
 | 
			
		||||
					fnAskDataRange = oRange
 | 
			
		||||
					Exit Function
 | 
			
		||||
				End If
 | 
			
		||||
			End If
 | 
			
		||||
		End If
 | 
			
		||||
	Loop
 | 
			
		||||
End Function
 | 
			
		||||
 | 
			
		||||
' fnFindActiveDataRange: Finds the selected data range.
 | 
			
		||||
Function fnFindActiveDataRange (oDoc)
 | 
			
		||||
	Dim oSelection As Object, nI As Integer
 | 
			
		||||
	Dim oRanges As Object, oRange As Object
 | 
			
		||||
	Dim aCellAddress As New com.sun.star.table.CellAddress
 | 
			
		||||
	Dim aRangeAddress As New com.sun.star.table.CellRangeAddress
 | 
			
		||||
	
 | 
			
		||||
	oSelection = oDoc.getCurrentSelection
 | 
			
		||||
	
 | 
			
		||||
	' Some data ranges are already selected.
 | 
			
		||||
	If Not oSelection.supportsService ("com.sun.star.sheet.SheetCell") Then
 | 
			
		||||
		' Takes the first selection in multiple selections
 | 
			
		||||
		If oSelection.supportsService ("com.sun.star.sheet.SheetCellRanges") Then
 | 
			
		||||
			fnFindActiveDataRange = oSelection.getByIndex (0)
 | 
			
		||||
		' The only selection
 | 
			
		||||
		Else
 | 
			
		||||
			fnFindActiveDataRange = oSelection
 | 
			
		||||
		End If
 | 
			
		||||
		Exit Function
 | 
			
		||||
	End If
 | 
			
		||||
	
 | 
			
		||||
	' Finds the data range containing the single active cell
 | 
			
		||||
	aCellAddress = oSelection.getCellAddress
 | 
			
		||||
	oRanges = oSelection.getSpreadsheet.queryContentCells ( _
 | 
			
		||||
		com.sun.star.sheet.CellFlags.VALUE _
 | 
			
		||||
		+ com.sun.star.sheet.CellFlags.DATETIME _
 | 
			
		||||
		+ com.sun.star.sheet.CellFlags.STRING _
 | 
			
		||||
		+ com.sun.star.sheet.CellFlags.FORMULA)
 | 
			
		||||
	For nI = 0 To oRanges.getCount - 1
 | 
			
		||||
		oRange = oRanges.getByIndex (nI)
 | 
			
		||||
		aRangeAddress = oRange.getRangeAddress
 | 
			
		||||
		If 		aRangeAddress.StartRow <= aCellAddress.Row _
 | 
			
		||||
				And aRangeAddress.EndRow >= aCellAddress.Row _
 | 
			
		||||
				And aRangeAddress.StartColumn <= aCellAddress.Column _
 | 
			
		||||
				And aRangeAddress.EndColumn >= aCellAddress.Column Then
 | 
			
		||||
			oDoc.getCurrentController.select (oRange)
 | 
			
		||||
			fnFindActiveDataRange = oRange
 | 
			
		||||
			Exit Function
 | 
			
		||||
		End If
 | 
			
		||||
	Next nI
 | 
			
		||||
	' Not in a data cell range
 | 
			
		||||
End Function
 | 
			
		||||
		Reference in New Issue
	
	Block a user