Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHPExcel] Import danych z pliku
maniek74
post
Post #1





Grupa: Zarejestrowani
Postów: 127
Pomógł: 0
Dołączył: 26.08.2013

Ostrzeżenie: (0%)
-----


Witam
W pliku Excel mam kolumnę 5,00 zł, przy imporcie otrzymuje $ 5.00. Jak można zrobić żeby otrzymać samo 5?
  1. <?php
  2. include '../class/PHPExcel/IOFactory.php';
  3. $inputFileName = '../Zeszyt1.xlsx';
  4. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  5. $allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
  6. $arrayCount = count($allDataInSheet);
  7. print '<table border="1">';
  8. for($i=3;$i<=$arrayCount;$i++){
  9. $collectName = $allDataInSheet[$i]["A"];
  10. $collectDateEnd = $allDataInSheet[$i]["B"];
  11. $collectLocation = $allDataInSheet[$i]["C"];
  12. $collectPrice = $allDataInSheet[$i]["D"];
  13. $collectEmail = $allDataInSheet[$i]["E"];
  14. $collectDate = $allDataInSheet[$i]["F"];
  15.  
  16. print '<tr>';
  17. print '<td>'.$collectName.'</td>';
  18. print '<td>'.$collectDateEnd.'</td>';
  19. print '<td>'.$collectLocation.'</td>';
  20. print '<td>'.$collectPrice.'</td>';
  21. print '<td>'.$collectEmail.'</td>';
  22. print '<td>'.$collectDate.'</td>';
  23. print '</tr>';
  24. }
  25. print '</table>';
  26. ?>


Pozdrawiam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

Ostrzeżenie: (0%)
-----


  1. $collectPrice = (int) $allDataInSheet[$i]["D"]; //lub (float) w zależności od potrzeb
Go to the top of the page
+Quote Post
maniek74
post
Post #3





Grupa: Zarejestrowani
Postów: 127
Pomógł: 0
Dołączył: 26.08.2013

Ostrzeżenie: (0%)
-----


Próbowalem zwraca 0 jeszcze zauważyłem problem z datą bo zamiast 2015-02-01 zwraca 02-01-15
Go to the top of the page
+Quote Post
CuteOne
post
Post #4





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

Ostrzeżenie: (0%)
-----


Zrób dumpa z $allDataInSheet, i wrzuć nam tutaj. Problem z datmi, to ustawienia lokalne, w PL używamy dd-mm-YYYY, zrób z tego \DateTime a potem wyświetl format('YYYY-mm-dd') (IMG:style_emoticons/default/wink.gif)

Ten post edytował CuteOne 21.11.2015, 14:54:31
Go to the top of the page
+Quote Post
maniek74
post
Post #5





Grupa: Zarejestrowani
Postów: 127
Pomógł: 0
Dołączył: 26.08.2013

Ostrzeżenie: (0%)
-----


z datą sobie już poradziłem:
$dateEnd = DateTime::createFromFormat('m-d-y', $allDataInSheet[$i]["B"]);
$date = DateTime::createFromFormat('m-d-y', $allDataInSheet[$i]["F"]);

i jest oki nie umiem jedynie sobie pordzić z ceną
próbowwałem
$number = filter_var($allDataInSheet[$i]["D"], FILTER_SANITIZE_NUMBER_INT);

ale zamiast 5 zwraca mi 500.

// Edit
Poradziłem sobie
$number = substr(filter_var($allDataInSheet[$i]["D"], FILTER_SANITIZE_NUMBER_INT), 0, -2);

Pytanie czynie ma lepszej metody aby zwrócił liczby w tej komórce.

Sorki że się spytam ale co to znaczy zrób dumpa z $allDataInSheet ?

Pozdrawiam

Ten post edytował maniek74 21.11.2015, 15:22:08
Go to the top of the page
+Quote Post
CuteOne
post
Post #6





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

Ostrzeżenie: (0%)
-----


wstaw var_dump($allDataInSheet); przed pętlą
Go to the top of the page
+Quote Post
maniek74
post
Post #7





Grupa: Zarejestrowani
Postów: 127
Pomógł: 0
Dołączył: 26.08.2013

Ostrzeżenie: (0%)
-----


zróciło ["D"]=> string(6) "$ 5.00", oczywiście jest tego więcej, ale nie chcę zaśmiecać forum
Go to the top of the page
+Quote Post
CuteOne
post
Post #8





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

Ostrzeżenie: (0%)
-----


Ok już czaje o co chodzi (IMG:style_emoticons/default/wink.gif)
https://degreedocumentation.wordpress.com/2...ll-in-phpexcel/
http://www.cmsws.com/examples/applications...mberFormat.html

W drugim linku masz również przykład zmiany daty
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.09.2025 - 11:43