W
W
wixtransfer2019-07-23 23:51:55
PHP
wixtransfer, 2019-07-23 23:51:55

How to make a function for EXCEL from a PHP script?

How to make a function for EXCEL from a PHP script?
Let's say we have a PHP script:

$str = '921205400655';
list($year, $month, $day) = sscanf($str, "%2d%2d%2d");
if ($year > 30) $year = 1900 + $year;
else $year = 2000 + $year;
$date = sprintf("%04d.%02d.%02d", $year, $month, $day);

echo $date;

I need a PHP script to run when printing the number 921205400655 into an EXCEL cell

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Edward, 2019-07-24
@IS-Builder

I sketched an example in VBA, the code needs to be saved in an Excel template. To start, find and run the "GetDate" macro - a window will pop up for entering the string "921205400655", and by clicking on "OK" the date will be added to the active sheet in the previously selected cell:

Function GetDate(ByVal str As String)
    
    Dim day As String, month As String, year As String
    
    year = Left(str, 2)
    month = Mid(str, 3, 2)
    day = Mid(str, 5, 2)
    
    If year > 30 Then year = year + 1900 Else year = year + 2000
    GetDate = year & "." & month & "." & day
    
End Function

Sub ПолучитьДату()

    Dim result As String
    On Error Resume Next
    
    result = InputBox("Введите число", "Диалоговое окно", "921205400655")
    ActiveCell = GetDate(result)
    
End Sub

D
Dmitry, 2019-07-24
@Compolomus

https://www.php.net/manual/en/language.functions.php
You can read here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question