Codeigniter & PHPexcel font size not changing on the first row - codeigniter

When I create a phpexcel document I have set a custom font size.
For some reason the font sizes not changing on the first row.
Question: How to make sure that all rows have the same size including the header row
I have the code in a foreach loop on main controller but miss the first row of cells.
$styleArray = array(
'font' => array(
'size' => 15,
'name' => 'Candara'
));
$objPHPExcel->getActiveSheet()->getStyle('A' . $excelrow . ':D' . $excelrow)->applyFromArray($styleArray);
$objPHPExcel->getActiveSheet()->getStyle($objPHPExcel->getActiveSheet()->calculateWorksheetDimension())->applyFromArray($styleArray2);
Controller
<?php
class Events extends MX_Controller {
public function generate_excel() {
$query = $this->db->get('event');
$excelresults = $query->result_array();
require (APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel.php');
require (APPPATH . 'third_party/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php');
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("");
$objPHPExcel->getProperties()->setLastModifiedBy("");
$objPHPExcel->getProperties()->setSubject("");
$objPHPExcel->getProperties()->setCreator("");
$objPHPExcel->getProperties()->setDescription("");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue("A1", 'Event');
$objPHPExcel->getActiveSheet()->SetCellValue("B1", 'Event Title');
$objPHPExcel->getActiveSheet()->SetCellValue("C1", 'Event Date');
$objPHPExcel->getActiveSheet()->SetCellValue("D1", 'Event Start Time');
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$objPHPExcel->getActiveSheet()->setPrintGridlines(TRUE);
$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
$excelrow = 2;
foreach ($excelresults as $excelresult => $excelvalue) {
$styleArray = array(
'font' => array(
'size' => 15,
'name' => 'Candara'
));
$objPHPExcel->getActiveSheet()->getStyle('A' . $excelrow . ':D' . $excelrow)->applyFromArray($styleArray);
if (!empty($excelvalue['fill_color'])) {
// Set the fill style
$objPHPExcel->getActiveSheet()->getStyle('A' . $excelrow . ':D' . $excelrow)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
// Set the colour for the fill
$objPHPExcel->getActiveSheet()->getStyle('A' . $excelrow . ':D' . $excelrow)->getFill()->getStartColor()->setRGB($excelvalue['fill_color']);
$styleArray1 = array(
'font' => array(
'color' => array('rgb' => $excelvalue['font_color']),
)
);
$objPHPExcel->getActiveSheet()->getStyle('A' . $excelrow . ':D' . $excelrow)->applyFromArray($styleArray1);
$objPHPExcel->getActiveSheet()->getStyle('A' . $excelrow . ':D' . $excelrow)->getAlignment()->setIndent(2);
}
$objPHPExcel->getActiveSheet()->SetCellValue("A" . $excelrow, $excelvalue['event']);
$objPHPExcel->getActiveSheet()->SetCellValue("B" . $excelrow, $excelvalue['event_title']);
$objPHPExcel->getActiveSheet()->SetCellValue("C" . $excelrow, $excelvalue['event_date']);
$objPHPExcel->getActiveSheet()->SetCellValue("D" . $excelrow, $excelvalue['event_start_time']);
$excelrow++;
}
///exit();
$filename = 'Bowling-Events-For-' . date('Y') . '.xlsx';
$objPHPExcel->getProperties()->setTitle("Riwaka Bowling Club Events");
header("Content-Type: application/vnd.ms-excel; charset=utf-8"); # Important
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".$filename."");
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit();
}
}

Are you sure you have attached your correct codes? or are you sure you have tested your attached codes?
I have tested your codes, and its working fine at mine.

Related

Problem with generate multiple file mPDF codeigniter

Hello guys i'm a little bit confuse with my mpdf function in codeigniter to generate multiple file pdf, i tried to research and nothing can solve this is issue,
i have anchor that action to download function, and the idea is to call all function with mpdf generate in it. here is the code :
public function download($id)
{
$this->kehadiranDosen($id);
$this->nilaiSeminar($id);
$this->beritaAcara($id);
}
function beritaAcara($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Berita Acara
$html = $this->load->view('seminar/beritaAcara', $data, true);
$this->load->library('M_pdf');
$mpdf = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf->WriteHTML($html);
$mpdf->Output('BERITA ACARA,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf);
unset($html);
}
function kehadiranDosen($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Kehadiran Dosen
$html2 = $this->load->view('seminar/kehadiranDosen', $data, true);
$this->load->library('M_pdf');
$mpdf2 = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf2->WriteHTML($html2);
$mpdf2->Output('KEHADIRAN DOSEN,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf2);
unset($html2);
}
function nilaiSeminar($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Nilai Seminar
$html3 = $this->load->view('seminar/nilaiSeminar', $data, true);
$this->load->library('M_pdf');
$mpdf3 = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf3->WriteHTML($html3);
$mpdf3->Output('NILAI SEMINAR,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf3);
unset($html3);
}
and when i click it, only kehadiran dosen generated, anyone can solve this? thank you so much before

Laravel file upload s3 Multipart

how do I integrate the multipart upload of s3? I am uploading to s3 and everything works. just I want to refactor the code to S3 multipart upload because the files are too large on the server
// Amazon checking folder
$directory = 'Case/'. $caseDir;
foreach ($request->file('fileslab') as $s3file) {
// Getting request names & extension
$s3patientFirstName = $request->patient_firstname;
$s3patientLastName = $request->patient_lastname;
$s3SavedOrigName = $s3file->getClientOriginalName();
$SendFileToS3 = $s3patientFirstName . '_' . $s3patientLastName . '_' . time() . $s3SavedOrigName;
$contents = file_get_contents($dbfile->getRealPath());
$path = Storage::disk('s3')->put($directory. '/' .$SendFileToS3, $contents);
if (!Storage::disk('s3')->exists($directory)){
Storage::disk('s3')->makeDirectory($directory);
$path = Storage::disk('s3')->put( $directory. '/' . $SendFileToS3, $contents );
}else{
$path = Storage::disk('s3')->put( $directory. '/' .$SendFileToS3, $contents);
}
The Amazon SK Example is below:
require 'vendor/autoload.php';
use Aws\Common\Exception\MultipartUploadException;
use Aws\S3\MultipartUploader;
use Aws\S3\S3Client;
$bucket = '*** Your Bucket Name ***';
$keyname = '*** Your Object Key ***';
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
// Prepare the upload parameters.
$uploader = new MultipartUploader($s3, '/path/to/large/file.zip', [
'bucket' => $bucket,
'key' => $keyname
]);
// Perform the upload.
try {
$result = $uploader->upload();
echo "Upload complete: {$result['ObjectURL']}" . PHP_EOL;
} catch (MultipartUploadException $e) {
echo $e->getMessage() . PHP_EOL;
}
I fixed it.
foreach ($request->file('fileslab') as $s3file) {
$directory = 'Case/'. $caseDir;
$contents = fopen($s3file, 'rb');
$s3patientFirstName = $request->patient_firstname;
$s3patientLastName = $request->patient_lastname;
$s3SavedOrigName = $s3file->getClientOriginalName();
$SendFileToS3 = $s3patientFirstName . '_' . $s3patientLastName .
'_' . time() . $s3SavedOrigName;
$disk = Storage::disk('s3');
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-west-1'
]);
$uploader = new MultipartUploader($s3, $contents, [
'bucket' => $_ENV['AWS_BUCKET'],
'key' => $SendFileToS3,
]);
try {
$result = $uploader->upload();
} catch (MultipartUploadException $e) {
return $e->getMessage();
}
}
```

404 not found twitter api 1.1 codeginter

I've been working on upgrading from v 1 to 1.1 for a few days now. I have 100s of users that can't see their followers in my dashboard.
I followed all the steps by changing /1/ to /1.1/ still not working.
Getting error 404 (Not Found)
Controller:
function twitter_auth()
{
if ( !$this->tweet->logged_in() )
{
die('some how you are not logged in');
}
$tokens = $this->tweet->get_tokens();
$this->tweet->enable_debug(TRUE);
$user = $this->tweet->call('get', 'account/verify_credentials');
var_dump($user);
}
$options = array(
'count' => 10,
'page' => 2,
'include_entities' => 1
);
$timeline = $this->tweet->call('get', 'statuses/home_timeline');
var_dump($timeline);
}
Jobs:
function get_twitter_subscribers($args)
{
$rate = #file_get_contents('http://api.twitter.com/1.1/application/rate_limit_status.json');
$rate = #json_decode($rate);
if($rate->remaining_hits == 0):
$status = 'retask';
else:
$new_data = #file_get_contents('http://api.twitter.com/1.1/users/show.json? screen_name='.$args['account_id'].'&include_entities=true');
$new_data = #json_decode($new_data);
if(isset($new_data->followers_count)){
$insert_args = array(
'account_id' => $args['account_id'],
'metric' => 'subscribers',
'value' => $new_data->followers_count,
'platform' => 'twitter'
);
$insert = $this->CI->metrics_model->insert_metric($insert_args);
if (isset($insert)) { $status = 'complete'; }
}else{
$this->send_error_email("Function: get_twitter_subscribers - new_data->followers_count not set for account id: " . $args['account_id'] . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
}
endif;
if(!isset($status)){
$this->send_error_email("Function: get_twitter_subscribers - status not set." . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json? screen_name='.$args['account_id'].'&include_entities=true');
$status = 'error';
}
return $status;
controllers:
function auth($platform)
{
if($platform == 'facebook'):
echo 'auth facebook';
elseif($platform == 'twitter'):
$this->load->library('tweet');
// current key in php page
$tokens = array(
'oauth_token' => 'xxxxxxxxxxxxx',
'oauth_token_secret' => 'xxxxxxxxxxxx'
);
$this->tweet->set_tokens($tokens);
if ( !$this->tweet->logged_in() ) :
$this->tweet->set_callback(site_url('manage/auth/twitter'));
$this->tweet->login();
else:
echo 'Twitter logged in. Return to manager';
endif;
endif;
}
What am I doing wrong?
This issue has been resolved. I created my own cURL library.
function get_twitter_subscribers($args){
$request = curl_init();
$bearer = "AAAAAAAAAAAAAAAAAAAAAJ%2xxxxxxxxxxxxxxx0000x0x0x0x0";
curl_setopt($request, CURLOPT_SSLVERSION, 1);
curl_setopt($request, CURLOPT_URL, 'https://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
curl_setopt($request, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$bearer));
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$new_data = json_decode($file_get_contents = curl_exec($request));
curl_close($request);
if(isset($new_data->followers_count)){
$insert_args = array(
'account_id' => $args['account_id'],
'metric' => 'subscribers',
'value' => $new_data->followers_count,
'platform' => 'twitter'
);
$insert = $this->CI->metrics_model->insert_metric($insert_args);
if (isset($insert)) { $status = 'complete'; }
}else{
$this->send_error_email("Function: get_twitter_subscribers - new_data->followers_count not set for account id: " . $args['account_id'] . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'https://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
}
if(!isset($status)){
$this->send_error_email("Function: get_twitter_subscribers - status not set." . "\r\n\r\n" . "args: " . http_build_query($args) . "\r\n\r\n" . 'http://api.twitter.com/1.1/users/show.json?screen_name='.$args['account_id'].'&include_entities=true');
$status = 'error';
}
return $status;
}

wordpress display image caption if possible, but only on post page

I'm trying to make a function I can put into my functions.php that controls the images placed on each post's page. I want any image that has a caption to have that caption display under the image with paragraph tags.
Try this:
function img_caption_only_in_posts( $current_html, $attr, $content ) {
global $post;
extract(shortcode_atts(array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $content;
if ($post->post_type=='page')
$caption="";
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
add_filter( 'img_caption_shortcode', 'img_caption_only_in_posts',10,3 );
I borrowed the code from this answer and added the code for checking if the post is page or not.

Uploading an image with Code Igniter?

I'm trying to set a site up so I can upload images using a web form in Code Igniter(CI). I'm not getting any errors but the file is not being saved either. I wanted to know if those that were successful in uploading images could help explain what might be the issue?
View:
<?php
echo form_open_multipart('admin/galleryUpload') . "\n";
echo "<div class='span-8'><span class='text'>Image:</span>" . form_upload('uploadImg') . "</div>";
foreach ($gallery as $picture)
{
$order[] = $picture->order;
}
$order[] = count($order) + 1;
echo "<div class='span-6 last'><span>Image Order #:</span>" . form_dropdown('order', $order) . "</div><div class='span-14'> </div>";
$conf = array('name' => 'alt_text', 'size' => '75');
echo "<div class='span-14 last'><span>Discription:</span>" . form_input($conf) . "<br /></div>";
echo form_hidden('propertyID', "$propertyID");
echo form_submit('upload', 'Upload');
echo form_close();
?>
Controller:
class Admin extends Controller
{
function galleryUpload()
{
if (! $this->session->userdata('is_admin'))
{
redirect('admin/index');
}
else
{
$this->load->model('admin_model');
$this->admin_model->imgUpload();
}
}
}
Model:
class Admin_model extends Model
{
function imgUpload()
{
$id = $this->input->post('propertyID');
$order = $this->input->post('order');
$alt_text = $this->input->post('alt_text');
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
//'upload_path' => '../' . $this->imgPath($id),
'upload_path' => '../img/galleries/temp/',
'max_size' => '5000', // 5MB files max
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->imgPath($id) . '/thumbs',
'maintain_ratio' => TRUE,
'width' => '60'
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
}
From the user guide:
By default the upload routine expects the file to come from a form
field called userfile, and the form must be a multipart type
So you either have to change the name of the form field to userfile:
form_upload('userfile')
or pass the name of your form field to do_upload:
$this->upload->do_upload('uploadImg');

Resources