Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8763067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:41:40+00:00 2026-06-13T15:41:40+00:00

I am new to PHPExcel, first time I’ve used it. I have written this

  • 0

I am new to PHPExcel, first time I’ve used it. I have written this piece of code, but I know that there is a better, faster way. At the moment, when I read the sample spreadsheet (6000 rows, same as the actual spreadsheet) it takes around 2 minutes on localhost.

So, in addition to making the code faster and more streamlined, is there a way to show the actual progress?

I have read through the documentation, but still struggle with this.

Here is the code I’m currently using:

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../local_code/classes/');

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

/**  Define a Read Filter class implementing PHPExcel_Reader_IReadFilter  */ 
class MyReadFilter implements PHPExcel_Reader_IReadFilter 
{ 
    public function readCell($column, $row, $worksheetName = '') { 
        //  read columns A, C, G, H from row 2
        if ($row >= 2) { 
            if (in_array($column,array("A","C","G","H"))) { 
                return true; 
            } 
        } 
        return false; 
    } 
} 

$inputFileName = 'newsheet.xlsx'; // change to uploaded file
$sheetname = 'FULL COMBINED';

$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setLoadSheetsOnly($sheetname);
$objReader->setReadFilter(new MyReadFilter()); 

$objPHPExcel = $objReader->load($inputFileName);

$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true);
foreach($sheetData as $row => $columns) {
    if($row != 1) {
        $value = '';
        foreach($columns as $cell => $val) {
            if($cell == 'A') {
                $val = trim($val);
            }
            if($cell == 'C') {
                if(substr($val,0,1) != 'B') {
                    $val = trim($val);
                    $temp = substr($val,1);
                    if(is_numeric($temp))
                        $val = (int) $temp;
                }
            }
            if($cell == 'G') {
                $val = ($val * 86400) - 2209075200 - 86400;
            }
            if($cell == 'H') {
                $val == floatval($val);
            }
            if($val != "")
                $value[] = $val;
        }
        $values = "('" . implode("','",$value) . "')";
        mysql_query("INSERT INTO projects_timesheet (employee_code,cost_code,date,hours) VALUES " . $values)or die(mysql_error());
    }
}

Question 1

Is there a faster way of doing what I’m doing now? I know about chunking, but it seems I’m doing it wrong as it doesn’t work.

Question 2

Is there a way that I can show the user at what row the script currently is?

Any help will be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:41:41+00:00Added an answer on June 13, 2026 at 3:41 pm

    You have about 6k SQL inserts, try to insert all data by one SQL query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this PHPExcel code: /** Error reporting */ error_reporting(E_ALL); date_default_timezone_set('Europe/London'); /** Include PHPExcel
New to PHP and MySQL, have heard amazing things about this website from Leo
New programmer here, I am trying to understand and break down this code below
The code I currently have: <?php /** PHPExcel */ require_once '../Classes/PHPExcel.php'; /** PHPExcel_IOFactory */
New to Objective-C and iOS development, would love a hand here! I have written
New to linux and trying to escape doing this the hard way. I have
For example I'm using such a code: <?php require_once(D:\server/www/cls/PHPExcel.php); require_once(D:\server/www/cls/PHPExcel/IOFactory.php); $objPHPExcel = new PHPExcel();
NEW EDIT: I have narrowed my problem to this - i have a view
this is my first question in stackoverflow. I am trying to use PHPExcel to
hello i am new to phpexcel, and i was wondering if there is some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.