KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Side by side tables in Excel #1569

Open Matt Jacobson opened this topic on on Aug 15, 2020 - 15 comments

Matt Jacobson commented on Aug 15, 2020

I have a report that requires 2 different tables to be displayed side-by-side in Excel. as shown in the attached screenshot.

I'm able to create the headers for both tables, but the second table is appearing below the first. Is there a way to position where the second table will appear?

Thanks

Matt Jacobson commented on Aug 15, 2020

I forgot to mention, I'm using an older version of Excel package because my server is still on php v5.6

David Winterburn commented on Aug 17, 2020

Hi Matt,

Which version of the Excel package are you using? It could be found in the text file koolreport/excel/composer.json.

If the version >= 6.0.0 you could use excel template export to arrange 2 tables side by side with "cell" property for each table's div:

https://www.koolreport.com/docs/excel/export_to_excel/#excel-export-template-(version-%3E=-6.0.0)

Another option is join the two datastores into one and display it as one table.

Matt Jacobson commented on Aug 17, 2020

Thank you I am using version 6, but when I try using the template, the second table appears below the first, even though its title appears in the expected location. Am I missing something?

This is my excel.view.php file.

<?php
use \koolreport\excel\Table;

$sheet1 = "Pass Sales Report";
?>
<meta charset="UTF-8">
<meta name="description" content="Pass Sales Report">
<meta name="creator" content="PAYCE Technology Parking Management">
<meta name="title" content="Pass Sales Report">

<div sheet-name="<?php echo $sheet1; ?>">
<?php
	$name = $this->params['empInfo']['first'] . " " . $this->params['empInfo']['last'];
	$startD = date('m/d/Y', strtotime($this->params['start']));
	$startT = date('H:i a', strtotime($this->params['start']));
	$endD = date('m/d/Y', strtotime($this->params['end']));
	$endT = date('H:i a', strtotime($this->params['end']));
	if ($startD == $endD) {
		$shift = "$endD &nbsp;&nbsp;&nbsp; $startD - $endD";
	}
	else {
		$shift = "$startD $startT -  $endD $endT";
	}

	$styleTitle = [
		'font' => [
			'name' => 'Calibri', //'Verdana', 'Arial'
			'size' => 25,
			'bold' => TRUE,
			'italic' => FALSE,
			'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
			'strikethrough' => FALSE,
			'superscript' => FALSE,
			'subscript' => FALSE,
			'color' => [
				'rgb' => '000000',
				'argb' => 'FF000000',
			]
		],
		'alignment' => [
			'horizontal' => 'center',//left, right, center, centerContinuous, justify, fill, distributed
			'vertical' => 'top',//top, center, justify, distributed
			'textRotation' => 0,
			'wrapText' => FALSE,
			'shrinkToFit' => FALSE,
			'indent' => 0,
			'readOrder' => 0,
		],
		'borders' => [
			'top' => [
				'borderStyle' => 'none', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
				'color' => [
					'rgb' => '808080',
					'argb' => 'FF808080',
				]
			],
			//left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
		],
	];
	$styleSection = [
		'font' => [
			'name' => 'Calibri', //'Verdana', 'Arial'
			'size' => 20,
			'bold' => TRUE,
			'italic' => FALSE,
			'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
			'strikethrough' => FALSE,
			'superscript' => FALSE,
			'subscript' => FALSE,
			'color' => [
				'rgb' => '000000',
				'argb' => 'FF000000',
			]
		],
		'alignment' => [
			'horizontal' => 'center',//left, right, center, centerContinuous, justify, fill, distributed
			'vertical' => 'top',//top, center, justify, distributed
			'textRotation' => 0,
			'wrapText' => false,
			'shrinkToFit' => false,
			'indent' => 0,
			'readOrder' => 0,
		],
		'borders' => [
			'top' => [
				'borderStyle' => 'none', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
				'color' => [
					'rgb' => '808080',
					'argb' => 'FF808080',
				]
			],
			//left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
		],
	];
	$styleUnderline = [
		'font' => [
			'name' => 'Calibri', //'Verdana', 'Arial'
			'size' => 20,
			'bold' => TRUE,
			'italic' => FALSE,
			'underline' => 'none', //'double', 'doubleAccounting', 'single', 'singleAccounting'
			'strikethrough' => FALSE,
			'superscript' => FALSE,
			'subscript' => FALSE,
			'color' => [
				'rgb' => '000000',
				'argb' => 'FF000000',
			]
		],
		'alignment' => [
			'horizontal' => 'left',//left, right, center, centerContinuous, justify, fill, distributed
			'vertical' => 'top',//top, center, justify, distributed
			'textRotation' => 0,
			'wrapText' => false,
			'shrinkToFit' => false,
			'indent' => 0,
			'readOrder' => 0,
		],
		'borders' => [
			'bottom' => [
				'borderStyle' => 'thin', //dashDot, dashDotDot, dashed, dotted, double, hair, medium, mediumDashDot, mediumDashDotDot, mediumDashed, slantDashDot, thick, thin
				'color' => [
					'rgb' => '000000',
					'argb' => 'FF000000',
				]
			],
			//left, right, bottom, diagonal, allBorders, outline, inside, vertical, horizontal
		],
	];
?>

	<div range="A1:O1" excelstyle='<?php echo json_encode($styleTitle); ?>' >Cashier Shift Report</div>

	<div cell="A4" excelstyle='<?php echo json_encode($styleSection); ?>' >Name:</div>
	<div cell="B4" range="B4:D4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ><?php echo $name; ?></div>
	<div cell="C4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ></div>
	<div cell="D4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ></div>

	<div cell="F4" excelstyle='<?php echo json_encode($styleSection); ?>' >Shift:</div>
	<div cell="G4" range="G4:J4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ><?php echo $shift; ?></div>
	<div cell="H4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ></div>
	<div cell="I4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ></div>
	<div cell="J4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ></div>

	<div cell="L4" excelstyle='<?php echo json_encode($styleSection); ?>' >Bank:</div>
	<div cell="M4" range="M4:N4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ></div>
	<div cell="N4" excelstyle='<?php echo json_encode($styleUnderline); ?>' ></div>


	<div cell="A6" range="A6:E6" excelstyle='<?php echo json_encode($styleSection); ?>' >Cash/Credit Card Payments</div>
	<div cell="A7">
		<?php
		Table::create(array(
			"dataSource" => $this->dataStore('tickets'),
			"showHeader" => true, //default: true
			"showBottomHeader" => false, //default: false
			"showFooter" => true, //default: false
			"map" => [
				"header" => function($colName) {
					$returnNames = array("pay_method"=>"Paid By", "Number"=>"Qty", "Value"=>"Value", "Cash"=>"Cash Collected", "CC"=>"Credit Card",);
					return $returnNames[$colName];
				},
				"bottomHeader" => function($colName) { return $colName; },
				"cell" => function($colName, $value, $row) { return $value; },
				"footer" => function($colName, $footerValue) { return $footerValue; },
			],
			"excelStyle" => [
				"header" => function($colName) {
					return [
						'font' => [
							'italic' => false,
							'bold' => true,
							'color' => [
								'rgb' => '000000',
							]
						],
					];
				},
				"bottomHeader" => function($colName) { return []; },
				"cell" => function($colName, $value, $row) {
					return [
						'font' => [
							'color' => [
								'rgb' => '000000',
							]
						],
					];
				},
				"footer" => function($colName, $footerValue) { return []; },
			]
		));
		?>
	</div>
	<div range="G6:K6" excelstyle='<?php echo json_encode($styleSection); ?>' >Pass Sales</div>
	<div cell="G7">
		<?php
		Table::create(array(
			"dataSource" => $this->dataStore('tickets'),
			"showHeader" => true, //default: true
			"showBottomHeader" => false, //default: false
			"showFooter" => true, //default: false
			"map" => [
				"header" => function($colName) {
					$returnNames = array("pay_method"=>"Paid By", "Number"=>"Qty", "Value"=>"Value", "Cash"=>"Cash Collected", "CC"=>"Credit Card",);
					return $returnNames[$colName];
				},
				"bottomHeader" => function($colName) { return $colName; },
				"cell" => function($colName, $value, $row) { return $value; },
				"footer" => function($colName, $footerValue) { return $footerValue; },
			],
			"excelStyle" => [
				"header" => function($colName) {
					return [
						'font' => [
							'italic' => false,
							'bold' => true,
							'color' => [
								'rgb' => '000000',
							]
						],
					];
				},
				"bottomHeader" => function($colName) { return []; },
				"cell" => function($colName, $value, $row) {
					return [
						'font' => [
							'color' => [
								'rgb' => '000000',
							]
						],
					];
				},
				"footer" => function($colName, $footerValue) { return []; },
			]
		));
		?>
	</div>
</div>

David Winterburn commented on Aug 18, 2020

Hi Matt,

I confirm this is a bug with Excel package v6.0.0. Would it be possible for you to update to the version 7.2.0 which fixed this bug? Thanks!

Matt Jacobson commented on Aug 18, 2020

Unfortunately, I can't because our server is running php 5.6. I will work around this until we upgrade the server.

David Winterburn commented on Aug 19, 2020

Oh I see. Please try Excel package version 7.1.1 or 7.0.0. I think at least one of them supports PHP 5.6 and fixed the bug with arranging cell. Let me know if you have any difficulty with it. Thanks!

Matt Jacobson commented on Aug 19, 2020

Great! How do I download the previous versions? I am up-to-date with my KoolReport Pro v.4.7.1 license.

David Winterburn commented on Aug 20, 2020

Please log into our website, go to your Account section and download a package of previous versions. Then extract the Excel folder to replace your current koolreport/excel one. Let me know if it works for you. Thanks!

Matt Jacobson commented on Aug 20, 2020

I must be missing it, but I've logged in and the only option I see for downloading is to download the current complete package. If I go to the Excel package (https://www.koolreport.com/packages/excel), there is no download option. Can you point me to where I would download the previous version? Thanks

David Winterburn commented on Aug 21, 2020

Hi Matt,

We've sent you the link to download Excel package version 7.1.1 via email. Please let us know if you have any issue with it. Thanks!

Matt Jacobson commented on Aug 21, 2020

David - thank you. Unfortunately it does not seem to work on php 5.6... Do you think 7.0.0 might work?

David Winterburn commented on Aug 24, 2020

Hi Matt,

We've sent you a link for Excel package version 7.1.1. Please let us know if there's still any problem with excel table positioning. Thanks!

Matt Jacobson commented on Aug 24, 2020

David, the 7.1.1 package is not compatible with php 5.6 and I can't upgrade the server because of other dependencies. Do you think the 7.0.0 package works with php 5.6?

David Winterburn commented on Aug 25, 2020

Hi Matt,

I've just checked the requirement for version 7.1.1. Turns out PHPSpreadsheet version is compatible with PHP 5.6 while the culprit is box/spout which is used for big spreasheet export.

We will email you a link to download verison 7.1.1 without box/spout to make it work for you. Thanks!

Matt Jacobson commented on Aug 25, 2020

That sounds great! Thank you.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Export