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