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

  • Home
  • SEARCH
  • 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 937491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:29:18+00:00 2026-05-15T21:29:18+00:00

I encountered a weird problem setting a custom date format with PHPExcel: I’m writing

  • 0

I encountered a weird problem setting a custom date format with PHPExcel: I’m writing an sql formatted date to a cell and setting it’s format with setFormatCode to ‘d/m/y’. When I open it in Excel 2007, it shows the orignial date format until I double click the cell and then it’s updated to my desired format.
Is there a way to have it refreshing itself without me helping?

$sheet->setCellValueByColumnAndRow($column, $row, '2010-07-16');
$sheet->getStyleByColumnAndRow($column, $row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH);
  • 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-05-15T21:29:19+00:00Added an answer on May 15, 2026 at 9:29 pm

    Unless you’re using PHPExcel’s "Advanced Value Binder", then $sheet->setCellValueByColumnAndRow($column, $row, '2010-07-16'); will be storing the value as a string, not as a date, so the date format you’re setting in the next line is meaningless when applied to a string until you read the resultant file in Excel and force a refresh… Excel itself then fixes your error.

    To ensure that the value is correctly stored in the first place, you need to store it as a date/timestamp/number rather than a string, then set the format mask to ensure that it is treated as a date/timestamp rather than a numeric value.

    Either convert your string to a PHP date using strtotime(), then use PHPExcel’s built in date conversion methods:

    $PHPDateValue = strtotime('2010-07-16');
    $ExcelDateValue = PHPExcel_Shared_Date::PHPToExcel($PHPDateValue);
    $sheet->setCellValueByColumnAndRow($column, $row, $ExcelDateValue); 
    $sheet->getStyleByColumnAndRow($column, $row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH); 
    

    or use the built-in method to convert a date-formatted string to an Excel datetime value directly

    $dateString = '2010-07-16';
    $ExcelDateValue = PHPExcel_Shared_Date::stringToExcel($dateString);
    $sheet->setCellValueByColumnAndRow($column, $row, $ExcelDateValue); 
    $sheet->getStyleByColumnAndRow($column, $row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH); 
    

    or use the Calculation Engines function library’s DATEVALUE() function:

    $dateString = '2010-07-16';
    $ExcelDateValue = PHPExcel_Calculation_Functions::DATEVALUE($dateString);
    $sheet->setCellValueByColumnAndRow($column, $row, $ExcelDateValue); 
    $sheet->getStyleByColumnAndRow($column, $row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH); 
    

    or, option 4, is to use PHPExcel’s "Advanced Value Binder"

    To enable this feature, execute the following static call

    PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
    

    before you instantiate your workbook object, or load it from file

    Then PHPExcel will identify that your value is a date, and handle the conversion to an Excel date/timestamp and format it automatically

    $dateString = '2010-07-16';
    $sheet->setCellValueByColumnAndRow($column, $row, $dateString); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered a weird problem, when i built my last ad-hoc version for
I'm using VS10 and C# and I've encountered a weird problem. I have 2
I encountered a weird problem when trying to write a cross-browser script. Basically my
I have encountered a weird problem: as far as I know, cache can be
A few minutes ago I encountered a weird problem with TopMost. I created a
so I encountered weird problem here. I have an array status=new Array() . Then
I've encountered a weird problem. Everytime I refresh the page, IsPostBack is false. To
I encountered a weird problem just now. The source code is simple and self-evident
I have encountered a weird problem and I can't manage a way to solve
I've encountered a weird problem about positioning bodies in cocos2d/box2d. If I set b2BodyDef

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.