Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function exportPdf() {
- $pdf = new FPDF('l','mm','A5');
- // membuat halaman baru
- $pdf->AddPage();
- // setting jenis font yang akan digunakan
- $pdf->SetFont('Arial','B',16);
- // Memberikan space kebawah agar tidak terlalu rapat
- $pdf->Cell(10,7,'',0,1);
- $pdf->SetFont('Arial','B',10, true);
- $pdf->Cell(85,6,'Nama Item',1,0, true);
- $pdf->Cell(40,6,'Harga Item',1,0, true);
- $pdf->Cell(65,6,'Deskripsi Item',1,1, true);
- $pdf->SetFont('Arial','',10);
- $pdf->Cell(10,0,'',0,1);
- $height_cell = 6;
- $data = $this->product_model->getAll();
- for($position = 0; $position < sizeof($data); $position++) {
- $product = $data[$position];
- $pdf->Cell(85,$height_cell,$product->name,1,0);
- $pdf->Cell(40,$height_cell,$product->price,1,0);
- $pdf->MultiCell(65,$height_cell,$product->description,1,1);
- }
- $pdf->Output();
- }
- public function exportXls() {
- $data = $this->product_model->getAll();
- $spreadsheet = new SpreadSheet();
- $sheet = $spreadsheet->getActiveSheet();
- $sheet->setCellValue('A1', 'Nama Item');
- $sheet->setCellValue('B1', 'Harga Item');
- $sheet->setCellValue('C1', 'Deskripsi Item');
- $rowCount = 2;
- for($position = 0; $position < sizeof($data); $position++) {
- $product = $data[$position];
- $sheet->setCellValue('A' . $rowCount, $product->name);
- $sheet->setCellValue('B' . $rowCount, $product->price);
- $sheet->setCellValue('C' . $rowCount, $product->description);
- $rowCount++;
- }
- $writer = new Xlsx($spreadsheet);
- $filename = 'products.xlsx';
- $this->output->set_header('Content-Type: application/vnd.ms-excel');
- $this->output->set_header("Content-type: application/csv");
- $this->output->set_header('Cache-Control: max-age=0');
- $writer->save($filename);
- //redirect(HTTP_UPLOAD_PATH.$fileName);
- $filepath = realpath($filename);
- if(file_exists($filepath)) {
- // force_download($filename, $filepath);
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Type: application/csv');
- header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
- flush();
- readfile($filepath);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement