My solution is based on this code here:
https://github.com/mithusree/wp-simple-phpexcel-export/blob/master/wp-simple-phpexcel-export.php
That use in this great library:
http://phpexcel.codeplex.com
My url looks now like this:
mysite.com/wp-admin/edit.php?post_status=all&post_type=lead&m=0&start_date=2016-07-04&end_date=2016-08-03&no_feat_img&companies=check-point&filter_action=Filter&paged=1
On line 109 on the form i cut the code and move it to function.php wrapping this form on function an call it only in wp-admin leads archive page and push the values from url to the form:
add_action( 'admin_notices', 'export_btn' );
function export_btn() {
global $typenow;
if ($typenow == 'lead') {
global $_GET;
$start_date = $_GET[start_date];
$end_date = $_GET[end_date];
$company = $_GET[companies];
?>
<div class="wrap alignright">
<form method='get' action="admin.php?page=spee-dashboard">
<input type="hidden" name='page' value="spee-dashboard"/>
<input type="hidden" name='noheader' value="1"/>
<input type="hidden" name='start_date' value="<?php echo $start_date ?>"/>
<input type="hidden" name='end_date' value="<?php echo $end_date ?>"/>
<input type="hidden" name='company' value="<?php echo $company ?>"/>
<input style="display:none" type="radio" name='format' id="formatCSV" value="csv" checked="checked"/>
<input type="submit" name='export' id="csvExport" value="Export"/>
</form>
</div>
<?php
}
}
In lines 45-50 I edited the mysql query according to my url:
$start_date = $_GET['start_date'];
$end_date = $_GET['end_date'];
$company = $_GET['company'];
$query = "
SELECT * FROM wp_posts p
LEFT OUTER JOIN wp_term_relationships r ON r.object_id = p.ID
LEFT OUTER JOIN wp_term_taxonomy x ON x.term_taxonomy_id = r.term_taxonomy_id
LEFT OUTER JOIN wp_terms t ON t.term_id = x.term_id
WHERE p.post_type = 'lead'
AND p.post_status = 'publish'
AND p.post_date BETWEEN '$start_date' AND '$end_date 23:59:59'
AND t.slug = '$company'
ORDER BY p.post_date DESC
";