1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<!--***********************************************************
4*b1cdbd2cSJim Jagielski *
5*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
6*b1cdbd2cSJim Jagielski * or more contributor license agreements.  See the NOTICE file
7*b1cdbd2cSJim Jagielski * distributed with this work for additional information
8*b1cdbd2cSJim Jagielski * regarding copyright ownership.  The ASF licenses this file
9*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
10*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
11*b1cdbd2cSJim Jagielski * with the License.  You may obtain a copy of the License at
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski *   http://www.apache.org/licenses/LICENSE-2.0
14*b1cdbd2cSJim Jagielski *
15*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
16*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
17*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*b1cdbd2cSJim Jagielski * KIND, either express or implied.  See the License for the
19*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
20*b1cdbd2cSJim Jagielski * under the License.
21*b1cdbd2cSJim Jagielski *
22*b1cdbd2cSJim Jagielski ***********************************************************-->
23*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="CreateTable" script:language="StarBasic">Option Explicit
24*b1cdbd2cSJim Jagielski
25*b1cdbd2cSJim JagielskiPublic Const FirstDayRow = 5          &apos; Row on month sheet for first day of month
26*b1cdbd2cSJim JagielskiPublic Const DateColumn% = 3          &apos; Column on month sheet with days
27*b1cdbd2cSJim JagielskiPublic Const NewYearRow = 4           &apos; Row on year sheet for January 1st
28*b1cdbd2cSJim JagielskiPublic Const NewYearColumn = 2        &apos; Column on year sheet for January 1st
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim JagielskiSub CalCreateYearTable(ByVal iSelYear as Integer)
32*b1cdbd2cSJim Jagielski&apos; Completes the overview for whole year
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski&apos; Needed by StarOffice Calc and StarOffice Schedule
35*b1cdbd2cSJim JagielskiDim CalDay as Integer
36*b1cdbd2cSJim JagielskiDim CalMonth as Integer
37*b1cdbd2cSJim JagielskiDim i as Integer
38*b1cdbd2cSJim JagielskiDim s as Integer
39*b1cdbd2cSJim JagielskiDim oYearCell as object
40*b1cdbd2cSJim JagielskiDim iDate
41*b1cdbd2cSJim JagielskiDim ColPos, RowPos as Integer
42*b1cdbd2cSJim JagielskiDim oNameCell, oDateCell as Object
43*b1cdbd2cSJim JagielskiDim iCellValue as Long
44*b1cdbd2cSJim JagielskiDim oRangeFebCell, oCellAddress, oFebcell as Object
45*b1cdbd2cSJim JagielskiDim oRangeBlank as Object
46*b1cdbd2cSJim JagielskiDim sBlankStyle as String
47*b1cdbd2cSJim Jagielski&apos;	On Error Goto ErrorHandling
48*b1cdbd2cSJim Jagielski	oStatusLine.Start(&quot;&quot;,140)	&apos;GetResText(sProgress)
49*b1cdbd2cSJim Jagielski	iDate = DateSerial(iSelYear,1,1)
50*b1cdbd2cSJim Jagielski	oYearCell = oSheet.GetCellRangeByName(&quot;Year&quot;)
51*b1cdbd2cSJim Jagielski	oYearCell.Value = iSelYear
52*b1cdbd2cSJim Jagielski
53*b1cdbd2cSJim Jagielski	CalMonth = 1
54*b1cdbd2cSJim Jagielski	CalDay = 0
55*b1cdbd2cSJim Jagielski	s = 10
56*b1cdbd2cSJim Jagielski	oStatusLine.SetValue(s)
57*b1cdbd2cSJim Jagielski	For i = 1 To 374
58*b1cdbd2cSJim Jagielski		CalDay = CalDay+1
59*b1cdbd2cSJim Jagielski		If CalDay = 32 Then
60*b1cdbd2cSJim Jagielski			CalDay = 1
61*b1cdbd2cSJim Jagielski			CalMonth = CalMonth+1
62*b1cdbd2cSJim Jagielski			s = s + 10
63*b1cdbd2cSJim Jagielski			oStatusLine.SetValue(s)
64*b1cdbd2cSJim Jagielski		End If
65*b1cdbd2cSJim Jagielski		ColPos = NewYearColumn+(2*CalMonth)
66*b1cdbd2cSJim Jagielski		RowPos = NewYearRow + CalDay
67*b1cdbd2cSJim Jagielski		FormatCalCells(ColPos,RowPos,i)
68*b1cdbd2cSJim Jagielski	Next
69*b1cdbd2cSJim Jagielski	If NOT CalIsLeapYear(iSelYear) Then
70*b1cdbd2cSJim Jagielski		&apos; Delete 29th February if necessary
71*b1cdbd2cSJim Jagielski		oRangeFebCell = oSheet.GetCellRangeByName(&quot;Feb29&quot;)
72*b1cdbd2cSJim Jagielski		oCellAddress = oRangeFebCell.RangeAddress
73*b1cdbd2cSJim Jagielski		oFebCell = oSheet.GetCellByPosition(oCellAddress.StartColumn,oCellAddress.StartRow)
74*b1cdbd2cSJim Jagielski		oFebCell.String = &quot;&quot;
75*b1cdbd2cSJim Jagielski		&apos; Change the CellStyle according to the Range &quot;Blank&quot;
76*b1cdbd2cSJim Jagielski		oRangeBlank = oSheet.GetCellRangebyName(&quot;Blank&quot;)
77*b1cdbd2cSJim Jagielski		sBlankStyle = oRangeBlank.CellStyle
78*b1cdbd2cSJim Jagielski		oRangeFebCell.CellStyle = sBlankStyle
79*b1cdbd2cSJim Jagielski	End If
80*b1cdbd2cSJim Jagielski	oStatusLine.SetValue(150)
81*b1cdbd2cSJim Jagielski	ErrorHandling:
82*b1cdbd2cSJim Jagielski	If Err &lt;&gt; 0 Then
83*b1cdbd2cSJim Jagielski		MsgBox sError$, 16, sWizardTitle$
84*b1cdbd2cSJim Jagielski	End If
85*b1cdbd2cSJim JagielskiEnd Sub
86*b1cdbd2cSJim Jagielski
87*b1cdbd2cSJim Jagielski
88*b1cdbd2cSJim Jagielski
89*b1cdbd2cSJim JagielskiSub CalCreateMonthTable(ByVal iSelYear as Integer, iSelMonth as Integer)
90*b1cdbd2cSJim JagielskiDim oMonthCell, oDateCell as Object
91*b1cdbd2cSJim JagielskiDim iDate as Date
92*b1cdbd2cSJim JagielskiDim oAddress
93*b1cdbd2cSJim JagielskiDim i, s as Integer
94*b1cdbd2cSJim JagielskiDim iStartDay as Integer
95*b1cdbd2cSJim Jagielski
96*b1cdbd2cSJim Jagielski&apos; Completes the monthly calendar
97*b1cdbd2cSJim Jagielski&apos;On Error Goto ErrorHandling
98*b1cdbd2cSJim Jagielski	oStatusLine.Start(&quot;&quot;,40)		&apos;GetResText(sProgess)
99*b1cdbd2cSJim Jagielski	&apos; Set month
100*b1cdbd2cSJim Jagielski	oMonthCell = oSheet.GetCellRangeByName(&quot;Month&quot;)
101*b1cdbd2cSJim Jagielski
102*b1cdbd2cSJim Jagielski	iDate = DateSerial(iSelYear,iSelMonth,1)
103*b1cdbd2cSJim Jagielski	oMonthCell.Value = iDate
104*b1cdbd2cSJim Jagielski	&apos; Inserting holidays
105*b1cdbd2cSJim Jagielski	iStartDay = (iSelMonth - 1) * 31 + 1
106*b1cdbd2cSJim Jagielski	s = 5
107*b1cdbd2cSJim Jagielski	For i = iStartDay To iStartDay + 30
108*b1cdbd2cSJim Jagielski		oStatusLine.SetValue(s)
109*b1cdbd2cSJim Jagielski		s = s + 1
110*b1cdbd2cSJim Jagielski		FormatCalCells(DateColumn+1,FirstDayRow + i - iStartDay,i)
111*b1cdbd2cSJim Jagielski	Next
112*b1cdbd2cSJim Jagielski	oDateCell = oSheet.GetCellbyPosition(DateColumn,FirstDayRow+i-iStartDay - 1)
113*b1cdbd2cSJim Jagielski	oAddress = oDateCell.RangeAddress
114*b1cdbd2cSJim Jagielski
115*b1cdbd2cSJim Jagielski	Select Case iSelMonth
116*b1cdbd2cSJim Jagielski		Case 2,4,6,9,11
117*b1cdbd2cSJim Jagielski			oSheet.RemoveRange(oAddress, com.sun.star.sheet.CellDeleteMode.ROWS)
118*b1cdbd2cSJim Jagielski			If iSelMonth = 2 Then
119*b1cdbd2cSJim Jagielski				oAddress.StartRow = oAddress.StartRow - 1
120*b1cdbd2cSJim Jagielski				oAddress.EndRow = oAddress.StartRow
121*b1cdbd2cSJim Jagielski				oSheet.RemoveRange(oAddress, com.sun.star.sheet.CellDeleteMode.ROWS)
122*b1cdbd2cSJim Jagielski				If Not CalIsLeapYear(iSelYear) Then
123*b1cdbd2cSJim Jagielski					oAddress.StartRow = oAddress.StartRow - 1
124*b1cdbd2cSJim Jagielski					oAddress.EndRow = oAddress.StartRow
125*b1cdbd2cSJim Jagielski					oSheet.RemoveRange(oAddress, com.sun.star.sheet.CellDeleteMode.ROWS)
126*b1cdbd2cSJim Jagielski				End If
127*b1cdbd2cSJim Jagielski			End If
128*b1cdbd2cSJim Jagielski	End Select
129*b1cdbd2cSJim Jagielski	oStatusLine.SetValue(45)
130*b1cdbd2cSJim JagielskiErrorHandling:
131*b1cdbd2cSJim Jagielski	If Err &lt;&gt; 0 Then
132*b1cdbd2cSJim Jagielski		MsgBox sError$, 16, sWizardTitle$
133*b1cdbd2cSJim Jagielski	End If
134*b1cdbd2cSJim JagielskiEnd Sub
135*b1cdbd2cSJim Jagielski
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim Jagielski
138*b1cdbd2cSJim JagielskiSub FormatCalCells(ColPos,RowPos,i as Integer)
139*b1cdbd2cSJim JagielskiDim oNameCell, oDateCell as Object
140*b1cdbd2cSJim JagielskiDim iCellValue as Long
141*b1cdbd2cSJim Jagielski	oDateCell = oSheet.GetCellbyPosition(ColPos-1,RowPos)
142*b1cdbd2cSJim Jagielski	If oDateCell.Value &lt;&gt; 0 Then
143*b1cdbd2cSJim Jagielski		iCellValue = oDateCell.Value
144*b1cdbd2cSJim Jagielski		oDateCell.Value = iCellValue
145*b1cdbd2cSJim Jagielski		If CalBankHolidayName$(i) &lt;&gt; &quot;&quot; Then
146*b1cdbd2cSJim Jagielski			oNameCell = oSheet.GetCellbyPosition(ColPos,RowPos)
147*b1cdbd2cSJim Jagielski			oNameCell.String = CalBankHolidayName$(i)
148*b1cdbd2cSJim Jagielski			If CalTypeOfBankHoliday%(i) = cHolidayType_Full Then
149*b1cdbd2cSJim Jagielski				oDateCell.CellStyle = cCalStyleWeekend$
150*b1cdbd2cSJim Jagielski			End If
151*b1cdbd2cSJim Jagielski		End If
152*b1cdbd2cSJim Jagielski	End If
153*b1cdbd2cSJim JagielskiEnd Sub</script:module>
154