Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. public function exportPdf() {
  2. $pdf = new FPDF('l','mm','A5');
  3. // membuat halaman baru
  4. $pdf->AddPage();
  5. // setting jenis font yang akan digunakan
  6. $pdf->SetFont('Arial','B',16);
  7. // Memberikan space kebawah agar tidak terlalu rapat
  8. $pdf->Cell(10,7,'',0,1);
  9. $pdf->SetFont('Arial','B',10, true);
  10. $pdf->Cell(85,6,'Nama Item',1,0, true);
  11. $pdf->Cell(40,6,'Harga Item',1,0, true);
  12. $pdf->Cell(65,6,'Deskripsi Item',1,1, true);
  13. $pdf->SetFont('Arial','',10);
  14. $pdf->Cell(10,0,'',0,1);
  15. $height_cell = 6;
  16. $data = $this->product_model->getAll();
  17. for($position = 0; $position < sizeof($data); $position++) {
  18. $product = $data[$position];
  19. $pdf->Cell(85,$height_cell,$product->name,1,0);
  20. $pdf->Cell(40,$height_cell,$product->price,1,0);
  21. $pdf->MultiCell(65,$height_cell,$product->description,1,1);
  22. }
  23. $pdf->Output();
  24. }
  25.  
  26. public function exportXls() {
  27. $data = $this->product_model->getAll();
  28. $spreadsheet = new SpreadSheet();
  29. $sheet = $spreadsheet->getActiveSheet();
  30. $sheet->setCellValue('A1', 'Nama Item');
  31. $sheet->setCellValue('B1', 'Harga Item');
  32. $sheet->setCellValue('C1', 'Deskripsi Item');
  33. $rowCount = 2;
  34. for($position = 0; $position < sizeof($data); $position++) {
  35. $product = $data[$position];
  36. $sheet->setCellValue('A' . $rowCount, $product->name);
  37. $sheet->setCellValue('B' . $rowCount, $product->price);
  38. $sheet->setCellValue('C' . $rowCount, $product->description);
  39. $rowCount++;
  40. }
  41.  
  42. $writer = new Xlsx($spreadsheet);
  43. $filename = 'products.xlsx';
  44.  
  45. $this->output->set_header('Content-Type: application/vnd.ms-excel');
  46. $this->output->set_header("Content-type: application/csv");
  47. $this->output->set_header('Cache-Control: max-age=0');
  48. $writer->save($filename);
  49. //redirect(HTTP_UPLOAD_PATH.$fileName);
  50. $filepath = realpath($filename);
  51. if(file_exists($filepath)) {
  52. // force_download($filename, $filepath);
  53. header('Content-Type: application/vnd.ms-excel');
  54. header('Content-Type: application/csv');
  55. header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
  56. flush();
  57. readfile($filepath);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement