Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Sub Main
  4.  
  5. Dim oRange
  6. Dim arkuszK, arkuszZ, arkuszKC, arkuszZC, Ekstrakt
  7. Dim kursorK, kursorZ
  8. Dim Klient
  9. Dim Zakup
  10. Dim s As String 'String ogólnego przeznaczenia ;)
  11. Dim i As Integer, j As Integer 'Do indeksowania
  12. Dim out As String 'arkusz wyjściowy
  13. Dim ar 'Tablica na wyniki pośrednie
  14. Dim d 'Data pośrdnia
  15. Dim ileK 'ile klientow
  16. Dim ileZ 'ile zakupów
  17. Dim path as String 'ścieżka do arkusza
  18. Dim srcpath 'ścieżka do folderu zawierającego arkusz
  19. Dim rMaxDate 'data ostatnich zakupów
  20.  
  21. ileK = ileKlientow()
  22. ileZ = ileZakupow()
  23.  
  24. arkuszK = ThisComponent.Sheets(0) 'arkusz klientów jest pierwszy w skoroszycie
  25. arkuszZ = ThisCOmponent.Sheets(1) 'arkusz zakupów - drugi
  26. oRange = arkuszK.getCellRangeByPosition(0,1,2,ileK) 'pobranie zakresu z klietami (bez nagłówków)
  27. Klient = oRange.getDataArray() 'pobranie tablicy z klientami z zakresu
  28. oRange = arkuszZ.getCellRangeByPosition(0,1,3,ileZ) 'analogicznie z zakupami
  29. Zakup = oRange.getDataArray()
  30.  
  31. out = "KlientC"                                  'usuwamy arkuz 'KlientC' tylko jesli istnieje
  32. If ThisComponent.Sheets().hasByName(out) Then
  33.     ThisComponent.Sheets().removeByName(out)
  34. End If
  35. ThisComponent.Sheets().insertNewByName(out, 2)   'tworzymy arkusz na oczyszczone dane
  36.  
  37. arkuszKC = ThisComponent.Sheets(2) 'arkusz KlientC
  38. arkuszKC.getCellRangeByName("A1").String = "Imię"
  39. arkuszKC.getCellRangeByName("B1").String = "Nazwisko"
  40. arkuszKC.getCellRangeByName("C1").String = "Wiek"
  41. arkuszKC.getCellRangeByName("D1").String = "Numer Klienta"
  42.  
  43. For i=0 To UBound(Klient) 'dla każdego klienta:
  44.     ar = Split(Klient(i)(0)," ") 'rozbij na imię i nazwisko
  45.     s = ar(0) 'imię jest pierwsze
  46.     s=TrimAll(s) 'obetnij spacje (w tym twarde spacje)
  47.     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))
  48.     arkuszKC.getCellByPosition(0,i+1).String = s 'wstaw imię
  49.     s = ar(UBound(ar)) 'to samo z nazwiskiem, nazwisko to ostatni element tablicy powstałem po rozbiciu
  50.     s=TrimAll(s)
  51.     s = Chr(Asc(Mid(s,1,1))-32)&Mid(s,2)
  52.     arkuszKC.getCellByPosition(1,i+1).String = s
  53.     d = CDate(Klient(i)(1)) 'pobierz ciąg z datą i skonwertuj na typ Date w Basicu
  54.     arkuszKC.getCellByPosition(2,i+1).Value = Year(Now)-Year(d) 'wstaw różnicę między aktualnym rokiem a rokiem urodzenia do kolumny "wiek"
  55.     arkuszKC.getCellByPosition(3,i+1).Value = Klient(i)(2) ''Nr klienta wstaw bez zmian
  56. Next i
  57.  
  58. out = "ZakupyC"                                 'usuwamy arkusz ZakupyC jeśli istnieje...
  59. If ThisComponent.Sheets().hasByName(out) Then
  60.     ThisComponent.Sheets().removeByName(out)
  61. End If
  62. ThisComponent.Sheets().insertNewByName(out, 3)
  63.  
  64. arkuszZC = ThisComponent.Sheets(3) 'arkusz ZakupyC
  65. arkuszZC.getCellRangeByName("A1").String = "Numer Klienta" 'nagłówki
  66. arkuszZC.getCellRangeByName("B1").String = "Data zakupów"
  67. arkuszZC.getCellRangeByName("C1").String = "Rozmiar koszyka"
  68. arkuszZC.getCellRangeByName("D1").String = "Cena koszyka"
  69.  
  70. Dim maxDate
  71. maxDate = Datevalue(Zakup(0)(1)) 'będziemy w pętli szukać ostatniej daty...
  72.  
  73. For i=0 To UBound(Zakup)
  74.     If Datevalue(Zakup(i)(1))>maxDate Then 'jeśli napotkana data jest większa, podstaw ją
  75.         maxDate = Datevalue(Zakup(i)(1))
  76.     End If
  77.     arkuszZC.getCellByPosition(0,i+1).Value = Zakup(i)(0) 'wstawiamy dane...
  78.     arkuszZC.getCellByPosition(1,i+1).String = CDate(Zakup(i)(1))
  79.     arkuszZC.getCellByPosition(2,i+1).Value = Zakup(i)(2)
  80.     arkuszZC.getCellByPosition(3,i+1).Value = Zakup(i)(3)
  81. Next i
  82.  
  83. rMaxDate = maxDate 'nieopatrznie używałem potem maxDate do czegoś innego, trzeba ją zapamiętać w tym miejscu (rMaxDate jak REAL MaxDate)
  84.  
  85. out = "Ekstrakt" 'arkusz wyjściowy
  86. If ThisComponent.Sheets().hasByName(out) Then
  87.     ThisComponent.Sheets().removeByName(out)
  88. End If
  89. ThisComponent.Sheets().insertNewByName(out, 4)
  90. Ekstrakt = ThisComponent.Sheets(4)
  91. Ekstrakt.getCellByPosition(0,0).String = "Imię"
  92. Ekstrakt.getCellByPosition(1,0).String = "Nazwisko"
  93. Ekstrakt.getCellByPosition(2,0).String = "Wiek"
  94. Ekstrakt.getCellByPosition(3,0).String = "Data ostatnich zakupów"
  95. Ekstrakt.getCellByPosition(4,0).String = "Liczba produktów zakupionych podczas ostatnich zakupów"
  96. Ekstrakt.getCellByPosition(5,0).String = "Liczba wszystkich zakupionych produktów"
  97. Ekstrakt.getCellByPosition(6,0).String = "Suma wydatków klienta"
  98. Ekstrakt.getCellByPosition(7,0).String = "Liczba dokonanych przez klienta zakupów"
  99.  
  100. oRange = arkuszKC.getCellRangeByPosition(0,1,3,ileK)
  101. Klient = oRange.getDataArray() 'pobieramy do tablicy już oczyszczone dane
  102. oRange = arkuszZC.getCellRangeByPosition(0,1,3,ileZ)
  103. Zakup = oRange.getDataArray()
  104.  
  105.  
  106.  
  107.  
  108. Dim id As Integer
  109. Dim lo As Integer 'liczba produktow zakupionych podczas ostatnich zakupow
  110. Dim lw As Integer 'liczba wszystkich zakupionych przez danego klienta produktow
  111. Dim sw As Double  'sumaryczna kwota zostawiona w sklepie przez klienta
  112. Dim lz As Integer 'liczba dokonanych przez klienta zakupów
  113.  
  114. For i=0 To UBound(Klient)
  115.     Ekstrakt.getCellByPosition(0,i+1).String = Klient(i)(0)
  116.     Ekstrakt.getCellByPosition(1,i+1).String = Klient(i)(1)
  117.     Ekstrakt.getCellByPosition(2,i+1).Value = Klient(i)(2)
  118.     id = Klient(i)(3)
  119.     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
  120.     lo = 0
  121.     lw = 0
  122.     sw = 0
  123.     lz = 0
  124.     For j=0 To Ubound(Zakup)
  125.         If Zakup(j)(0)=id Then
  126.             If Datevalue(Zakup(j)(1))>maxDate Then 'porównanie daty zakupów z maxDate
  127.                 maxDate = Datevalue(Zakup(j)(1))
  128.                 lo = Zakup(j)(2)
  129.             End If
  130.             lw = lw + Zakup(j)(2)
  131.             sw = sw + Zakup(j)(3)
  132.             lz=lz+1
  133.         End If
  134.     Next j
  135.     Ekstrakt.getCellByPosition(3,i+1).String = maxDate
  136.     Ekstrakt.getCellByPosition(4,i+1).Value = lo
  137.     Ekstrakt.getCellByPosition(5,i+1).Value = lw
  138.     Ekstrakt.getCellByPosition(6,i+1).Value = sw
  139.     Ekstrakt.getCellByPosition(7,i+1).Value = lz
  140. Next i
  141.  
  142. ''''''''''''''''''KONIEC PRACY NA ARKUSZACH''''''''''''''''''''
  143.  
  144. oRange = Ekstrakt.getCellRangeByPosition(0,1,7,ileK) 'pobranie tablicy danych z ostatniego arkusza
  145. Klient = oRange.getDataArray()
  146.  
  147. Dim Turnover 'Całkowity obrót sklepu
  148. Turnover = 0
  149.  
  150. For i=0 To Ubound(Klient)
  151.     Turnover = Turnover + Klient(i)(6) 'sumujemy...
  152. Next i
  153.  
  154. path = ThisComponent.getURL() 'pobieramy ścieżkę do skoroszytu
  155.  
  156.  
  157. Dim index 'tutaj operacja wyszukiwania ostatniego slasha w ścieżce do pliku, aby uzyskać ścieżkę do folderu
  158. index = InStr(path,"/")
  159. Dim t
  160. t = index
  161. Do While t<>0 'dopóki znajdujesz / (indeks nie jest zerowy)
  162.     t = InStr(Mid(path,index+1),"/") 'wyszukuj w pozostałej części stringa
  163.     index = t+index 'i dodaj indeks do aktualnej pozycji
  164. Loop
  165.  
  166. srcpath = Left(path,index) & "src/" 'stronę będziemy tworzyć w subfolderze src
  167.  
  168. MkDir(srcpath) 'utwórz folder
  169.  
  170. Dim outfile
  171. outfile = FreeFile 'utwórz plik
  172. Open srcpath & "index.html" For Output As #outfile
  173.     Print #outfile, "<!DOCTYPE html>"
  174.     Print #outfile, "<html lang=""en"">"
  175.     Print #outfile, "<head>"
  176.     Print #outfile, "<title>Raport</title>"
  177.     Print #outfile, "<meta charset=""utf-8"">"
  178.     Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
  179.     Print #outfile, "</head>"
  180.     Print #outfile, "<body>"
  181.     Print #outfile, "<div class=""navbar navbar-inverse"">"
  182.     Print #outfile, "<div class=""container-fluid"">"
  183.     Print #outfile, "<div class=""navbar-header"">"
  184.     Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
  185.     Print #outfile, "</div>"
  186.     Print #outfile, "<ul class=""nav navbar-nav"">"
  187.     Print #outfile, "<li class=""active""><a href=""#"">Summary</a></li>"
  188.     Print #outfile, "<li><a href=""statystyka.html"">Statistics</a></li>"
  189.     Print #outfile, "<li><a href=""oautorze.html"">About author</a></li>"
  190.     Print #outfile, "</ul>"
  191.     Print #outfile, "</div>"
  192.     Print #outfile, "</div>"
  193.     Print #outfile, "<div class=""jumbotron"">"
  194.     Print #outfile, "<div class=""container"">"
  195.     Print #outfile, "<h1>Summary</h1>"
  196.     Print #outfile, "<h2>The text below contains the most important informations concerning the shop: the number of clients, the total turnover etc.</h2>"
  197.     Print #outfile, "<p>There are ";
  198.     Print #outfile, ileK;
  199.     Print #outfile, " clients in the shop, who visited us ";
  200.     Print #outfile, ileZ;
  201.     Print #outfile, " times. They have left in the shop ";
  202.     Print #outfile, Turnover;
  203.     Print #outfile, " PLN.</p>"
  204.     Print #outfile, "<p>The last purchase took place ";
  205.     Print #outfile, rMaxDate;
  206.     Print #outfile, "</p>"
  207.     Print #outfile, "</div>"
  208.     Print #outfile, "</div>"
  209.     Print #outfile, "</body>"
  210.     Print #outfile, "</html>"
  211. Close outfile
  212.  
  213. outfile = FreeFile
  214. Open srcpath & "oautorze.html" For Output As #outfile
  215.     Print #outfile, "<!DOCTYPE html>"
  216.     Print #outfile, "<html lang=""en"">"
  217.     Print #outfile, "<head>"
  218.     Print #outfile, "<title>Raport</title>"
  219.     Print #outfile, "<meta charset=""utf-8"">"
  220.     Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
  221.     Print #outfile, "</head>"
  222.     Print #outfile, "<body>"
  223.     Print #outfile, "<div class=""navbar navbar-inverse"">"
  224.     Print #outfile, "<div class=""container-fluid"">"
  225.     Print #outfile, "<div class=""navbar-header"">"
  226.     Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
  227.     Print #outfile, "</div>"
  228.     Print #outfile, "<ul class=""nav navbar-nav"">"
  229.     Print #outfile, "<li><a href=""index.html"">Summary</a></li>"
  230.     Print #outfile, "<li><a href=""statystyka.html"">Statistics</a></li>"
  231.     Print #outfile, "<li class=""active""><a href=""#"">About author</a></li>"
  232.     Print #outfile, "</ul>"
  233.     Print #outfile, "</div>"
  234.     Print #outfile, "</div>"
  235.     Print #outfile, "<div class=""jumbotron"">"
  236.     Print #outfile, "<div class=""container"">"
  237.     Print #outfile, "<h1 class=""display-3"">About author</h1>"
  238.     Print #outfile, "<p>Firstname & Lastname: Michal Kaczanowicz</p>"
  239.     Print #outfile, "<p>Index: 221122</p>"
  240.     Print #outfile, "<p>Group: Lic. Bartlomiej Mortka, Wednesday, 11:15</p>"
  241.     Print #outfile, "</div>"
  242.     Print #outfile, "</div>"
  243.     Print #outfile, "</body>"
  244.     Print #outfile, "</html>"
  245. Close outfile
  246.  
  247. outfile = FreeFile
  248. Open srcpath & "raport.html" For Output As #outfile
  249.     Print #outfile, "<!DOCTYPE html>"
  250.     Print #outfile, "<html lang=""en"">"
  251.     Print #outfile, "<head>"
  252.     Print #outfile, "<title>Raport</title>"
  253.     Print #outfile, "<meta charset=""utf-8"">"
  254.     Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
  255.     Print #outfile, "</head>"
  256.     Print #outfile, "<body>"
  257.     Print #outfile, "<div class=""navbar navbar-inverse"">"
  258.     Print #outfile, "<div class=""container-fluid"">"
  259.     Print #outfile, "<div class=""navbar-header"">"
  260.     Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
  261.     Print #outfile, "</div>"
  262.     Print #outfile, "<ul class=""nav navbar-nav"">"
  263.     Print #outfile, "<li><a href=""index.html"">Summary</a></li>"
  264.     Print #outfile, "<li><a href=""statystyka.html"">Statistics</a></li>"
  265.     Print #outfile, "<li><a href=""oautorze.html"">About author</a></li>"
  266.     Print #outfile, "</ul>"
  267.     Print #outfile, "</div>"
  268.     Print #outfile, "</div>"
  269.     Print #outfile, "<div class=""jumbotron"">"
  270.     Print #outfile, "<div class=""container"">"
  271.     Print #outfile, "<h1 class=""display-3"">Project</h1>"
  272.     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>"
  273.     Print #outfile, "</div>"
  274.     Print #outfile, "</div>"
  275.     Print #outfile, "<div class=""container"">"
  276.     Print #outfile, "<footer>"
  277.     Print #outfile, "<p>&copy; Michal Kaczanowicz</p>"
  278.     Print #outfile, "</footer>"
  279.     Print #outfile, "</div>"
  280.     Print #outfile, "</body>"
  281.     Print #outfile, "</html>"
  282. Close outfile
  283.  
  284. outfile = FreeFile
  285. Open srcpath & "statystyka.html" For Output As #outfile
  286.     Print #outfile, "<!DOCTYPE html>"
  287.     Print #outfile, "<html lang=""en"">"
  288.     Print #outfile, "<head>"
  289.     Print #outfile, "<title>Raport</title>"
  290.     Print #outfile, "<meta charset=""utf-8"">"
  291.     Print #outfile, "<link rel=""stylesheet"" href=""https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"">"
  292.     Print #outfile, "</head>"
  293.     Print #outfile, "<body>"
  294.     Print #outfile, "<div class=""navbar navbar-inverse"">"
  295.     Print #outfile, "<div class=""container-fluid"">"
  296.     Print #outfile, "<div class=""navbar-header"">"
  297.     Print #outfile, "<a class=""navbar-brand"" href=""raport.html"">Report</a>"
  298.     Print #outfile, "</div>"
  299.     Print #outfile, "<ul class=""nav navbar-nav"">"
  300.     Print #outfile, "<li><a href=""index.html"">Summary</a></li>"
  301.     Print #outfile, "<li class=""active""><a href=""statystyka.html"">Statistics</a></li>"
  302.     Print #outfile, "<li><a href=""oautorze.html"">About author</a></li>"
  303.     Print #outfile, "</ul>"
  304.     Print #outfile, "</div>"
  305.     Print #outfile, "</div>"
  306.     Print #outfile, "<body>"
  307.     Print #outfile, "<div class=""jumbotron"">"
  308.     Print #outfile, "<div class=""container"">"
  309.     Print #outfile, "<h1 class=""display-3"">Detailed data</h1>"
  310.     Print #outfile, "<p>The table below contains detailed data about every client</p>"
  311.     Print #outfile, "</div>"
  312.     Print #outfile, "</div>"
  313.     Print #outfile, "<div class=""container"">"
  314.     Print #outfile, "<table class=""table table-bordered"">"
  315.     Print #outfile, "<thead>"
  316.     Print #outfile, "<tr>"
  317.     Print #outfile, "<th>Firstname</th>"
  318.     Print #outfile, "<th>Lastname</th>"
  319.     Print #outfile, "<th>Age</th>"
  320.     Print #outfile, "<th>Last purchase</th>"
  321.     Print #outfile, "<th>Purchased products</th>"
  322.     Print #outfile, "<th>Sum of purchases</th>"
  323.     Print #outfile, "<th>Shoppings</th>"
  324.     Print #outfile, "</thead>"
  325.     Print #outfile, "<tbody>"
  326.     For i=0 To Ubound(Klient) 'tutaj przeleć po tablicy klientów wraz z danymi izapisuj je w tabeli
  327.         Print #outfile, "<tr>"
  328.         Print #outfile, "<td>";
  329.         Print #outfile, Klient(i)(0);
  330.         Print #outfile, "</td>"
  331.         Print #outfile, "<td>";
  332.         Print #outfile, Klient(i)(1);
  333.         Print #outfile, "</td>"
  334.         Print #outfile, "<td>";
  335.         Print #outfile, Klient(i)(2);
  336.         Print #outfile, "</td>"
  337.         Print #outfile, "<td>";
  338.         If Klient(i)(3)<>"-1" Then
  339.             Print #outfile, Klient(i)(3); 'jęsli klient dokonał jakiś zakupów to fajnie
  340.         Else
  341.             Print #outfile, "-"; 'a jak nie to wstaw '-'
  342.         End If
  343.         Print #outfile, "</td>"
  344.         Print #outfile, "<td>";
  345.         Print #outfile, Klient(i)(5);
  346.         Print #outfile, "</td>"
  347.         Print #outfile, "<td>";
  348.         Print #outfile, Klient(i)(6) & " PLN";
  349.         Print #outfile, "</td>"
  350.         Print #outfile, "<td>";
  351.         Print #outfile, Klient(i)(7);
  352.         Print #outfile, "</td>"
  353.         Print #outfile, "<tr>"
  354.     Next i
  355.     Print #outfile, "</body>"
  356.     Print #outfile, "</html>"
  357. Close outfile
  358.  
  359.  
  360. End Sub
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368. Function ileKlientow
  369.     'funkcja zwraca ile klientow jest w sklepie
  370.     Dim kursorK
  371.     kursorK = ThisComponent.Sheets(0).createCursor()
  372.     kursorK.gotoEndOfUsedArea(false)
  373.     ileKlientow = kursorK.getRangeAddress().EndRow
  374. End Function
  375.  
  376. Function ileZakupow
  377.     'funkcja zwraca ile zostalo dokonanych zakupow
  378.     Dim kursorZ
  379.     kursorZ = ThisComponent.Sheets(1).createCursor()
  380.     kursorZ.gotoEndOfUsedArea(false)
  381.     ileZakupow = kursorZ.getRangeAddress().EndRow
  382. End Function
  383.  
  384. Function TrimAll(ByVal Str)
  385.     'funkcja usuwa zbedne spacje z poczatku i konca wyrazu (wlacznie z twarda spacja, asc= 160)
  386.     Dim s As String
  387.     s = Trim(Str)
  388.     Do While Asc(Left(s,1))=160 Or Asc(Left(s,1))=32
  389.         s=Mid(s,2)
  390.     Loop
  391.     Do While Asc(Right(s,1))=160 Or Asc(Right(s,1))=32
  392.         s=Left(s, Len(s)-1)
  393.     Loop
  394.     TrimAll = s
  395. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement