I'm using formulas in phpexcel and I have a problem using the countif
Wrong number of arguments for COUNTIFS() function: 4 given, 2 expected
But in the documentation countif is:
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
I have for exemple:
COUNTIFS(C$17:D$46,$B55,C$16:D$45,$B55)
It works when I directly use it on excel, is there a way to catch the error and keep the formula ?
Change the definition of COUNTIFS in the /Classes/PHPExcel/Calculation.php file (around lines 499 to 502).
Currently it reads:
'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'argumentCount' => '2'
),
add a comma after the argument count to make it
'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
'argumentCount' => '2,'
),
Note that the COUNTIFS() function isn't actually implemented, so you can't do a getCalculatedValue() on any cell using the function to get the correct result, but it will then save correctly using the Excel2007 Writer.
COUNTIFS in phpexcel is not yet implemented.
Related
I am trying to figure out how to have aggregate functions in the having clause with CakePHP's query builder.
Background: the intent is to correct all rows in a table with compound primary-keys (page-ID and URL) such that each page-ID-group has only one default video. There are some groups with no, and some groups with more than one "default" row, which needs to be corrected. I've figured out all the steps – except for this detail.
This is the query that I'm trying to build.
SELECT
video_page_id, video_url
FROM page_video
WHERE
video_page_id IN (
SELECT video_page_id
FROM page_video
GROUP BY video_page_id
HAVING SUM(video_is_default) < 1
)
AND video_order = 0
;
And this is what I have built:
// sub-select: all groups that have too few defaults.
// Returns list of page-IDs.
$qb = $this->getQueryBuilder();
$group_selection = $qb
->select(array(
'video_page_id',
))
->from('page_video')
->group('video_page_id')
->having(array(
'1 >' => $qb->func()->sum('video_is_default'),
))
;
// sub-select: compound-primary-key identifiers of all rows where
// `video_is_default` has to be modified from `0` to `1`.
// Returns list of two columns.
$qb = $this->getQueryBuilder();
$modifiable_selection = $qb
->select(array(
'video_page_id',
'video_url',
))
->from('page_video')
->where(array(
'video_page_id IN' => $group_selection,
'video_order = 0',
))
;
But then I get this exception: Column not found: 1054 Unknown column '1' in 'having clause'
The crux is the HAVING clause. I basically don't know how to combine the aggregate function with the attribute-value properties of an array. Usually, in order to craft lower/greater-than clauses, you write it like this: array('col1 >' => $value). But here, I needed to flip the equation because the complex expression can't fit into an array key. And now the 1 gets interpreted as a column name.
Writing it as a concatenated string doesn't seem to help either.
array(
$qb->func()->sum('video_is_default') .' > 1',
)
Exception: PHP Recoverable fatal error: Object of class Cake\Database\Expression\FunctionExpression could not be converted to string
I know I could do …
SELECT (…), SUM(video_is_default) AS default_sum FROM (…) HAVING default_sum < 1 (…)
… but then the sub-select column count doesn't match anymore.
Exception: ERROR 1241 (21000): Operand should contain 1 column(s)
I feel silly for figuring out the solution so soon after asking the question.
The lt method acccepts complex values as the first parameter.
->having(function($exp, $qb) {
$default_sum = $qb->func()->sum('video_is_default');
return $exp->lt($default_sum, 1);
})
I'm have a list with string types and i want to get each one that have maximum of occurence element grouped by another column. I'm trying to do this by linqu expression but it doesn't work. Is it possible to run my code that i show below ?
#test=(from a in #data
group a by new {a.PostCode}
into obj
select obj).ToDictionary(x => x.Key,x=>x.ToList()
.Select(y=>y.Statistic).GroupBy(s => s)
.OrderByDescending(s => s.Count())
.First().Key);
On pay-per-view content nodes (with Drupal MoneySuite module) when I click 'override settings' to input an amount/ type for then node it crashes with this error, though I have tried many versions for the price (eg 1, or 1.00) and dates (eg 2, or 2 days). I have tried using full html, filtered html and plain text in the settings for the field. One answer on Stackexhange hints that this is a ut8 issue but I don't know what that means about how to solve it? Any tips?
The error is:
PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'full_html' for column 'protected_content_message_format' at row 1: INSERT INTO {ms_ppv_price} (vid, nid, price, expiration_string, allow_multiple, protected_content_message, protected_content_message_format, stock, out_of_stock_message) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => 96 [:db_insert_placeholder_1] => 96 [:db_insert_placeholder_2] => 3 [:db_insert_placeholder_3] => 3 days [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => This is a premium film- pay per view only. Get access [ms_ppv:price] to view for [ms_ppv:expirationLength] : [ms_ppv:addToCartLink] [ms_ppv:nodeTeaser] [:db_insert_placeholder_6] => full_html [:db_insert_placeholder_7] => 0 [:db_insert_placeholder_8] => ) in ms_ppv_insert_node_price() (line 774 of /home/cineafzh/public_html/sites/all/modules/moneysuite/ms_ppv/ms_ppv.module).
Looks like the MoneySuite module created the database table incorrectly.
Your error message explains exactly what's going wrong.
Column 'protected_content_message_format' is defined as a datetime column in your database. The value the module attempts to store in it is 'full_html', which is a string. It fails validation and throws an exception.
One workaround would be to edit your database and change the type of column for 'protected_content_message_format' to string, instead of datetime.
I can't guarantee that this won't introduce other undesirable behaviour without looking at the code, but it would definitely resolve this specific error.
I'm using WP-GeSHi in WordPress, and largely I'm very happy with it. There are, however, a few minor scenarios where the color highlighting is too aggressive when a keyword is:
a variable name (denoted by a leading #)
part of another word (e.g. IN in INSERTED)
the combination (part of a variable name, e.g. JOIN and IN in #JOINBING)
inside square brackets (e.g. [status])
Certain keywords are case sensitive, and others are not. The below screenshot sums up the various cases where this goes wrong:
Now, the code in GeSHi.php is pretty verbose, and I am by no means a PHP expert. I'm not afraid to get my hands a little dirty here, but I'm hoping someone else has made corrections to this code and can provide some pointers. I already implemented a workaround to prevent ##ROWCOUNT from being highlighted incorrectly, but this was easy, since ##ROWCOUNT is defined - I just shuffled the arrays around so that it was found before ROWCOUNT.
What I'd like is for GeSHi to completely ignore keywords that aren't whole words (whether they are prefixed by # or immediately surrounded by other letters/numbers). JOIN should be grey, but #JOIN and JOINS should not. I'd also like it to ignore keywords that are inside square brackets (after all, this is how we tell Management Studio to not color highlight it, and it's also how we tell the SQL engine to ignore reserved words, keywords, and invalid identifiers).
You can do this by adding a PARSER_CONTROL control to the end of the array:
'PARSER_CONTROL' => array(
'KEYWORDS' => array(
1 => array( // "1" maps to the main keywords near the start of the array
'DISALLOWED_BEFORE' => '(?![\(\w])',
'DISALLOWED_AFTER' => '(?![\(\w])'
),
5 => array( // "5" maps to the shorter keywords like "IN" that are further down
'DISALLOWED_BEFORE' => '(?![\(\w])',
'DISALLOWED_AFTER' => '(?![\(\w])'
),
)
)
Edit
I've modified your gist to move some of the keywords you added to SYMBOLS back to KEYWORDS (though in their own group and with your custom style), and I updated the PARSER_CONTROL array to match the new keyword array indexes and also to include the default regex that geshi generates. Here is the link:
https://gist.github.com/jamend/07e60bf0b9acdfdeee7a
According to me, what you are doing would take a lot of time. So, I suggest that you install a different plugin:
It has better features and supports more languages and in a better way. So, it would remove all these problems.
EDIT:
Hey, I tried out the same code with latest version and got following result-
EDIT:
So, if you don't want to use another plugin, then I'll tell you about the coding:
First open \wp-content\plugins\wp-geshi-highlight\geshi\geshi\tsql.php in your text editor.
Then, locate the array 'KEYWORDS' or search for it.
Add 6 to the last of it (after 5) and add your custom keywords in it. For example:
5 => array(
'ALL', 'AND', 'ANY', 'BETWEEN', 'CROSS', 'EXISTS', 'IN', 'JOIN', 'LIKE', 'NOT', 'NULL',
'OR', 'OUTER', 'SOME',
),
6 => array( //This line has been added by me
'status' //This line has been added by me
) //This line has been added by me
Note: I have just shown array element 5 (already present) and array element 6 (which I have made).
Then, to make it case-sensitive add below code to the last of 'CASE_SENSITIVE' array:
6 => true
The 'CASE_SENSITIVE' array should look like this:
'CASE_SENSITIVE' => array(
GESHI_COMMENTS => false,
1 => false,
2 => false,
3 => false,
4 => false,
5 => false,
6 => true //This line has been added by me
),
Now, you will have to add styling to the custom keywords. This can be achieved by adding below line to the 'KEYWORDS' element of 'STYLES' array. The starting of 'STYLES' array should look like this:
'STYLES' => array(
'KEYWORDS' => array(
1 => 'color: #0000FF;',
2 => 'color: #FF00FF;',
3 => 'color: #AF0000;',
4 => 'color: #AF0000;',
5 => 'color: #808080;',
6 => 'color: #0000FF;' //This line has been added by me
),
You can solve your problems by above guidelines, but for the part in which the plugin highlights incomplete words, I have found only one solution, that you update your plugin to latest version, because it solves this problem.
I am trying to get my console to print out a summation of all my Locations rate card pricing.
I am trying to complete this task through the console but getting a BigDecimal as the result. Stuck on how to convert this result into a legible string or integer.
Results:
Location.pluck(:rate_card).sum
=> "#<BigDecimal:7f7cf347edd0,'0.3091675E6',18(36)>"
In my Location 'index', to be able to see a dollar amount, I have this setup as:
<%= number_to_currency(location.rate_card, :precision => 2) %>
TIA
Location.each do |e|
puts e.rate_card.to_s.to_f.round(2)
end
You're seeing :rate_card returned as a BigDecimal because that's how it's defined in your database schema. If you were to issue Location.rate_card.class in a Rails console you'll see => BigDecimal.
As was mentioned by #Darby, you can use round. In a console, issue Location.pluck(:rate_card).sum.round(2) and that should show the desired result rounded properly.
Lastly, is there significance to the second part of your results? You show the code you're using to display the view code properly but I don't think it has bearing on your question.
A BigDecimal can be converted to a string like this.
pry(main)> b = BigDecimal.new('78.23')
=> #<BigDecimal:7ff0119cab68,'0.7823E2',18(18)>
[37] pry(main)> b.to_s
=> "0.7823E2"
You don't need to change this to a string first and then a float.
to_f is defined on a BigDecimal object.
[34] pry(main)> b.to_f
=> 78.23
There is also to_i and to_r for integers and rationals respectively.