This topic is locked
[SOLVED]

Export excel format without header line

12/17/2023 6:59:47 AM
PHPRunner General questions
konenamogo author

Hello,

I want to export the contents of my table in excel format without header.

The export is done without problem, only I don't want to display the header line.

How can I do this with phprunner 10.8 enterprise ?

Thanks

img alt

C
cristi 12/17/2023

option1 - "fast and fake it" - you will get an empty row at the top:
Export page -> before process:

Labels::setFieldLabel("table_name", "field_name", "");

option2: since PHPRunner already includes PHPExcel you can create your own custom export attached to an custom button

option 3: use one of fernando's excelent tutorials on custom reports using phpspreadsheet - there is a method Worksheet::removeRow()

I don't know if there is any built in function to ignore headers in export...

konenamogo author 12/18/2023

Hello cristi

Thank you for option 1 which blanks the columns.
see below

img alt

img alt

I would like to delete the first line.

Is there anyone who can help me?

Thanks

C
cristi 12/18/2023

Again, you need to create your own export routine for what you want.
The simplest possible example without any reference from outside since PHPRunner already includes PHPExcel would be:

  1. delete the code that I suggested before - you won't need that anymore.
  2. create a folder "files" in the root of your application on the server and give full "777" permissions on this folder - use any ftp client for that
  3. Insert a custom button in the list page (in the line with the add new, delete, etc buttons) of the table that you want to export.
  4. in the client before insert the following code:

if ($("[name^=selection]:checked").length<1) {
swal("Select at least one record");
return false;
}

This code gives a warning if you don't select anything on the list page to export and stops execution of the server and client after events - the button will work as "export selected" button

  1. in the server part insert the following code:

require_once ('plugins/PHPExcel.php'); //call the library
$objPHPExcel = new PHPExcel(); //instantiate object
$row = 1; //we will not define any headers and start from first line and now we will iterate through the $data array
while($data = $button->getNextSelectedRecord()){

$col = 'A';
foreach($data as $cell) {

$objPHPExcel->getActiveSheet()->setCellValue($col.$row,$cell);

$col++; //increment column
}

$row++; //increment row

}

//write the results and create link for download
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
$path="files/test.xlsx";
$objWriter->save($path);
$result["txt"] = $path;
  1. insert the following code in the client after:

location.href=result["txt"];

Build application, upload, select some records on the list page and push your custom button - it will download an xlsx file without headers in the columns.

This is the simplest example possible with minimum validation, no error check, etc - it can be enhanced so it will download all records or all records on current page without checking them first but this is something that I leave it to you.

You can customize your output even further using the documentation and examples from here

HJB 12/18/2023

Optionally, you can suppress the header row from inside Excel table.

img alt

konenamogo author 12/19/2023

Hello Cristi,

Thank you very much for your help to use custom button.

the solution is found.

Thank you very much