require(APPPATH.'libraries/PHPExcel.php');
$file_name = 'Statement_' . compact_date($from) . '-' . compact_date($to) . '_' . $partner_id . '.xls';
$file = FCPATH . 'uploads' . DIRECTORY_SEPARATOR . $file_name;
$file_url = base_url() . 'uploads/' . $file_name;
//log_g($file);
// Initiate cache
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array( 'memoryCacheSize' => '32MB');
PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$objPHPExcel = new PHPExcel();
//Create $worksheet object to save data
$worksheet = $objPHPExcel->setActiveSheetIndex(0);
//This line is must because of unknwon reason or follow setCellValue won't work
$worksheet->setCellValueByColumnAndRow(0, 1, 'xxx股份有限公司');
$worksheet->mergeCells('A1:I1');
$worksheet->mergeCells('A2:I2');
$worksheet->setCellValue('A2','xxx Inc.');
$title_style = array(
'font' => array(
'bold' => true,
'size' => '22'
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER
)
);
$center_style = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER
)
);
$style_bu = array(
'font' => array(
'bold' => true,
'size' => '18',
'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE
),
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER
)
);
$style_border_t = array(
'borders' => array(
'top' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
$style_border_b = array(
'borders' => array(
'bottom' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
$style_border_d = array(
'font' => array(
'bold' => true
),
'borders' => array(
'bottom' => array(
'style' => PHPExcel_Style_Border::BORDER_DOUBLE
)
)
);
$worksheet->getStyle('A1')->applyFromArray($title_style);
$worksheet->getStyle('A2')->applyFromArray($title_style);
$worksheet->getStyle('A3')->applyFromArray($center_style);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($file);