SUMIFS corrupting spreadsheets with PHPSpreadsheet - phpspreadsheet

I am using PHPSpreadsheet and am reading in a spreadsheet with the following (working correctly) formula. I'm using Libre Office to generate my spreadsheet.
=SUMIFS($My_sheet.C:C,$My_sheet.B:B,">"&$'Home page'.$I$12,$My_sheet.B:B,"<"&$'Home page'.$I$13)
For some reason when I remove the offending rows my sheet reads/writes perfectly fine but with them I get corrupted files and it throws unreadable files.
I'm not setting the value - this is already in the spreadsheet I'm reading.

I hope this will help someone. I was looking for PhpOffice\PhpSpreadsheet\Calculation\Statistical\Conditional::SUMIFS() as your call.
For the example given simply wrap each , separated section in quotes and pass them to this function. So the answer would be:
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Conditional as StatCond;
StatCond::SUMIFS('$My_sheet.C:C','$My_sheet.B:B','">"&$\'Home page\'.$I$12','My_sheet.B:B','"<"&$\'Home page\'.$I$13')

Related

Google Sheets - copying CONCATENATE'd text deletes line breaks (comes out as massive block)

Issue with Google Sheets:
I have the CONCATENATE function combining text from several cells into 1 "copypastable" block.
I'm inserting line breaks using CHAR(10).
So it looks fine in Google Sheets itself, and functions perfectly when copied to other Google apps.
But copying it out to other programs (CorelDRAW, Illustrator, or AutoCAD) causes 2 issues:
1.) Adds unwanted double quotes around the entire text.
2.) Destroys all line breaks.
So I have to manually edit every text block, to delete the quotes and add line breaks.
Huge waste of time. How can I make it work properly?
Interestingly enough, it works more properly in Notepad:
Still adds the double quotes, but at least the line breaks work.
But having to copy/paste everything into Notepad, deleting the double-quotes, and then copy/pasting it into Corel/Illustrator/AutoCAD - STILL has the issue with the deleted line breaks.
Depending on the program you're bringing this into, you might want to try using CHAR(13) instead of CHAR(10).
CHAR(13) is a carriage return, while CHAR(10) is a linefeed which will not "show" in google sheets, but when you copy/paste it to a different program depending on the interpretation of those characters it should show up as a separate line.
this is a known issue and one way how to counter it is to copy the content of fx bar (or active cell) instead of the cell itself. you may also want to move down the output to not catch the formula itself. try:
={""; CONCATENATE(...)}
where ... is your formula

=LEN Function in Google Sheet not working corretly

I have a column with lots of rows containing text. I want to highlight cells with over an x-amount of characters, but how? The code I'm using in combination with 'Conditional Formatting' is not working all the time. Sometimes it highlights text over the x amount and sometimes it doesn't, so there is something I'm doing wrong here. The x-amount in the example below is: 300.
you may also need to lock it like:
=LEN(E$1:E$170)>300
Silly me... I found the answer myself. I need to put in the same range in the formula as well. Formula with the range E1:E170 needs to be: =LEN(E1:E170)>300

Parsing Error trying to import Coinbase Pro API into Google Sheets

New to APIs in Google sheets, but I feel like I'm 95% of the way to where I'm trying to go.
I'm trying to pull crypto data into my spreadsheet to do a simple 24 hour price comparison and gauge whether the price has gone up or down, maybe use some conditional code to change the background to green or red. Simple enough. Most of the sites that offer APIs have given me various errors, though, so coinbase pro (and weirdly the deprecated gdax) have been most reliable (although I haven't ruled out that it started breaking because I'm now putting in too many call requests).
Found this as a way to get the current price of ETH, for instance:
=VALUE(SUBSTITUTE(SUBSTITUTE(INDEX(IMPORTDATA("https://api.gdax.com/products/ETH-USD/ticker"),0,2), "price:",""), """", ""))
Works like a charm. So I changed the request to target different info, specifically the 24hr stats listed on the API doc, and the first value in that section, "open" for opening price (this ensures I get the price exactly 24hrs earlier). But I got a weird parsing error using the request, which is here:
=VALUE(SUBSTITUTE(SUBSTITUTE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,1), "open:",""), """", ""))
I've figured out the issue, but not the solution. Google Sheets says I am pulling in text. Because the "open" (opening price) value is the first listed in the JSON code, it is pulling in the code bracket from the nested HTML/JSON code. For instance, it says I can't parse "{open" into a number. And I get the same problem in reverse when I pull the last value listed in the stats section, which is "volume_30day:"
=VALUE(SUBSTITUTE(SUBSTITUTE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,6), "volume_30day:",""), """", ""))
This returns an error saying "volume_30day: #}" can't be parsed, so now it is the closing bracket of the JSON code. So I can't use "open" the first item in the API 24hr stats section, or Volume_30day, which is the sixth item on that list, but items 2-5 work just fine. Seems super weird to me, but I've tested it and it is seems to be what's going on.
There must be something stupid I need to tweak here, but I don't know what it is.
Answer 1:
About =VALUE(SUBSTITUTE(SUBSTITUTE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,1), "open:",""), """", ""))
When I checked =SUBSTITUTE(SUBSTITUTE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,1), "open:",""), """", ""), the value is {open:617. I think that when by this, when VALUE is used for the value, the error occurs.
In order to retrieve the values you expect, I would like to propose to use REGEXREPLACE instead of SUBSTITUTE. The modified formula is as follows.
=VALUE(REGEXREPLACE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,1), "open|""|{|}|:",""))
In this modified formula, open|""|{|}|: is used as the regex. These are replaced with "".
In this case, I think that =VALUE(REGEXEXTRACT(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,1), "\d+")) can be also used. But when I thought about your 2nd question, I thought that above formula might be useful.
Result:
Answer 2:
About =VALUE(SUBSTITUTE(SUBSTITUTE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,6), "volume_30day:",""), """", ""))
When I checked =SUBSTITUTE(SUBSTITUTE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,6), "volume_30day:",""), """", ""), the value is 7101445.64098932}. I think that when by this, when VALUE is used for the value, the error occurs.
In order to retrieve the values you expect, I would like to propose to use REGEXREPLACE instead of SUBSTITUTE. The modified formula is as follows.
=VALUE(REGEXREPLACE(INDEX(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"),0,6), "volume_30day|""|{|}|:",""))
In this modified formula, volume_30day|""|{|}|: is used as the regex. These are replaced with "".
In this regex, it can use by replacing open of open|""|{|}|: to volume_30day at above regex.
Result:
Other pattern 1:
As other pattern using the built-in formula, how about the following modified formulas?
=VALUE(TEXTJOIN("",TRUE,ARRAYFORMULA(IFERROR(VALUE(REGEXREPLACE(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"), "open|""|{|}|:","")),""))))
=VALUE(TEXTJOIN("",TRUE,ARRAYFORMULA(IFERROR(VALUE(REGEXREPLACE(IMPORTDATA("https://api.pro.coinbase.com/products/ETH-USD/stats"), "volume_30day|""|{|}|:","")),""))))
In these formulas, the values can be retrieved by replacing KEY of KEY|""|{|}|: of the regex.
Other pattern 2:
The returned value from https://api.pro.coinbase.com/products/ETH-USD/stats is the JSON value. So in this case, when the custom function created by Google Apps Script can be also used.
The Google Apps Script is as follows.
const SAMPLE = (url, key) => JSON.parse(UrlFetchApp.fetch(url).getContentText())[key] || "no value";
When you use this script, please copy and paste the above script to the script editor of Spreadsheet and save it. And please put the custom function like =SAMPLE("https://api.pro.coinbase.com/products/ETH-USD/stats","open") and =SAMPLE("https://api.gdax.com/products/ETH-USD/ticker","price") to a cell. By this, the value can be retrieved.
References:
REGEXREPLACE
Custom Functions in Google Sheets

Calculation not working after save file phpspreadseet

Strange...I only replace some value in a template xlsx with setCellValue(), I save the file and when I open it in Excel 2013 or Libre Office calc, the calculation are not done.. But it's ok in Excel 365...
I must use calculation without condition in Libre Office to get the good result...
Is there a way to tell phpspreadsheet to force calculation of the whole spreadsheet before saving it ?
Thank's
Guen
You should use the calculation engine.
I found the solution this night... It is beacause I put some null and empty values in some cell and formula MIN() doesn't like this !
It's OK now !

Calling an Excel formula from server-side Ruby web application

My customer has a coded a function that takes 20 boolean values and comes up with an integer result.
They did it with Excel, as a complex formula.
In a new ROR web application, am I better off recoding the whole thing in Ruby, or somehow calling the Excel formula?
I could try to contact a server-side instance of Excel or headless OpenOffice and communicate with it using JACOB or the OpenOffice API?
You can use the spreadsheet gem to read from the Excel file. Try the following code, using a sample file in the same directory called ss.xls which has 1 in A1, 2 in B1, and =A1+B1 in C1.
#gem install spreadsheet
require 'spreadsheet'
book = Spreadsheet.open('ss.xls')
sheet = book.worksheet('Sheet1')
puts sheet.row(0)[2].value
The value call returns the last value for the cell that was calculated by Excel, with the above example it will output 3.0
Edit: Read more about the gem here: http://spreadsheet.rubyforge.org/GUIDE_txt.html
Edit 2: Of course, if you happen to be on Windows you will not need a gem; you just can use the win32ole library as described here: http://www.ruby-doc.org/docs/ProgrammingRuby/html/win32.html
No answers, so for now I will guess that re-implementing the formula in Ruby is less difficult than calling Excel/OpenOffice.
Feel free to provide a better answer!

Resources