Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub Main
- Dim oRange
- Dim arkuszK, arkuszZ, arkuszKC, arkuszZC, Ekstrakt
- Dim kursorK, kursorZ
- Dim Klient
- Dim Zakup
- Dim s As String 'String ogólnego przeznaczenia ;)
- Dim i As Integer, j As Integer 'Do indeksowania
- Dim out As String 'arkusz wyjściowy
- Dim ar 'Tablica na wyniki pośrednie
- Dim d 'Data pośrdnia
- Dim ileK 'ile klientow
- Dim ileZ 'ile zakupów
- Dim path as String 'ścieżka do arkusza
- Dim srcpath 'ścieżka do folderu zawierającego arkusz
- Dim rMaxDate 'data ostatnich zakupów
- ileK = ileKlientow()
- ileZ = ileZakupow()
- arkuszK = ThisComponent.Sheets(0) 'arkusz klientów jest pierwszy w skoroszycie
- arkuszZ = ThisCOmponent.Sheets(1) 'arkusz zakupów - drugi
- oRange = arkuszK.getCellRangeByPosition(0,1,2,ileK) 'pobranie zakresu z klietami (bez nagłówków)
- Klient = oRange.getDataArray() 'pobranie tablicy z klientami z zakresu
- oRange = arkuszZ.getCellRangeByPosition(0,1,3,ileZ) 'analogicznie z zakupami
- Zakup = oRange.getDataArray()
- out = "KlientC" 'usuwamy arkuz 'KlientC' tylko jesli istnieje
- If ThisComponent.Sheets().hasByName(out) Then
- ThisComponent.Sheets().removeByName(out)
- End If
- ThisComponent.Sheets().insertNewByName(out, 2) 'tworzymy arkusz na oczyszczone dane
- arkuszKC = ThisComponent.Sheets(2) 'arkusz KlientC
- arkuszKC.getCellRangeByName("A1").String = "Imię"
- arkuszKC.getCellRangeByName("B1").String = "Nazwisko"
- arkuszKC.getCellRangeByName("C1").String = "Wiek"
- arkuszKC.getCellRangeByName("D1").String = "Numer Klienta"
- For i=0 To UBound(Klient) 'dla każdego klienta:
- ar = Split(Klient(i)(0)," ") 'rozbij na imię i nazwisko
- s = ar(0) 'imię jest pierwsze
- s=TrimAll(s) 'obetnij spacje (w tym twarde spacje)
- s = Chr(Asc(Mid(s,1,1))-32)&Mid(s,2) 'podstaw pod imię imię z pierwszą literą zmienioną na wielką (Asc(a)-32=Asc(A))
- arkuszKC.getCellByPosition(0,i+1).String = s 'wstaw imię
- s = ar(UBound(ar)) 'to samo z nazwiskiem, nazwisko to ostatni element tablicy powstałem po rozbiciu
- s=TrimAll(s)
- s = Chr(Asc(Mid(s,1,1))-32)&Mid(s,2)
- arkuszKC.getCellByPosition(1,i+1).String = s
- d = CDate(Klient(i)(1)) 'pobierz ciąg z datą i skonwertuj na typ Date w Basicu
- arkuszKC.getCellByPosition(2,i+1).Value = Year(Now)-Year(d) 'wstaw różnicę między aktualnym rokiem a rokiem urodzenia do kolumny "wiek"
- arkuszKC.getCellByPosition(3,i+1).Value = Klient(i)(2) ''Nr klienta wstaw bez zmian
- Next i
- out = "ZakupyC" 'usuwamy arkusz ZakupyC jeśli istnieje...
- If ThisComponent.Sheets().hasByName(out) Then
- ThisComponent.Sheets().removeByName(out)
- End If
- ThisComponent.Sheets().insertNewByName(out, 3)
- arkuszZC = ThisComponent.Sheets(3) 'arkusz ZakupyC
- arkuszZC.getCellRangeByName("A1").String = "Numer Klienta" 'nagłówki
- arkuszZC.getCellRangeByName("B1").String = "Data zakupów"
- arkuszZC.getCellRangeByName("C1").String = "Rozmiar koszyka"
- arkuszZC.getCellRangeByName("D1").String = "Cena koszyka"
- Dim maxDate
- maxDate = Datevalue(Zakup(0)(1)) 'będziemy w pętli szukać ostatniej daty...
- For i=0 To UBound(Zakup)
- If Datevalue(Zakup(i)(1))>maxDate Then 'jeśli napotkana data jest większa, podstaw ją
- maxDate = Datevalue(Zakup(i)(1))
- End If
- arkuszZC.getCellByPosition(0,i+1).Value = Zakup(i)(0) 'wstawiamy dane...
- arkuszZC.getCellByPosition(1,i+1).String = CDate(Zakup(i)(1))
- arkuszZC.getCellByPosition(2,i+1).Value = Zakup(i)(2)
- arkuszZC.getCellByPosition(3,i+1).Value = Zakup(i)(3)
- Next i
- rMaxDate = maxDate 'nieopatrznie używałem potem maxDate do czegoś innego, trzeba ją zapamiętać w tym miejscu (rMaxDate jak REAL MaxDate)
- out = "Ekstrakt" 'arkusz wyjściowy
- If ThisComponent.Sheets().hasByName(out) Then
- ThisComponent.Sheets().removeByName(out)
- End If
- ThisComponent.Sheets().insertNewByName(out, 4)
- Ekstrakt = ThisComponent.Sheets(4)
- Ekstrakt.getCellByPosition(0,0).String = "Imię"
- Ekstrakt.getCellByPosition(1,0).String = "Nazwisko"
- Ekstrakt.getCellByPosition(2,0).String = "Wiek"
- Ekstrakt.getCellByPosition(3,0).String = "Data ostatnich zakupów"
- Ekstrakt.getCellByPosition(4,0).String = "Liczba produktów zakupionych podczas ostatnich zakupów"
- Ekstrakt.getCellByPosition(5,0).String = "Liczba wszystkich zakupionych produktów"
- Ekstrakt.getCellByPosition(6,0).String = "Suma wydatków klienta"
- Ekstrakt.getCellByPosition(7,0).String = "Liczba dokonanych przez klienta zakupów"
- oRange = arkuszKC.getCellRangeByPosition(0,1,3,ileK)
- Klient = oRange.getDataArray() 'pobieramy do tablicy już oczyszczone dane
- oRange = arkuszZC.getCellRangeByPosition(0,1,3,ileZ)
- Zakup = oRange.getDataArray()
- Dim id As Integer
- Dim lo As Integer 'liczba produktow zakupionych podczas ostatnich zakupow
- Dim lw As Integer 'liczba wszystkich zakupionych przez danego klienta produktow
- Dim sw As Double 'sumaryczna kwota zostawiona w sklepie przez klienta
- Dim lz As Integer 'liczba dokonanych przez klienta zakupów
- For i=0 To UBound(Klient)
- Ekstrakt.getCellByPosition(0,i+1).String = Klient(i)(0)
- Ekstrakt.getCellByPosition(1,i+1).String = Klient(i)(1)
- Ekstrakt.getCellByPosition(2,i+1).Value = Klient(i)(2)
- id = Klient(i)(3)
- maxDate = -1 'będziemy poszukiwać dla każdego klienta w pętli daty ostatnich zakupów, jeśli nie było żadnych to zostanie -1
- lo = 0
- lw = 0
- sw = 0
- lz = 0
- For j=0 To Ubound(Zakup)
- If Zakup(j)(0)=id Then
- If Datevalue(Zakup(j)(1))>maxDate Then 'porównanie daty zakupów z maxDate
- maxDate = Datevalue(Zakup(j)(1))
- lo = Zakup(j)(2)
- End If
- lw = lw + Zakup(j)(2)
- sw = sw + Zakup(j)(3)
- lz=lz+1
- End If
- Next j
- Ekstrakt.getCellByPosition(3,i+1).String = maxDate
- Ekstrakt.getCellByPosition(4,i+1).Value = lo
- Ekstrakt.getCellByPosition(5,i+1).Value = lw
- Ekstrakt.getCellByPosition(6,i+1).Value = sw
- Ekstrakt.getCellByPosition(7,i+1).Value = lz
- Next i
- ''''''''''''''''''KONIEC PRACY NA ARKUSZACH''''''''''''''''''''
- oRange = Ekstrakt.getCellRangeByPosition(0,1,7,ileK) 'pobranie tablicy danych z ostatniego arkusza
- Klient = oRange.getDataArray()
- Dim Turnover 'Całkowity obrót sklepu
- Turnover = 0
- For i=0 To Ubound(Klient)
- Turnover = Turnover + Klient(i)(6) 'sumujemy...
- Next i
- path = ThisComponent.getURL() 'pobieramy ścieżkę do skoroszytu
- Dim index 'tutaj operacja wyszukiwania ostatniego slasha w ścieżce do pliku, aby uzyskać ścieżkę do folderu
- index = InStr(path,"/")
- Dim t
- t = index
- Do While t<>0 'dopóki znajdujesz / (indeks nie jest zerowy)
- t = InStr(Mid(path,index+1),"/") 'wyszukuj w pozostałej części stringa
- index = t+index 'i dodaj indeks do aktualnej pozycji
- Loop
- srcpath = Left(path,index) & "src/" 'stronę będziemy tworzyć w subfolderze src
- MkDir(srcpath) 'utwórz folder
- Dim outfile
- outfile = FreeFile 'utwórz plik
- Open srcpath & "index.html" For Output As #outfile
- Print #outfile, "<!DOCTYPE html>"
- Print #outfile, "<html lang=""en"">"
- Print #outfile, "<head>"
- Print #outfile, "<title>Raport</title>"
- Print #outfile, "<meta charset=""utf-8"">"
- Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
- Print #outfile, "</head>"
- Print #outfile, "<body>"
- Print #outfile, "<div class=""navbar navbar-inverse"">"
- Print #outfile, "<div class=""container-fluid"">"
- Print #outfile, "<div class=""navbar-header"">"
- Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
- Print #outfile, "</div>"
- Print #outfile, "<ul class=""nav navbar-nav"">"
- Print #outfile, "<li class=""active""><a href=""#"">Summary</a></li>"
- Print #outfile, "<li><a href=""statystyka.html"">Statistics</a></li>"
- Print #outfile, "<li><a href=""oautorze.html"">About author</a></li>"
- Print #outfile, "</ul>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "<div class=""jumbotron"">"
- Print #outfile, "<div class=""container"">"
- Print #outfile, "<h1>Summary</h1>"
- Print #outfile, "<h2>The text below contains the most important informations concerning the shop: the number of clients, the total turnover etc.</h2>"
- Print #outfile, "<p>There are ";
- Print #outfile, ileK;
- Print #outfile, " clients in the shop, who visited us ";
- Print #outfile, ileZ;
- Print #outfile, " times. They have left in the shop ";
- Print #outfile, Turnover;
- Print #outfile, " PLN.</p>"
- Print #outfile, "<p>The last purchase took place ";
- Print #outfile, rMaxDate;
- Print #outfile, "</p>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "</body>"
- Print #outfile, "</html>"
- Close outfile
- outfile = FreeFile
- Open srcpath & "oautorze.html" For Output As #outfile
- Print #outfile, "<!DOCTYPE html>"
- Print #outfile, "<html lang=""en"">"
- Print #outfile, "<head>"
- Print #outfile, "<title>Raport</title>"
- Print #outfile, "<meta charset=""utf-8"">"
- Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
- Print #outfile, "</head>"
- Print #outfile, "<body>"
- Print #outfile, "<div class=""navbar navbar-inverse"">"
- Print #outfile, "<div class=""container-fluid"">"
- Print #outfile, "<div class=""navbar-header"">"
- Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
- Print #outfile, "</div>"
- Print #outfile, "<ul class=""nav navbar-nav"">"
- Print #outfile, "<li><a href=""index.html"">Summary</a></li>"
- Print #outfile, "<li><a href=""statystyka.html"">Statistics</a></li>"
- Print #outfile, "<li class=""active""><a href=""#"">About author</a></li>"
- Print #outfile, "</ul>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "<div class=""jumbotron"">"
- Print #outfile, "<div class=""container"">"
- Print #outfile, "<h1 class=""display-3"">About author</h1>"
- Print #outfile, "<p>Firstname & Lastname: Michal Kaczanowicz</p>"
- Print #outfile, "<p>Index: 221122</p>"
- Print #outfile, "<p>Group: Lic. Bartlomiej Mortka, Wednesday, 11:15</p>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "</body>"
- Print #outfile, "</html>"
- Close outfile
- outfile = FreeFile
- Open srcpath & "raport.html" For Output As #outfile
- Print #outfile, "<!DOCTYPE html>"
- Print #outfile, "<html lang=""en"">"
- Print #outfile, "<head>"
- Print #outfile, "<title>Raport</title>"
- Print #outfile, "<meta charset=""utf-8"">"
- Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
- Print #outfile, "</head>"
- Print #outfile, "<body>"
- Print #outfile, "<div class=""navbar navbar-inverse"">"
- Print #outfile, "<div class=""container-fluid"">"
- Print #outfile, "<div class=""navbar-header"">"
- Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
- Print #outfile, "</div>"
- Print #outfile, "<ul class=""nav navbar-nav"">"
- Print #outfile, "<li><a href=""index.html"">Summary</a></li>"
- Print #outfile, "<li><a href=""statystyka.html"">Statistics</a></li>"
- Print #outfile, "<li><a href=""oautorze.html"">About author</a></li>"
- Print #outfile, "</ul>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "<div class=""jumbotron"">"
- Print #outfile, "<div class=""container"">"
- Print #outfile, "<h1 class=""display-3"">Project</h1>"
- Print #outfile, "<p>The site below was created as a final project for classes of Information Technology run by Andrzej Giniewicz in academic year 2016/17</p>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "<div class=""container"">"
- Print #outfile, "<footer>"
- Print #outfile, "<p>© Michal Kaczanowicz</p>"
- Print #outfile, "</footer>"
- Print #outfile, "</div>"
- Print #outfile, "</body>"
- Print #outfile, "</html>"
- Close outfile
- outfile = FreeFile
- Open srcpath & "statystyka.html" For Output As #outfile
- Print #outfile, "<!DOCTYPE html>"
- Print #outfile, "<html lang=""en"">"
- Print #outfile, "<head>"
- Print #outfile, "<title>Raport</title>"
- Print #outfile, "<meta charset=""utf-8"">"
- Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
- Print #outfile, "</head>"
- Print #outfile, "<body>"
- Print #outfile, "<div class=""navbar navbar-inverse"">"
- Print #outfile, "<div class=""container-fluid"">"
- Print #outfile, "<div class=""navbar-header"">"
- Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
- Print #outfile, "</div>"
- Print #outfile, "<ul class=""nav navbar-nav"">"
- Print #outfile, "<li><a href=""index.html"">Summary</a></li>"
- Print #outfile, "<li class=""active""><a href=""statystyka.html"">Statistics</a></li>"
- Print #outfile, "<li><a href=""oautorze.html"">About author</a></li>"
- Print #outfile, "</ul>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "<body>"
- Print #outfile, "<div class=""jumbotron"">"
- Print #outfile, "<div class=""container"">"
- Print #outfile, "<h1 class=""display-3"">Detailed data</h1>"
- Print #outfile, "<p>The table below contains detailed data about every client</p>"
- Print #outfile, "</div>"
- Print #outfile, "</div>"
- Print #outfile, "<div class=""container"">"
- Print #outfile, "<table class=""table table-bordered"">"
- Print #outfile, "<thead>"
- Print #outfile, "<tr>"
- Print #outfile, "<th>Firstname</th>"
- Print #outfile, "<th>Lastname</th>"
- Print #outfile, "<th>Age</th>"
- Print #outfile, "<th>Last purchase</th>"
- Print #outfile, "<th>Purchased products</th>"
- Print #outfile, "<th>Sum of purchases</th>"
- Print #outfile, "<th>Shoppings</th>"
- Print #outfile, "</thead>"
- Print #outfile, "<tbody>"
- For i=0 To Ubound(Klient) 'tutaj przeleć po tablicy klientów wraz z danymi izapisuj je w tabeli
- Print #outfile, "<tr>"
- Print #outfile, "<td>";
- Print #outfile, Klient(i)(0);
- Print #outfile, "</td>"
- Print #outfile, "<td>";
- Print #outfile, Klient(i)(1);
- Print #outfile, "</td>"
- Print #outfile, "<td>";
- Print #outfile, Klient(i)(2);
- Print #outfile, "</td>"
- Print #outfile, "<td>";
- If Klient(i)(3)<>"-1" Then
- Print #outfile, Klient(i)(3); 'jęsli klient dokonał jakiś zakupów to fajnie
- Else
- Print #outfile, "-"; 'a jak nie to wstaw '-'
- End If
- Print #outfile, "</td>"
- Print #outfile, "<td>";
- Print #outfile, Klient(i)(5);
- Print #outfile, "</td>"
- Print #outfile, "<td>";
- Print #outfile, Klient(i)(6) & " PLN";
- Print #outfile, "</td>"
- Print #outfile, "<td>";
- Print #outfile, Klient(i)(7);
- Print #outfile, "</td>"
- Print #outfile, "<tr>"
- Next i
- Print #outfile, "</body>"
- Print #outfile, "</html>"
- Close outfile
- End Sub
- Function ileKlientow
- 'funkcja zwraca ile klientow jest w sklepie
- Dim kursorK
- kursorK = ThisComponent.Sheets(0).createCursor()
- kursorK.gotoEndOfUsedArea(false)
- ileKlientow = kursorK.getRangeAddress().EndRow
- End Function
- Function ileZakupow
- 'funkcja zwraca ile zostalo dokonanych zakupow
- Dim kursorZ
- kursorZ = ThisComponent.Sheets(1).createCursor()
- kursorZ.gotoEndOfUsedArea(false)
- ileZakupow = kursorZ.getRangeAddress().EndRow
- End Function
- Function TrimAll(ByVal Str)
- 'funkcja usuwa zbedne spacje z poczatku i konca wyrazu (wlacznie z twarda spacja, asc= 160)
- Dim s As String
- s = Trim(Str)
- Do While Asc(Left(s,1))=160 Or Asc(Left(s,1))=32
- s=Mid(s,2)
- Loop
- Do While Asc(Right(s,1))=160 Or Asc(Right(s,1))=32
- s=Left(s, Len(s)-1)
- Loop
- TrimAll = s
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement