Current exchange rates for Excel - php

Is there a way to import current exchange rates in MS-Excel and keep them updated?
Excel provides a way of calling a URL and import the response into a cell.
There are several prof. services on the internet but I wanted to make sure that no data is logged and the information provided is up-to-date. And it should be free of charge...

Here is a coding-free solution. You can download data in CSV format from Yahoo Finances and import it to Excel as a query.
How to import the data from Yahoo Finances to Excel?
Go to Data → From Web.
Specify the data URL in the field URL, e.g. for the USD to EUR rate:
http://download.finance.yahoo.com/d/quotes.csv?s=USDEUR=X&f=b
Press Load. The new sheet with the required data will be automatically created.
You can hide the header and the style of the cell by unselecting the Header Row and Banded Rows respectively.
That's all, now you have a cell with the desired data. You can referece to the cell like to any other cell in Excel.
Good to know:
You can manually trigger the data refresh by clicking on Data → Refresh All. For automatic update when a workbook is opened: https://support.office.com/en-US/article/Refresh-an-external-data-connection-in-Excel-2016-for-Windows-1524175f-777a-48fc-8fc7-c8514b984440
The URL in the example above contains the &f=b fragment, which means bid. For the detailed Yahoo Finances query data parameters, please see: http://www.financialwisdomforum.org/gummy-stuff/Yahoo-data.htm

Exchange Rates in Excel
Call the URL http://genia.berlin/usd.php to get the actual exchange rate in comparison to US-Dollar. The accuracy is 4 decimal places. An erroneous call returns an empty result, no error message. One parameter given in ISO 4217 notation, e.g.: http://genia.berlin/usd.php?eur
The information is provided without warranty of any kind!
The step-by-step solution including screenshots can be found here: https://eves.genia.berlin/excelquery_e.html
Create a text file. The name can be freely selected. Please make sure that there is a blank line after the URL.
WEB
1
http://genia.berlin/usd.php?["Currency","Enter currency code (ISO 4217)"]
Selection=EntirePage
Formatting=None
PreFormattedTextToColumns=True
ConsecutiveDelimitersAsOne=True
SingleBlockTextImport=False
DisableDateRecognition=False
DisableRedirections=True
Select a stored request
Start Excel and display the following menu: Data / Get External Data / Run Saved Query ...
Type the location and name of the text file (for example, excelquery.txt) from the previous section.
The query is treated as a formula. The assigned cell can be stored in another worksheet.
Selection of external data
In selecting the properties different settings such as automatic updating can be set when opening the Excel document.
Selection of currency as a parameter
There are three possible ways to select the currency as a parameter.
Input by user (Prompt for value using this string)
Specifying a string, for example EUR (Use this value)
Specifying an Excel cell containing a string (Get the value from
this cell)
Input by user
The user is prompted in a dialog to specify the currency. He can also determine whether the input is to be used again in future updates of the same document.
Next time you call the Excel file a warning is issued. The connection for data retrieval must be confirmed by the user.
Here is the code snipped (PHP) on the server side:
<?php
if ($p= substr ($_SERVER['QUERY_STRING'], 0, 3)) {
$pu= strtoupper ($p);
if (preg_match ('/^(?:
BGN|CHF|CZK|DKK|EEK|EUR|GBP|HRK|HUF|ISK|LTL|LVL|MDL|MKD|NOK|PLN|RON|RSD|RUB|SEK|SKK|TRY|UAH|
BDT|BND|CNY|FJD|HKD|IDR|INR|JPY|KRW|LKR|MVR|MYR|NPR|PHP|PKR|SGD|THB|TWD|VND|IQD|
ANG|ARS|BOB|BRL|CAD|CLP|COP|CRC|DOP|HNL|KYD|MXN|NIO|PEN|PYG|SVC|TTD|UYU|VEF|
BWP|DZD|EGP|KES|MAD|MUR|NAD|NGN|PGK|SCR|SLL|TZS|UGX|XOF|ZAR|ZMK|
AED|AUD|BHD|ILS|JOD|KWD|KZT|LBP|NZD|OMR|QAR|SAR|TND|UZS|YER
)$/x', $pu)) {
$pl= strtolower ($p);
if ($x= simplexml_load_file ("http://xxxxx/$pl.xml", null, LIBXML_NOCDATA)) {
if (preg_match ("/(\d+)\.(\d+)\s*$pu/", (string) $x->channel->item->description, $currency)) {
header ('Content-type: text/plain');
header ('Cache-Control: no-cache, must-revalidate');
echo "$currency[1],$currency[2]"; //Excel braucht Komma statt Punkt
exit;
}
}
}
}
header ('HTTP/1.1 204 No Content', true, 204);

Related

Google Drive PHP v3 API File Metadata

Google specifies the metadata in https://developers.google.com/drive/api/v3/reference/files#resource.
If I do
$parameters['fields']="*";
$files = $service->files->listFiles($parameters);
Then I indeed get pretty much all that.
If I just do
$files = $service->files->listFiles($parameters);
i.e. no fields setting I get a subset, but some fields such as createdTime are now blank - and that is one I need.
Google recommend (https://developers.google.com/drive/api/v3/fields-parameter) listing only the fields you need to improve performance, but just about everything I put in fields gets an error "Invalid field selection" (tested in https://developers.google.com/drive/api/v3/reference/about/get?apix_params=%7B%22fields%22%3A%22createdTime%22%7D)
$parameters['fields']="name,parents,mimeType,filesize,createdTime,modifiedTime";
$files = $service->files->listFiles($parameters);
Any clues as to how this works?
Thanks
I believe your goal as follows.
You want to retrieve the file list using name,parents,mimeType,filesize,createdTime,modifiedTime using Drive API v3 with googleapis for php.
Modification points:
There is no fields of filesize. In this case, it's size.
When the field values of name,parents,mimeType,size,createdTime,modifiedTime are set for the method of "Files: list" of Drive API v3, please use files(name,parents,mimeType,size,createdTime,modifiedTime). I think that the reason of your error message of Invalid field selection name is due to this.
When above points are reflected to your script, it becomes as follows.
Modified script:
From:
$parameters['fields']="name,parents,mimeType,filesize,createdTime,modifiedTime";
To:
$parameters['fields']="files(name,parents,mimeType,size,createdTime,modifiedTime)";
References:
Files
Files: list

FileMaker - editing container field using php api and Insert from URL script

I am using php api for adding/editing/viewing a FileMaker database. I am using Filemaker pro 14 and FMS 14 in windows environment.
I am having an issue with adding/editing container fields. Tried the solution given in the following link: https://community.filemaker.com/thread/66165
It was success. The FM script is:
Goto Layout[ The layout that shows your container field ]
New Record/Request
Set Variable[$url ; Value:Get(ScriptParameter)]
Insert from URL [Select, No Dialog ; database_name::ContainerField ; $url]
Exit Script
I don't want to add new record. I have several container fields in the layout so it's not a solution to add a record for each one, and I need to be able to modify older records' container fields.
I tried modifying the script as follows:
Go to Layout ["products" (products)]
Go to Record/Request/Page [Last]
Open Record/Request
Set Variable [$url; Value: Get(ScriptParameter)]
Insert from URL [Select, No Dialog; products::brochure; $url]
Exit Script []
note: (Last) parameter is just experimental.
The php script is as follows:
$runscript = $fm->newPerformScriptCommand('products', 'addContainerData', 'http://link_to_uploded_file');
$result = $runscript->execute();
$result returns success, but the file wasn't inserted in the container field.
Somebody pointed to me that to use "Insert from URL" I have to specify a record ID. So I did the follows:
modified the php script to:
$editCommand = $fm->newEditCommand('products', $recordID, $editedData);
$editCommand->setPreCommandScript('addContainerData', 'http://url_to_my_uploaded_file');
$result = $editCommand->execute();
and the FM script (addContainerData) to
Set Variable [$url; Value: Get(ScriptParameter)]
Insert from URL [Select, No Dialog; products::brochure; $url]
Exit Script []
Also the result was success BUT without inserting the file to the container field.
What am I missing? What to do to be able to add container data to new/old records?
A possible workaround is to use PHP functions to encode the file to base 64 and set that value to a text field in FileMaker. Once there, you can have auto enter or a script to take the base 64 value and decode it to a container field. This works well especially for files with smaller file sizes.

Google Sheets API (PHP) Batch Update

I would like to use the Google Sheets API Batch Update because the calls to update individual cells are extremely slow. The problem is that cells that have no data do not come back as part of a cell feed, so I do not have the necessary edit URL to include those cells in the Batch Update. I have seen reference to a "return-empty" parameter in the Google .NET API which will supposedly return all cells, even empty cells, in a cell feed, but I cannot find any reference to that for the "Protocol" API I am using in PHP (here is an example of a reference to the "return-empty" parameter: Writing to an empty cell in Google Spreadsheets). Does anyone know how to get the cell feed request to return all cells (including empty cells)? Or am I doomed to using the abysmally slow cell update requests?
Quick Hack
If you're using the same API I am, then in googlespraedsheet/api.php at line 152 after
$cellRangeCriteriaQuerystringList = [];
You can add:
$cellRangeCriteriaQuerystringList[] = "return-empty=true";
Better Way
There's a better way, which I have added in my own fork. I created a pull request.
If you work with my fork (or if the pull request is accepted), then you can just add 'returnEmpty' => true to your $cellRange. For example:
$cellList = $spreadsheetAPI->getWorksheetCellList(
$spreadsheetKey,
$worksheetID,
['rowStart' => $rowStart,
'rowEnd' => $rowEnd,
'returnEmpty' => true]);

where magento stores country full name

I have spent hours searching to find where magento stores full county name.
We can get a full list of countries using this code:
$_countries = Mage::getResourceModel('directory/country_collection')
->loadData()
->toOptionArray(false);
This will return an array with country code and name, I investigated the directory module, and found out this call gets data from the table
directory_county
But this table don't have full county name! So where is it stored?
and how is it retrieved using that call?
Thanks in advance.
Ok so to compensate for my wrong answer. Here is how this works:
/lib/Zend/Locale/Data/en.xml - if your store is in english, else another xml in the same directoery is read. Every country is there and its code under the xml tag <territory>
The xml is cached using the Zend_Cache_Core class.
/lib/Zend/Locale.php - function getTranslation invokes the lib/Zend/Cache/Core.php class
to load from the cache.
Example: If you change the name of some country in en.xml and clear the magento cache. You will see the change when u invoke your code again.
Full country names are not stored in database. Magento uses inbuilt Zend functionality.
Check file: lib/Zend/Locale/Data/Translation.php for full list.
Use the Zend_Local translation.
<?php
$code = 'EN';
echo Mage::app()->getLocale()->getTranslation($code, 'Territory', null, 2);
?>
Use the column 'iso2_code' from the table 'directory_country' for your $code.
Magneto only stores country codes in DB, and relies for names on Zend's Locale module to provide translated names, for different locale.
By the toOptionArray method it invokes the Zend_Locale class to get the translated value.
Refer $name = Mage::app()->getLocale()->getCountryTranslation($data['value']);, which gets to Mage_Core_Model_Locale and then to Zend_Locale.
It decides which of the node from the data to read, by the switch case statement in Zend_Locale_Data::getContent() line# 962, 963
Magento caches the names, so if you make any change to XML files, make sure to clean your cache folder to get what you seek.

How to grab data from the script protected site with Excel VBA?

I can't import data table from the site which contain stock data. I did in MS Excel 2007; Data > Get External Data > From Web > Import as usual but there have no return from sites. When I tried to grab data table from the site its shown a small window massage (screenshot), I think the process redirecting to another link; but ultimate result is zero. I think the page is script protected.
Redirecting massage: "Opening: 'http://www.dsebd.org/latest_share_price_all.php"
Please advice me how could I download ( import) data from such site in my Excel Workbook.
The site original link: http://www.dsebd.org/latest_share_price_scroll_l.php [I want to download data from here]
Thanks in Advance for any support.
It's not problem with Excel.
Website is using iframe-->and denying access to request...
Look for site code by pressing F12. Did it ever worked for you before
The following code will place each trading code, LTP, change and % change on a separate line in the active worksheet.
' open IE, navigate to the website of interest and loop until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate "http://www.dsebd.org/latest_share_price_scroll_l.php"
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
If you use F12 to look at the source code, you'll notice that each stock and it's associated data is bracketed by a tagname (in this case "a"). Use this to collect the data for each stock and place the data for all stocks in "Results". Step through "Results" and place each stock on a separate line. Use the replace function to remove a line break so the data appears on 1 line.
Set Results = IE.document.getElementsByTagname("table")(0).getElementsByTagname("a")
x = Results.Length
For y = 0 To x - 1
gg = Results(y).innertext
gg = Replace(gg, Chr(10), "", 1, -1, vbTextCompare)
ActiveCell = gg
ActiveCell.Offset(1,0).Select
Next
Press A1 cell, then data-> http://www.dsebd.org/latest_share_price_scroll_l.php-> click first arrow-> import->ok .....eureka
on cell E1 you will see ur desired thing

Categories