PHP cURL输出被截断(PHP cURL output is truncated)
我试图用
cURL
加载一个JS
文件,但结果是被截断了。 我也尝试过file_get_contents
,它仍然会被截断。
但我可以直接从浏览器访问.js
文件。 除了user agent
和referer
之外,request headers
没有任何内容,我将其包含在curl request
。到底是怎么回事? 服务器弄乱了我吗?
I am trying to load a
JS
file withcURL
, but the result is getting truncated. I also triedfile_get_contents
and it still truncates.
But I can access.js
file directly from browser. There isn't anything in therequest headers
exceptuser agent
andreferer
, which I included incurl request
.What is going on? Is the server messing with me?
原文:https://stackoverflow.com/questions/28414416
最满意答案
如果您在“riepilogo”(摘要)表的标题中将月份表示为日期,则可以在公式中引用它们。 通过使用年份编号开始行,您可以轻松地将日期调整为年份中的更改。
例如,这里A2是年份,表示为简单数字。 B2,对于Gennaio(1月),使用
Date(year,month,day)
电子表格功能构建日期,在本例中为2013/1/1。 以下几个月使用EDATE(date,number_of_months)
电子表格功能设置每个后续月份的第一天。现在,调整您的公式以引用该月的日期。
date
操作符需要“yyyy-mm-dd”形式的日期,因此您需要使用TEXT
函数对它们进行格式化。 以下是B3中的公式:=INDEX(query('Scheda Intervento'!$C$2:$K$13;ʺselect sum (K) where (F >= date'ʺ & text(B$2,ʺyyyy-mm-ddʺ) & ʺ' and F < date 'ʺ & text(edate(B$2,1),ʺyyyy-mm-ddʺ) & ʺ' and C = 'ʺ & $A3 &ʺ')ʺ);2;1)
请注意,再次使用
EDATE()
- 这样公式仅依赖于同一列中的值。 不是必需的,但有用,因为它可以在电子表格的最右侧列中使用而无需修改。您可以选择:而不是将年份放入A2中:
- 使用
=year(today())
自动确定=year(today())
,或- 引用电子表格中的另一个单元格。
编辑:Google电子表格日期的本地化问题
上述解决方案有效 - 但不是在意大利,也可能不在其他地区。 对于使用Locale == Italia的用户,
Date()
和EDate()
函数都会导致Google Spreadsheets中出现“解析错误”。为了解决这个问题,下面的自定义函数将给定日期值转换为
QUERY
date
运算符的正确格式的字符串。 有关自定义函数的详细信息,请参阅此博客条目 。 您只需从“工具”菜单中选择“脚本编辑器...”,将此代码块粘贴到编辑器工作区,然后保存。 您可以根据需要为脚本命名。/** * Return the given date as a string formatted as 'yyyy-mm-dd'. */ function date2string(dateval) { var d = new Date(dateval); var dateArr = []; dateArr[0]=d.getFullYear(); dateArr[1]=d.getMonth() + 1; //Months are zero based dateArr[2]=d.getDate(); return dateArr.join('-'); }
有了脚本,您就可以在电子表格中使用新功能
date2string()
。 单元格C3的更新公式为:=INDEX(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')");2;1)
INDEX问题()
这个公式还有另一个问题,它与
INDEX()
函数有关。 该函数需要一个数组作为输入,以及索引来索引数组中的项。 当QUERY()
找到符合查询字符串条件的数据时,这很有效。 在这种情况下,从QUERY('Scheda Intervento'!$C$2:$K$13;"select...
返回QUERY('Scheda Intervento'!$C$2:$K$13;"select...
就像这个2行数组:Sum 54
在这种情况下,
INDEX([["Sum"],[54]];2;1)
得到54
,从数组的第2行第1列中选取。但是如果我们没有匹配的数据,则没有第2行,我们有
#REF
错误。 我们可以通过简单地使用SUM()
来添加数组的数值来避免这种情况。 当没有数字时,这将导致0
- 完美。这是单元格C3的结果公式:
=SUM(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')"))
If you expressed the months as dates in the header of your "riepilogo" (summary) sheet, you could reference them in your formula. By starting the row with a year number, you can easily have the dates adjust to changes in year.
For example, here A2 is the year, expressed as a simple number. B2, for Gennaio (January), builds the date using the
Date(year,month,day)
spreadsheet function, in this case 2013/1/1. The following months use theEDATE(date,number_of_months)
spreadsheet function to set the first day of each subsequent month.Now, adjust your formula to reference the date for the month. The
date
operator expects dates in the form "yyyy-mm-dd", so you need to use theTEXT
function to format them. Here's what the formula in B3 will look like:=INDEX(query('Scheda Intervento'!$C$2:$K$13;ʺselect sum (K) where (F >= date'ʺ & text(B$2,ʺyyyy-mm-ddʺ) & ʺ' and F < date 'ʺ & text(edate(B$2,1),ʺyyyy-mm-ddʺ) & ʺ' and C = 'ʺ & $A3 &ʺ')ʺ);2;1)
Note that
EDATE()
is used again - this is so that the formula relies only on values in the same column. Not a requirement, but helpful because it can be used in the right-most column of your spreadsheet without modification.Instead of placing the year into A2, you could choose to:
- have the year determined automatically using
=year(today())
, or- referencing another cell in your spreadsheet.
Edit: Localization Issues with Google Spreadsheet Dates
The above solution works - but not in Italy, and perhaps not in other locales. Both the
Date()
andEDate()
functions result in "parse errors" in Google Spreadsheets for users with Locale == Italia.To get around that, the custom function below converts a given date value into a string in the proper format for the
date
operator inQUERY
. See this blog entry for more information about custom functions. All you need to do is select "Script Editor..." from the "Tools" menu, paste this block of code into the editor workspace, and save it. You can name the script anything you like./** * Return the given date as a string formatted as 'yyyy-mm-dd'. */ function date2string(dateval) { var d = new Date(dateval); var dateArr = []; dateArr[0]=d.getFullYear(); dateArr[1]=d.getMonth() + 1; //Months are zero based dateArr[2]=d.getDate(); return dateArr.join('-'); }
With the script in place, you have a new function
date2string()
that you can use in your spreadsheet. The updated formula for cell C3 is:=INDEX(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')");2;1)
Problem with INDEX()
There's another problem with this formula, and it's with the
INDEX()
function. That function expects an array as input, along with indices to index an item in the array. That works well whenQUERY()
finds data that meets the criteria in the query string. In that case, the return fromQUERY('Scheda Intervento'!$C$2:$K$13;"select...
is something like this 2-row array:Sum 54
In that case,
INDEX([["Sum"],[54]];2;1)
results in54
, picked from row 2 col 1 of the array.But if we have no matching data, there is no row 2, and we have a
#REF
error. We can avoid that by simply usingSUM()
to add the numeric values of the array. When there is no number, that will result in0
- perfect.Here's the resulting formula for cell C3:
=SUM(query('Scheda Intervento'!$C$2:$K$13;"select sum (K) where (F >= date '" & date2string(C$2) & "' and F < date '" & date2string(D$2) & "' and C = '" & $A3 &"')"))
相关问答
更多-
如果您在“riepilogo”(摘要)表的标题中将月份表示为日期,则可以在公式中引用它们。 通过使用年份编号开始行,您可以轻松地将日期调整为年份中的更改。 例如,这里A2是年份,表示为简单数字。 B2,对于Gennaio(1月),使用Date(year,month,day)电子表格功能构建日期,在本例中为2013/1/1。 以下几个月使用EDATE(date,number_of_months)电子表格功能设置每个后续月份的第一天。 现在,调整您的公式以引用该月的日期。 date操作符需要“yyyy-mm-d ...
-
Google App脚本中的内容如下所示? 这应该在编辑时设置set列的值。 如果您不熟悉GAS,请从“电子表格”菜单中选择“工具” - >“脚本编辑器”。 选择“空白项目”,然后清除其中的内容并替换为此。 保存它(名称不重要)并返回到您的电子表格以尝试编辑并查看结果。 function onEdit() { var dateColNum = 6 //column F var ss1 = SpreadsheetApp.getActiveSpreadsheet(); //set da ...
-
Google电子表格IF公式(Google Spreadsheet IF formula)[2023-07-08]
我不明白你的要求,但你的公式充满了语法错误,所以以下内容至少可以帮助你: =IF(AND(G11="",H11=""),"",IF(AND(G11>=0,H11=""),G11-E$1,IF(AND(G11>=0,H11>0),"paid"))) I don't understand your requirement but your formula is full of syntax errors so the following might at least help: =IF(AND(G11="", ... -
您可以使用= FORECAST(值,data_Y,data_X)公式。 值是您想要预测相应预测的已知值(在您的案例B5中); data_Y是您想要预测未来值(C2:C4)的一系列数据点; data_X是构成预测基础的一系列相应数据点(B2:B4)。 因此,在你的例子中,你将输入C5的公式是=预测(B5,C2:C4,B2:B4),它将返回28.7 您可以通过https://support.google.com/drive/bin/static.py?hl=zh-CN&topic=25273&page=tabl ...
-
如何根据下拉列表在Google电子表格中创建动态公式?(How to create a Dynamic Formula in a Google Spreadsheet based on a dropdown?)[2022-03-26]
你有没有尝试过? IF((COUNTIF( '1' B3:!P3, '1' $ A $ 1))= 0 “”, “XX”) 这样,您只需要更改名为1的工作表的值单元格A1。 对于Dropbox,DATA> VALIDATION - Range'1'!A1 - Criteria,选择LIST WITH ITEMS Have you tried? IF((COUNTIF('1'!B3:P3,'1'!$a$1))=0,"","XX") In this way you only need to change the ... -
如何在Google电子表格中设置包含两个条件的公式?(How can I set a formula with two conditions in Google Spreadsheet?)[2022-02-09]
我认为这个公式在单元格G4中可以正常工作: =QUERY(A4:C,"select C,sum(B),count(B),avg(A),sum(A),count(A),avg(B) where C<>'' group by C") I think this formula works as you want in cell G4: =QUERY(A4:C,"select C,sum(B),count(B),avg(A),sum(A),count(A),avg(B) where C<>'' group by C ... -
所有GoogleSheets - > R软件包都会从GoogleSheets导出csv,因此它只显示值。 最好的方法是将Google Sheet的论坛版复制粘贴到文本页面: 先做一个find-replace(等于) = 到(单引号 - 等于) '= 这将删除公式并将其更改回字符串,然后复制粘贴回Google表格或R. 哈基:) All the GoogleSheets -> R packages export a csv from GoogleSheets, so it will only show ...
-
Chang sum() to sumif() =ARRAYFORMULA(IF(ROW(A:A)=1,"Weekly Sum", IF(WEEKDAY(A:A)=7, sumif(C:C,C:C,B:B),))) Chang sum() to sumif() =ARRAYFORMULA(IF(ROW(A:A)=1,"Weekly Sum", IF(WEEKDAY(A:A)=7, sumif(C:C,C:C,B:B),)))
-
另一种选择是使用单个数组公式,它将自动填充列: =ArrayFormula(IF(LEN(A2:A);COUNTIF(A2:A;A2:A);IFERROR(1/0))) Another option is to use a single array formula that will automatically populate down the column: =ArrayFormula(IF(LEN(A2:A);COUNTIF(A2:A;A2:A);IFERROR(1/0)))
-
您可以更轻松地使用导入范围到新工作表。 然后从该表中扣除它。 它仍将动态更新。 You could make an easier work around is to use the import range to a new sheet. Then sumif it from that sheet. It will still dynamically update.