Currency cells and PHPSpreadsheet: How to read the currency from it? - phpspreadsheet

I have an Excel (XLSX) file with a column containing values in different currencies, e.g. "CAD 4711.00", "NOK 56.78", "CHF 123.45".
Now I try to read data from these cells and I just cannot get the currencies. The best I can do is get the value (4711, 56.78, 123.45) but I also need to figure out which currency the cell is in. How can I do this?
I would be relatively happy if I could just get the formatted value but I do not see a way to do that either.

maybe this helps to get started :
$fileExcel = 'mony.xlsx';
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($fileExcel);
$sheet = $spreadsheet->getActiveSheet();
$lsValue = $sheet->getCell('A1')->getValue();
$lsFormat = $sheet->getStyle('A1')->getNumberFormat()->getFormatCode();
echo $lsValue .':'. $lsFormat .'<HR>';
the result is something like that:
123:#,##0.00\ "€"
123.12:#,##0.00\ [$EUR]
3123:#,##0.00\ [$₽-444]
split the format and inspect it further for your currency

Related

Odoo 10 selection field after save error

I have a selection field and this function for list items in field by dynamically.
def get_years(self):
year_list = []
year = date.today().year+1
lastyear = date.today().year - 20
for i in range(int(lastyear),int(year)):
year_list.append((i, str(i)))
return year_list
this is the field,
year = fields.Selection(get_years, string='Yıl', default=get_current_year, restore="True")
and when I save the form, this field becomes unknown. I found what is the problem but I don't know the solution. Problem is compute function, when i write items like [(1997,1997),(2016,2016),(2017,2017)] it is working but i don't want to write hard code. How can i solve this problem? Thank you.
I found the solution, i don't need to create a new method and can use like;
year = fields.Selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )],string='Year', default=datetime.now().year)
Thanks.

Money gem converting variable of currency code to lower case

I am using the money gem in rails to perform some currency conversion.
I'd like to dynamically set the conversion rate so that I can use it in a script.
currency_code = ":SEK"
conversion_rate = #bank.get_rate(:USD, currency_code).to_f
I get this error:
Money::Currency::UnknownCurrency: Unknown currency ':sek'
Which means it's converting the variable to lower case. If I explicitly put in :SEK I don't have any issues.
I've even tried playing around with this:
cb = "SEK"
conversion_rate = #bank.get_rate(:USD, ":#{cb}").to_f
And
cc = ":SEK"
conversion_rate = #bank.get_rate(:USD, cc.upcase).to_f
However I get the same error.
Any ideas?
bnussey,
I looks like you are passing in your currency as a string instead of a symbol. Try this instead:
currency_code = :SEK
If you need to store a string in the database, Ruby can easily convert it to a symbol.
currency = "SEK"
currency_code = currency.to_sym
=> :SEK

How to use Slickgrid Formatters with MVC

I am working on a first Slickgrid MVC application where the column definition and format is to be stored in a database. I can retrieve the list of columns quite happily and populate them until I ran into the issue with formatting of dates. No problem - for each date (or time) column I can store a formatter name in the database so this can be retrieved as well. I'm using the following code which works ok:
CLOP_ViewColumnsDataContext columnDB = new CLOP_ViewColumnsDataContext();
var results = from u in columnDB.CLOP_VIEW_COLUMNs
select u;
List<dynColumns> newColumns = new List<dynColumns>();
foreach(CLOP_VIEW_COLUMN column in results)
{
newColumns.Add(new dynColumns
{
id = column.COLUMN_NUMBER.ToString(),
name = column.HEADING.Trim(),
field = column.VIEW_FIELD.Trim(),
width = column.WIDTH,
formatter = column.FORMATTER.Trim()
});
}
var gridColumns = new JavaScriptSerializer().Serialize(newColumns);
This is all fine apart from the fomatter. An example of the variable gridColumns is:
[{"id":"1","name":"Date","field":"SCHEDULED_DATE","width":100,"formatter":"Slick.Formatters.Date"},{"id":"2","name":"Carrier","field":"CARRIER","width":50,"formatter":null}]
Which doesn't look too bad however the application the fails with the error Microsoft JScript runtime error: Function expected in the slick.grid.js script
Any help much appreciated - even if there is a better way of doing this!
You are assigning a string to the formatter property, wich is expected to be function.
Try:
window["Slick"]["Formatters"]["Date"];
But i really think you should reconsider doing it this way and instead store your values in the db and define your columns through code.
It will be easier to maintain and is less error prone.
What if you decide to use custom editors and formatters, which you later rename?
Then your code will break or you'll have to rename all entries in the db as well as in code.

HTML Styles in TextView on Mono for Android

I have this situation in my strings.xml.
<string name="mensagem">Olá <b><i> {0} </i></b>,</string>
And in my code I do this:
string msg = String.Format(Resources.GetString(Resource.String.mensagem).ToString(), cliente.Nome.ToUpper());
lblNome.Text = Html.FromHtml(msg).ToString();
But the style tags (b,i) do not work. I need to concatenate words with and without style, so I need to do it in this way. I cant use setTypeface because I need to style individual words and after that, join those words on a sentence.
What is the way ?
Regards,
Marcelo.
You need to change your code to the following.
string msg = String.Format(Resources.GetString(Resource.String.mensagem).ToString(), cliente.Nome.ToUpper());
lblNome.TextFormatted = Html.FromHtml(msg);
Html.FromHtml(string).ToString() is just converting the formatted ISpannable back to a string so you are losing the formatting.

spaces not accepting in ListQuery while querying a list in Google spreadsheet

I am trying to pass a query to a spreadsheet. I have a value say "John cena". How do I pass it in the following line. I am getting an error while doing so
ListQuery query = new ListQuery(listFeedUrl);
query.setSpreadsheetQuery("name = 'John cena' and age > 25");
ListFeed feed = service.query(query, ListFeed.class);
This is the error im getting:
com.google.gdata.util.InvalidEntryException: Bad Request
Parse error: Invalid token encountered
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:662)
at com.google.gdata.client.Service.query(Service.java:1237)
at com.google.gdata.client.Service.query(Service.java:1178)
I'm sorry I don't know the answer completely, but I want to help.
Can you try something like this:
query.setSpreadsheetQuery("name = \"John cena\" and age > 25");
The wiki post # http://code.google.com/apis/spreadsheets/data/3.0/developers_guide.html#SendingStructuredRowQueries says that you have to include data with space in quotations.
I had the same issue, where I had my item column with values that can contain white spaces. By adding double quotes and escaping it in string, I was able to bypass the issue. Also you might want to remove other spaces in the query, apart from the ones between "and", just in case.
String queryString = ""; //should contain feedURL
ListQuery lsListQuery = new ListQuery(new URI(queryString).toURL());
lsListQuery.setSpreadsheetQuery("item=\"Item Name4\" ");
\\This will have the URI encoded
logger.debug(lsListQuery.getQueryUri());
\\This will give you the complete URL
logger.debug(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL());
\\ This should give the feed from which the columns can be read
ListFeed listFeed = service.getFeed(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL(), ListFeed.class);

Resources