Tôi đang gặp sự cố khi xuất sang excel. Tôi đang sử dụng codeigniter 4 GroceryCRUD 2. 9. 2, Tuy nhiên, xuất sang pdf và in hoạt động như mong đợi. Chi tiết lỗi
ErrorExceptionTham số bắt buộc $p Giá trị theo sau tham số tùy chọn $Coordinate
- APPPATH\Libraries\GroceryCrudEnterprise\scoumbourdis\phpexcel\Classes\PHPExcel\Autoloader. php. 79 — CodeIgniter\Debug\Exceptions->errorHandler
$severity
8192 $message
Tham số bắt buộc $p Giá trị theo sau tham số tùy chọn $pCoordinate$file
D. \webDevelopment\08-08-2021_New_Build\30-10-2021\ci4\app\Libraries\GroceryCrudEnterprise\scoumbourdis\phpexcel\Classes\PHPExcel\Worksheet. php____31477
- InsiteFX
Người điều hành cấp cao Bài viết. 5.640
Chủ đề. 177
Đã tham gia. Tháng 10 năm 2014
Danh tiếng. 178
Điều này có thể giúp ích cho bạn.
Cách xuất dữ liệu trong Excel bằng Codeigniter 4
Bạn đã thử những gì? What did you Get? What did you Expect?
Đã tham gia cộng đồng CodeIgniter 2009. [ Ứng dụng trò chuyện. insitfx ]
- InsiteFX
Người điều hành cấp cao Bài viết. 5.640
Chủ đề. 177
Đã tham gia. Tháng 10 năm 2014
Danh tiếng. 178
Đây là phiên bản CodeIgniter 3 từ cùng một trang web.
Cách tạo tệp Excel trong Codeigniter bằng PHPExcel
Bạn đã thử những gì? What did you Get? What did you Expect?
Đã tham gia cộng đồng CodeIgniter 2009. [ Ứng dụng trò chuyện. insitfx ]
- demyr
Thành viên cấp cao Bài đăng. 258
Chủ đề. 14
Đã tham gia. Tháng 9 năm 2018
Danh tiếng. 4
Xin chào. Đầu tiên bạn cần lấy tất cả dữ liệu sau đó, nó là một công việc mô hình. Sau đó, bạn cần một foreach.
Tôi sử dụng PhpSpreadSheet để xuất excel, đây có vẻ là cách tốt nhất hiện tại và để tôi chia sẻ một bản sao mã của mình với bạn.
Mã PHP.
function download_invoice[$user_id]{
$spreadsheet = new Spreadsheet[];
$sheet = $spreadsheet->getActiveSheet[];
$date = date['Y-m-d'];
/*set column names*/
$table_columns = array["Company Name", "Address", "Email", "phone", "Invoice Date", "Product Name", "etc", "etc"];
$column = 1;
foreach [$table_columns as $field] {
$sheet->setCellValueByColumnAndRow[$column, 1, $field];
$column++;
}
/*end set column names*/
$invoice_data = $this->InvoiceModel->download_invoice[$user_id]; //get your data from model
$excel_row = 2; //now from row 2
foreach [$invoice_data as $row] {
$sheet->setCellValueByColumnAndRow[1, $excel_row, $row->company_name];
$sheet->setCellValueByColumnAndRow[2, $excel_row, $row->user_address.'-'.$row->user_country];
$sheet->setCellValueByColumnAndRow[3, $excel_row, $row->user_email];
$sheet->setCellValueByColumnAndRow[4, $excel_row, $row->uye_phone];
$sheet->setCellValueByColumnAndRow[5, $excel_row, $row->invoice_date];
$sheet->setCellValueByColumnAndRow[6, $excel_row, $row->product_date];
$sheet->setCellValueByColumnAndRow[7, $excel_row, $row->etc];
$excel_row++;
}
$invoice_name = 'Invoice-'.$user_id.'-'.$date.'.xls';
$object_writer = new Xlsx[$spreadsheet];
header['Content-Type: application/vnd.ms-excel'];
header['Content-Disposition: attachment;filename="'.$invoice_name.'"'];
$object_writer->save['php://output'];
}
- Tajar_Dobro
Thành viên cấp dưới Bài viết. 20
Chủ đề. 10
Đã tham gia. Tháng 5 năm 2021
Danh tiếng. 0
Chà, tôi có truy vấn chính trong DB.
bây giờ tôi chỉ muốn xuất kết quả tìm kiếm. Ngoài ra, PHP excel không hoạt động.
Mã này xuất cho tôi tất cả các giá trị trong khi tôi chỉ cần kết quả từ tìm kiếm
//Xuất ra Excel
public function export_csv[]{
$filename = 'expenses_'.ngày['Y-m-d'].'. csv'; . Truyền tệp"
header["Content-Description: File Transfer"];
tiêu đề["Content-Disposition: attachment; filename=$filename"];
header["Content-Type: application/csv; "];
$expenses_data = $this->expenses_model->export_expenses[];
$file = fopen['php://output', 'w'];
$header = array["Nr.",
"Tiêu đề",
"Date",
"Time",
"User",
"Amount",
];
fputcsv[$file, $header];
foreach [$expenses_data as $key=>$line]{
fputcsv[$file,$line];
}
fclose[$file];
exit;
}
- paulkd
Thành viên Bài viết. 65
Chủ đề. 14
Đã tham gia. Tháng 10 năm 2015
Danh tiếng. 0
[14-06-2021, 12. 35 giờ sáng] Tajar_Dobro đã viết. Chà, tôi có truy vấn chính trong DB.
bây giờ tôi chỉ muốn xuất kết quả tìm kiếm. Ngoài ra, PHP excel không hoạt động.
Mã này xuất cho tôi tất cả các giá trị trong khi tôi chỉ cần kết quả từ tìm kiếm
//Xuất ra Excel
public function export_csv[]{
$filename = 'expenses_'.ngày['Y-m-d'].'. csv'; . Truyền tệp"
header["Content-Description: File Transfer"];
tiêu đề["Content-Disposition: attachment; filename=$filename"];
header["Content-Type: application/csv; "];
$expenses_data = $this->expenses_model->export_expenses[];
$file = fopen['php://output', 'w'];
$header = array["Nr.",
"Tiêu đề",
"Date",
"Time",
"User",
"Amount",
];
fputcsv[$file, $header];
foreach [$expenses_data as $key=>$line]{
fputcsv[$file,$line];
}
fclose[$file];
exit;
}
Bạn có thể cho chúng tôi xem mã tìm kiếm không?
- Tajar_Dobro
Thành viên cấp dưới Bài viết. 20
Chủ đề. 10
Đã tham gia. Tháng 5 năm 2021
Danh tiếng. 0
[16-06-2021, 05. 12 giờ sáng] Tajar_Dobro đã viết.Mã PHP
public function search_expense[$search=NULL]{
$keyword = $this->input->get['search',TRUE];
// pagination settings
$total_rows = $this->db->select['*']->from['expenses']->like["expense",$keyword]->get[]->num_rows[];
$limit = 15;
$config["base_url"] = base_url["expenses/search"];
$config["total_rows"] = $total_rows;
$config["per_page"] = $limit;
$config['next_link'] = '→';
$config['prev_link'] = '←';
$config['full_tag_open'] = "";
$config['full_tag_close'] = "";
$config['num_tag_open'] = '';
$config['num_tag_close'] = '';
$config['cur_tag_open'] = '';
$config['cur_tag_close'] = '';
$config['next_tag_open'] = '';
$config['next_tagl_close'] = '';
$config['prev_tag_open'] = '';
$config['prev_tagl_close'] = '';
$config['first_tag_open'] = "";
$config['first_tagl_close'] = "";
$config['last_tag_open'] = '';
$config['last_tagl_close'] = '';
$config['attributes'] = array['class' => 'page-link'];
$this->pagination->initialize[$config];
$header["links"] = $this->pagination->create_links[];
$start = $this->uri->segment[3];
$header['query'] = $this->db->select["*"]
->from["expenses"]
->like["title",$keyword]
->or_like["user",$keyword]
->or_like["amount",$keyword]
->limit[$limit,$start]
->order_by['id','DESC']
->get[]
->result_array[];
$this->load->view['expenses/index', $header];
}
paulkd[14-06-2021, 12. 35 giờ sáng] Tajar_Dobro đã viết. Chà, tôi có truy vấn chính trong DB.
bây giờ tôi chỉ muốn xuất kết quả tìm kiếm. Ngoài ra, PHP excel không hoạt động.
Mã này xuất cho tôi tất cả các giá trị trong khi tôi chỉ cần kết quả từ tìm kiếm
//Xuất ra Excel
public function export_csv[]{
$filename = 'expenses_'.ngày['Y-m-d'].'. csv'; . Truyền tệp"
header["Content-Description: File Transfer"];
tiêu đề["Content-Disposition: attachment; filename=$filename"];
header["Content-Type: application/csv; "];
$expenses_data = $this->expenses_model->export_expenses[];
$file = fopen['php://output', 'w'];
$header = array["Nr.",
"Tiêu đề",
"Date",
"Time",
"User",
"Amount",
];
fputcsv[$file, $header];
foreach [$expenses_data as $key=>$line]{
fputcsv[$file,$line];
}
fclose[$file];
exit;
}
Can you show us the search code ?