I am trying out PHPExcel and based on its examples I have written this code:
<?php
require_once "QueryHandler.php";
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */
require_once 'PHPExcel/Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Lajos Arpad")
->setLastModifiedBy("Lajos Arpad")
->setTitle("Import Test Foto")
->setSubject("Import Test Foto")
->setDescription("Import Test Foto")
->setKeywords("office PHPExcel php")
->setCategory("Test result file");
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'cod_comanda')
->setCellValue('B1', 'Foto 1')
->setCellValue('C1', 'Foto 2')
->setCellValue('D1', 'Foto 3')
->setCellValue('E1', 'Foto 4')
->setCellValue("F1", "Foto 5")
->setCellValue("G1", "Foto 6")
->setCellValue("H1", "Foto 7");
$objPHPExcel->getActiveSheet()->setTitle('Import Test Foto');
$toContinue = true;
$limit = 0;
$size = 100;
$pictures = QueryHandler::buildSelect("testtable", array("cod_comanda", "poze"), "Created", $limit, $size);
$index = 2;
$activeSheet = $objPHPExcel->getActiveSheet();
$columns = array("B", "C", "D", "E", "F", "G", "H");
foreach ($pictures as $picture) {
$activeSheet->setCellValue("A".$index, $picture["cod_comanda"]);
if (strlen($picture["poze"])) {
$items = explode(",", $picture["poze"]);
$itemCount = count($items);
for ($innerIndex = 0; $innerIndex < $itemCount; $innerIndex++) {
$activeSheet->setCellValue($columns[$innerIndex].$index, $items[$innerIndex]);
}
}
$index++;
}
// Save Excel 2007 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("export/Import Test Foto.xlsx");
It exports the kind of stuff which can be seen on the first picture. I would like to be able to export it like shown in the second picture, which involves the Foto columns being near several lines in the A column. Notice that the current code only exports textual data, while at the end I need to export the images, but I think I need to figure out how can I modify the relative height of cells compared to the first column's cells first. How can I achieve that?
如果你知道你的图片的分辨率,那么你可以使用PHPExcel_Shared_Drawing
类中的方法将像素转换为单元格尺寸 (),反之亦然
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.