三岁铭

文章 评论 浏览 32

三岁铭 2025-02-20 10:37:30

普通CSS是用于样式的,因此我会编写自定义CSS文件并在那里写悬停CS。

抱歉,我不知道您的方式是否有命令 - 找不到任何东西。

Normaly css is for style, so i would write custom css-file and write hover-css there.

Sorry, i do not know whether there is a command for your way - did not found anything.

动态设置悬停颜色

三岁铭 2025-02-20 07:09:22

DevTools上的功能称为“覆盖范围”

https://developer.chrome.chrome.com/docs/ DevTools/coverage/

使您看到使用了多少个字节,

有多少不是。

您也可以使用它来查看哪些选择器没有用!

蓝线的意思是:使用CSS

红色的手段:不使用CSS

there is functionality on devtools called "coverage"

https://developer.chrome.com/docs/devtools/coverage/

that make you see how many bytes are used,

and how many aren't.

enter image description here

you can also use it to see what selectors aren't useful!

enter image description here

the blue lines means: CSS is used

the red one means: CSS isn't used

用于计算CSS类名称浪费多少数据的扩展/工具

三岁铭 2025-02-20 06:59:25

不重要的漫步:我使用node-postgres(又称NPM软件包pg)具有完全相同的问题。它似乎几乎竭尽所能超越客户。确实可以执行您所描述的内容 - 将常规对象作为“错误”传递,而不是错误或只是投掷。我终于找到了一种可靠的方法来处理此问题,但是它不是很漂亮。


在定义makehttprequest时,立即存储当前stack。稍后,在函数(在您的catch中)中,您可以使用错误记录。

示例使用您的代码:

export const makeHttpRequest = (requestData) => {
  // tracking origin as soon as request begins
  // no callbacks or promises involved yet
  const _stack = new Error().stack;

  return externalLib(requestData)
    .catch(err => {
      // I don't know enough about your code so I'm just adding what I do + what your original did.
      // Play with it if needed
      console.log(`error occurred - origin stack: ${_stack}`);
      throw new Error(JSON.stringify(err));
    });
}

请注意 - 如果您的此异步代码以更多嵌套的异步代码运行(进一步添加到线上 - 回调地狱,请保证炼狱),您将继续遇到相同的问题原因(回调在不同的时间从其他地方发射到另一个堆栈上 - 对堆栈没有意识,将其添加到队列中)。

如果您有大量的嵌套路线和/或连续的中间件,则可能还需要调整堆栈的显示多少。将其放在函数的顶部:

Error.stackTraceLimit = 40;
// or ...
// Error.stackTraceLimit = 3;
// or ...
// Error.stackTraceLimit = Infinity;
// etc.

如果您喜欢- stack-trace-limit = ...,也有一个节点标志。两者都是执行上下文的全局(节点 - 每个进程,chrome-每个窗口/iframe)。更多信息在这里: https://v8.dev/docs/stack-trace-trace-trace-api

unimportant ramble: I have the exact same issue using node-postgres (aka npm package pg). It almost seems to go out of its way to be untraceable beyond the client. Does exactly what you're describing too - passes a regular object as "error" instead of an Error or just throwing. I finally found a reliable way to handle this, but it's not very pretty.


When defining your makeHttpRequest, immediately store the current stack. Later in the function (in your catch) you can then log this with your error.

Example using your code:

export const makeHttpRequest = (requestData) => {
  // tracking origin as soon as request begins
  // no callbacks or promises involved yet
  const _stack = new Error().stack;

  return externalLib(requestData)
    .catch(err => {
      // I don't know enough about your code so I'm just adding what I do + what your original did.
      // Play with it if needed
      console.log(`error occurred - origin stack: ${_stack}`);
      throw new Error(JSON.stringify(err));
    });
}

Please note - if you have this async code running in more nested async code (further down the line - callback hell, promise purgatory) you will continue to run into this problem for the same reason (the callback gets fired from elsewhere, at a different time, on a different stack - no awareness of the stack that added itself to the queue).

If you have a very large number of nested routes and/or consecutive middleware, you probably want to also adjust how much of the stack shows. Put this at the top of the function:

Error.stackTraceLimit = 40;
// or ...
// Error.stackTraceLimit = 3;
// or ...
// Error.stackTraceLimit = Infinity;
// etc.

There's also a Node flag for this if you prefer --stack-trace-limit=.... Both are global for the execution context (Node - per process, Chrome - per window/iframe). More info is here: https://v8.dev/docs/stack-trace-api

如何将堆栈跟踪保持在node.js async函数中

三岁铭 2025-02-19 20:11:17

将数据不合同。为识别连接记录的父母和孩子添加钥匙。将所有内容都放入一个索引中。您的搜索将变得更快,并且不会使用太多CPU。

停止完全使用父子映射。浪费时间和记忆。

Hth。

Denormalize the data. Add keys to the parents and children identifying the connecting record. Put everything into one index. Your search will become way faster and won't use so much CPU.

Stop using parent child mappings completely.Its a waste of time and memory.

HTH.

Elasticsearch查询/结果优化

三岁铭 2025-02-19 15:10:28

如果您想一次查找并替换许多文件中的文本,请按命令+shift+f or control+shift+h 在文件工具中打开sublime text的查找,该工具可以搜索和替换为您的菜单上打开或选择许多文件。
有关详细信息,请单击此处

If you want to find and replace text in a number of files at once, press Command+Shift+F or Control+Shift+H to open Sublime Text's Find in Files tool that can search and replace across as many files as you have open or select from its menu.
For detail please click here

崇高,搜索包含特定单词的整个文件并替换整行代码

三岁铭 2025-02-19 12:55:11

我相信,将链接更改为参数以包含/(slash)在开始时解决您的问题。最终元素应该看起来像这样:< link =“/register”> register</link>

I believe, that changing the Link to parameter to contain / (slash) at the beggining, should solve your problem. Final elem should look like this: <Link to="/register">Register</Link>

React路由器DOM V6,路线不断添加

三岁铭 2025-02-18 21:39:18

这是可以在基础Python中进行的,但是如果您正在进行更大的项目,我强烈建议您使用统计软件包(特别是numpy pandas )来执行此操作。这是因为随着数据集的增长,Numpy和Pandas以比基本Python更有效的方式存储数据。 (请参阅本文以获取更多信息)。

使用pandas

import pandas as pd

fullTime= []
file = open('traffic_input.txt').read().split('\n')
for counter, line in enumerate(file):
        data.append(line_information(line))

#create dataframe
data= pd.DataFrame(fullTime)

#split columns into starting time (sensor 1), ending time (sensor 2), and license plate
data["startingTime"] = data[fullTime].split()[1]
data["endingTime"] = data[fullTime].split()[4]
data["licensePlate"] = data[fullTime.split()[2]

#use elapsed time function to create a new column in the dataframe with elapsed time
data["elapsedTime"] = elapsed_time(data["startingTime"], data["endingTime"])

链接:

  • 有关pandas的一些有用的 href =“ https://pandas.pydata.org/docs/getting_started/intro_tutorials/05_add_columns.html” rel =“ nofollow noreferrer”>入门教程
  • a /book/“ rel =“ nofollow noreferrer”>用于数据分析书籍的Python

如果您有理由与Base Python绝对结婚,请评论,我将进行编辑。但是,对于大多数数据分析任务,Python库使您的生活更轻松(即使他们花了一点时间才能提前学习)。

编辑由于您与基本Python绑定:

我将使用带有格式的列表[[启动时间,结束时间,经过的时间] [汽车2的启动时间,CAR 2的终止时间,经过)汽车2],...],这样

timeArr = []
for i in data:
    thisRow = [];
    startingTime = i[fullTime].split()[1]
    endingTime = i[fullTime].split()[4]
    thisRow.append([startingTime, endingTime, elapsed_time(startingTime, endingTime)

之后,您可以使用使用的时间访问每个车牌的经过的时间,

for i in timeArr:
    print(i[2])

甚至可以将车牌号添加到原始数组的一部分中使用它可以访问它的一种ID。

This is possible in base python, but if you're doing a bigger project, I highly recommend using statistical packages (specifically numpy and pandas) to do this. This is because as your dataset grows, numpy and pandas store data in a much more efficient way than base python. (see this article for more information).

Using pandas:

import pandas as pd

fullTime= []
file = open('traffic_input.txt').read().split('\n')
for counter, line in enumerate(file):
        data.append(line_information(line))

#create dataframe
data= pd.DataFrame(fullTime)

#split columns into starting time (sensor 1), ending time (sensor 2), and license plate
data["startingTime"] = data[fullTime].split()[1]
data["endingTime"] = data[fullTime].split()[4]
data["licensePlate"] = data[fullTime.split()[2]

#use elapsed time function to create a new column in the dataframe with elapsed time
data["elapsedTime"] = elapsed_time(data["startingTime"], data["endingTime"])

Some helpful links about pandas:

If you have a reason to be absolutely married to base python, comment and I'll edit. But for most data analysis tasks, python libraries make your life way easier (even if they take a little bit of time to learn up front).

Edit since you're tied to base python:

I would approach this by using a list of lists with the format [[starting time, endingtime, elapsed time][starting time for car 2, ending time for car 2, elapsed time for car 2], ...], like so

timeArr = []
for i in data:
    thisRow = [];
    startingTime = i[fullTime].split()[1]
    endingTime = i[fullTime].split()[4]
    thisRow.append([startingTime, endingTime, elapsed_time(startingTime, endingTime)

After this, you can access the elapsed time for every license plate by using

for i in timeArr:
    print(i[2])

You could even add the license plate number to part of the original array if you wanted some kind of ID to access it with.

如何比较两个列表并找到它们之间的区别?

三岁铭 2025-02-18 12:05:50

main函数是程序输入点,需要具有特定的函数签名

另外,要从硬编码元素中创建一个数组,您将使用arrayof()。您可以找到有关它的更多信息。

一个工作的例子是:

fun main()
{
    test(arrayOf(12,3,4,5))
}

fun test(args: Array<Int>) {
    //printing out the first element of the array
    println(args[0])
}

The main function is the program entry point and needs to have a specific function signature.

Also, to create an array in Kotlin from hard-coded elements you would use arrayOf(). You can find more about it here.

A working example would be:

fun main()
{
    test(arrayOf(12,3,4,5))
}

fun test(args: Array<Int>) {
    //printing out the first element of the array
    println(args[0])
}

如何将整数数组作为变量并打印出Kotlin中数组的第一个元素?

三岁铭 2025-02-17 19:12:18

您可以从file1导入数据,然后在file2中的行上循环循环,以及在环境中找到匹配列中的匹配项,以team之类的值更新数据。下图:

$data = Import-Csv -Path 'D:\Test\file1.csv'
foreach ($row in (Import-Csv -Path 'D:\Test\file2.csv')) {
    $data | Where-Object { $_.environment -match [regex]::Escape($row.environment) } | 
            ForEach-Object {  $_.team = $row.team }
}

# show on screen
$data | Format-Table -AutoSize

# output to new csv
$data | Export-Csv -Path 'C:\Output\combinedData.csv' -NoTypeInformation

使用[REGEX] :: ESCEAS($ row.Environment)在您的示例数据中不需要,但是在现实生活中,该值可能包含REGEX中具有特殊含义的字符(> -Match使用Regex)。
如果您不想使用正则表达式,则可以使用
来实现同样的表达式
where -object {$ _。环境-like -like“*$($ row.Environment)*”}

在屏幕上输出:

environment  team   
-----------  ----   
storage prod geodata
storage test geodata
master prod  fsd    
master mds   fsd 

You can import the data from file1, then loop over the rows in file2 and where there is a match found in the environment column, update the data with the value of team like below:

$data = Import-Csv -Path 'D:\Test\file1.csv'
foreach ($row in (Import-Csv -Path 'D:\Test\file2.csv')) {
    $data | Where-Object { $_.environment -match [regex]::Escape($row.environment) } | 
            ForEach-Object {  $_.team = $row.team }
}

# show on screen
$data | Format-Table -AutoSize

# output to new csv
$data | Export-Csv -Path 'C:\Output\combinedData.csv' -NoTypeInformation

Using [regex]::Escape($row.environment) is not needed in your example data, but in real life, that value could contain characters that have special meaning in regex (-match uses regex).
If you don't want to use regular expressions, the same can be achieved with
Where-Object { $_.environment -like "*$($row.environment)*" }

Output on screen:

environment  team   
-----------  ----   
storage prod geodata
storage test geodata
master prod  fsd    
master mds   fsd 

如果存在字符

三岁铭 2025-02-17 18:51:27

那以下疯狂的公式呢?

=IF(OR(AD2="N/A",AD2=0),0,AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AE2="N/A",AE2=0),0,AE2*AE$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AF2="N/A",AF2=0),0,AF2*AF$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AG2="N/A",AG2=0),0,AG2*AG$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AH2="N/A",AH2=0),0,AH2*AH$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AI2="N/A",AI2=0),0,AI2*AI$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))

假定为第2行的重量调整为第2行。将其存储为百分比(因此,如果将单元格式设置为一般,则将30%显示为0,3)。

首先构建,

如果合适的话,它首先返回给定单元的基本重量:

重量 *和( value &lt;&gt; 0, value value < /strong>&lt;&gt;“ n/a”)

AD$729*AND(AD2<>0,AD2<>"N/A")

,对行的每个单元重复:

cell 1 + 先前的cell公式的先前公式2 + 细胞3的先前公式 + 细胞4 + 先前的公式对于单元6

(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A"))

用于划分价值和重量的乘积:

value * stroge /先前的公式< /strong>

AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A"))

实际上仅在必要时才会衡平:

if(or( value =“ n/a”, value = 0),0),0 ,以前的公式

IF(OR(AD2="N/A",AD2=0),0,AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))

该行重复:

细胞1 + 先前的公式/strong> + 细胞3 + 的先前公式6

=IF(OR(AD2="N/A",AD2=0),0,AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AE2="N/A",AE2=0),0,AE2*AE$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AF2="N/A",AF2=0),0,AF2*AF$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AG2="N/A",AG2=0),0,AG2*AG$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AH2="N/A",AH2=0),0,AH2*AH$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AI2="N/A",AI2=0),0,AI2*AI$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))

编辑:注释的请求

我们需要动态更改对第729行的(适当单元格中的(适当单元格)。为了实现此目的,我们将使用此公式:

indirect(硬编码列&amp;行(车辆列表的左上方单元格) - 1 +匹配(带有给定车辆的类型车辆清单,0 )

INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))

我们将适应所需的每个单元格:

先前的参考新公式
AD $ 729间接(“ ad” )
AE $ 729间接(“ AE”&amp; row($ ad $ 729)-1+Match(B2,$ b $ 729:$ b $ 734,0))
AF $ 729间接(“ AF”&amp; row($ $ aD $ 729) -1+Match(B2,$ B $ 729:$ B $ 734,0))
AG $ 729间接(“ AG”&amp; row($ ad $ 729)-1+Match(B2,$ B $ 729:$ B $ 734,0) )
ah $ 729间接(“ ah”&amp; row($ ad $ 729)-1+match(b2,$ b $ 729:$ b $ 734,0))
ai $ 729间接(“ ai”&amp; row($ $ $ $ 729) - 1+匹配(B2,$ b $ 729:$ b $ 734,0))

因此,我们将能够相应地替换它们并获得此信息:

=IF(OR(AD2="N/A",AD2=0),0,AD2*INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AE2="N/A",AE2=0),0,AE2*INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AF2="N/A",AF2=0),0,AF2*INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AG2="N/A",AG2=0),0,AG2*INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AH2="N/A",AH2=0),0,AH2*INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AI2="N/A",AI2=0),0,AI2*INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))

第二次编辑,

我将其重新编写为公式,将其调整为新请求。尝试一下:

=IF(OR(AL2="N/A",AL2=0),0,AL2*INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AM2="N/A",AM2=0),0,AM2*INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AN2="N/A",AN2=0),0,AN2*INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AO2="N/A",AO2=0),0,AO2*INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AP2="N/A",AP2=0),0,AP2*INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))

在这里一张表使范围更改的表更容易:

ABCDEFG
重量单板1
重量排729
重量列Al=左(cell(单元格(“地址”,偏移),偏移(c3&amp;“ 1”) ,0,1),2,99),find(“ $”,中间(“ address”,offset(c3&amp;“ 1”),0,1),2,99)) - 1 )=左(中间(单元格(“地址”,偏移)(间接(D3&amp;“ 1”),0,1)),2,99),find(“ $”,mid cell(cell(“地址”,offset))间接(d3&amp;“ 1”),0,1),2,99)) - 1)=左(中间(单元格(“地址”),偏移(间接(E3&amp;“ 1”),0,1)))))))))) ,2,99),find(“ $”,中间(“地址”,偏移(e3&amp;“ 1”),0,1),2,99)) - 1)) - 1)=左(中(Mid)单元格(“地址”,偏移(间接(F3&amp;“ 1”),0,1),2,99),查找(“ $”,mid(cell(“地址”,偏移),偏移(f3&amp;“ 1) ”),0,1),2,99)) - 1)
值表1
值行2
值列Al=左(中间(单元格)(“地址”,偏移(c6&amp;“ 1”),0,1),2,99),find(“ $”,MID(MID)(单元格(“地址”,偏移(间接(C6&amp;“ 1”),0,1),2,99)) - 1)=左(cell(cell(“地址”),偏移(间接偏移(D6&amp;“ 1)) “),0,1),2,99),find(“ $”,cell(“地址”,偏移(D6&amp;“ 1”),0,1),2,99)),2,99)))))))))) -1)=左(中间(单元格(“地址”,偏移),偏移(e6&amp;“ 1”),0,1),2,99),find(“ $”,mid(cell(“地址”,“地址”,”)偏移(间接(E6&amp;“ 1”),0,1),2,99))-1)=左(中间(单元格(“地址”,偏移),偏移(f6&amp;“ 1”),0,1 ),2,99),find(“ $”,中间(“地址”,偏移(间接(F6&amp;“ 1”),0,1),2,99)) - 1))-1))-1)
案例表案例
2
列列B
重量指数地址
1表1 (“&amp; $ c $ 1&amp;“!”!&amp; $ c $ 3&amp;“ $” C $ 9&amp; $ C $8 &amp; row(“&amp; $ c $ 1&amp;“!”!&amp; $ c $ 3&amp;“ $”&amp; $ c $ 2&amp;“) - 1+match(“&amp; $ c $ 7&amp;“!”! &amp; $ c $9 “”“”&amp; row(“&amp; $ c $ 1&amp;“!”&amp; $ c $ 3&amp; amp;“ $”&amp; $ c $ 2&amp;“) - 1+match(“&amp; $ c $ 7&amp; amp; “!” f3&amp;“”&amp; row(“&amp; $ c $ 1&amp;“!”! !$ 7 “&amp; g3&amp;“”&amp; row(“&amp; $ c $ 1&amp;“!”&amp; $ c $ 3&amp; “ $”&amp; $ c $ 2&amp;“) - 1+匹配(“&amp; $ c $ 7&amp;“!”&amp; $ c $ 9&amp; $ c $ 8&c $ 8&amp;“,”,“”&amp; $ c $ 10&amp; amp;“,0)) “
= $ c $ 4&amp;“!” &amp; c6&amp; $ c $ 5= $ c $ 4&amp;“!” &amp; d6&c $ 5= $ c $ 4&amp;“!” &amp; e6&amp; $ c $ 5= $ c $ 4&amp;“!” &amp; f6&amp; $ c $ 5= $ c $ 4&amp;“!” &amp; g6&c $ 5
重量 *和(value&lt;&gt; 0,value&lt;&lt;&lt;&gt;&gt;&lt; 0,“&amp; c14&amp;”&lt;&gt;“” n/a“”)“= d13&amp;” &lt;&gt;“” n/a“”)“= e13&amp;” a“”)“= f13&amp;“*”&amp;“ and(”&amp; f14&amp;&lt;&gt;&gt; 0,“”&amp; f14&amp;&amp;&lt; “*”&amp;“ and(”&amp; g14&amp;“&lt;&gt;&gt; 0,”&amp; g14&amp;“&lt
; +细胞3+单元4+先前的公式的先前公式,用于细胞5公式2= c16&amp; amp; amp; d16&amp; amp;“+”+”&amp; e16&amp; amp;“+”+“ f16&amp; f16&amp; amp;
价值*重量/先前公式3= C14&amp;“*”&amp; c13&amp;“/”/“&amp;”(“&amp; $ c17&c17&amp;“)”= d14&amp;“*”*“*”&amp; d13&amp; d13&amp; amp; amp; (“&amp; $ c17&amp;“)”= e14&amp;“*”&amp; e13&amp;“/”/“&amp;”(“&amp; amp; $ c17&amp;“)”= f14&amp;“*” ;“(”(“&amp; $ c17&amp;“)”= g14&amp;“*”&amp; g13&amp;“/”/“&amp;”(“&amp; $ c17&amp; amp;”)'if
(or(value =“ n/a”,“”,“”,“”,“”,“”,值= 0),0,以前的公式)公式4=“ if(或(”&amp; c14&amp;“ =”“ n/a”,“,”&amp; c14&amp;“ = 0),0),0,&amp; amp; c18&amp; “)”=“ if(或(”&amp; d14&amp;“ =”“ n/a”,“”,“”&amp; d14&amp;“ = 0),0,”,“”&amp; d18&amp;“)”= ”&amp; e14&amp;“ =”“ n/a”,“”,“”&amp; e14&amp;“ = 0),0,“”&amp; e18&amp;“)”=“ if(或(或(或(或”&(“”&(&amp; f14 n/a“”,“”,&amp; f14&amp;“ = 0),0,”,“”&amp; f18&amp;“)”=“ if(or(或(”&(“&amp; g14&amp;” =“ n/a”“ n/a”,“”,“&amp; g14&amp;“ = 0),0,“”,&amp; g18&amp;“)”
单元1 +单元格2 +先前公式的先前公式2 + cell 3 + cell 4 +先前的公式4 +先前的公式5个单元格5= c19&amp ;“+”&amp; d19&amp;“+”&amp; e19&amp;“+”&amp; f19&amp;“+”+“ g19

Crazy Formulas都需要疯狂的编辑方式。

What about the following crazy formula?

=IF(OR(AD2="N/A",AD2=0),0,AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AE2="N/A",AE2=0),0,AE2*AE$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AF2="N/A",AF2=0),0,AF2*AF$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AG2="N/A",AG2=0),0,AG2*AG$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AH2="N/A",AH2=0),0,AH2*AH$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AI2="N/A",AI2=0),0,AI2*AI$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))

This one is tuned for the row 2. Weight are assumed to be stored as percentage (therefore if the cell format is set as general, 30% will be shown as 0,3).

The building up

First it return the base weight for the given cell if it's appropriate:

weight * AND(value<>0, value<>"N/A")

AD$729*AND(AD2<>0,AD2<>"N/A")

which is repeated for each cell of the row:

previous formula for cell 1 + previous formula for cell 2 + previous formula for cell 3 + previous formula for cell 4 + previous formula for cell 5 + previous formula for cell 6

(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A"))

which is used to divide the product of value and weight:

value * weight / previous formula

AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A"))

which is actually calulated only if necessary:

IF(OR(value = "N/A", value = 0), 0, previous formula)

IF(OR(AD2="N/A",AD2=0),0,AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))

which is repeated for each cell of the row:

previous formula for cell 1 + previous formula for cell 2 + previous formula for cell 3 + previous formula for cell 4 + previous formula for cell 5 + previous formula for cell 6

=IF(OR(AD2="N/A",AD2=0),0,AD2*AD$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AE2="N/A",AE2=0),0,AE2*AE$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AF2="N/A",AF2=0),0,AF2*AF$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AG2="N/A",AG2=0),0,AG2*AG$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AH2="N/A",AH2=0),0,AH2*AH$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AI2="N/A",AI2=0),0,AI2*AI$729/(AD$729*AND(AD2<>0,AD2<>"N/A")+AE$729*AND(AE2<>0,AE2<>"N/A")+AF$729*AND(AF2<>0,AF2<>"N/A")+AG$729*AND(AG2<>0,AG2<>"N/A")+AH$729*AND(AH2<>0,AH2<>"N/A")+AI$729*AND(AI2<>0,AI2<>"N/A")))

EDIT: comment's request

We need to dynamically change the reference to the (appropriate cell in the) row 729. To achieve this, we will use this formula:

INDIRECT( hardcoded column & ROW( top-left cell of the vehicle list ) - 1 + MATCH( cell with the kind of the given vehicle , vehicle list , 0 ))

INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))

which we will adapt for each cell needed:

Previous referenceNew formula
AD$729INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))
AE$729INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))
AF$729INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))
AG$729INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))
AH$729INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))
AI$729INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))

so we will be able to substitute them accordingly and obtain this:

=IF(OR(AD2="N/A",AD2=0),0,AD2*INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AE2="N/A",AE2=0),0,AE2*INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AF2="N/A",AF2=0),0,AF2*INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AG2="N/A",AG2=0),0,AG2*INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AH2="N/A",AH2=0),0,AH2*INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))+IF(OR(AI2="N/A",AI2=0),0,AI2*INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))/(INDIRECT("AD"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AD2<>0,AD2<>"N/A")+INDIRECT("AE"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AE2<>0,AE2<>"N/A")+INDIRECT("AF"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AF2<>0,AF2<>"N/A")+INDIRECT("AG"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AG2<>0,AG2<>"N/A")+INDIRECT("AH"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AH2<>0,AH2<>"N/A")+INDIRECT("AI"&ROW($AD$729)-1+MATCH(B2,$B$729:$B$734,0))*AND(AI2<>0,AI2<>"N/A")))

Second edit

I've re-written the formula tuning it for the new request. Try it:

=IF(OR(AL2="N/A",AL2=0),0,AL2*INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AM2="N/A",AM2=0),0,AM2*INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AN2="N/A",AN2=0),0,AN2*INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AO2="N/A",AO2=0),0,AO2*INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))+IF(OR(AP2="N/A",AP2=0),0,AP2*INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))/(INDIRECT("AL"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AL2<>0,AL2<>"N/A")+INDIRECT("AM"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AM2<>0,AM2<>"N/A")+INDIRECT("AN"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AN2<>0,AN2<>"N/A")+INDIRECT("AO"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AO2<>0,AO2<>"N/A")+INDIRECT("AP"&ROW(AL$729)-1+MATCH(B2,$AK$729:$AK$734,0))*AND(AP2<>0,AP2<>"N/A")))

Here a table to make the range change easier:

ABCDEFG
weight sheetSheet1
weight row729
weight columnAL=LEFT(MID(CELL("address",OFFSET(INDIRECT(C3&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(C3&"1"),0,1)),2,99))-1)=LEFT(MID(CELL("address",OFFSET(INDIRECT(D3&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(D3&"1"),0,1)),2,99))-1)=LEFT(MID(CELL("address",OFFSET(INDIRECT(E3&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(E3&"1"),0,1)),2,99))-1)=LEFT(MID(CELL("address",OFFSET(INDIRECT(F3&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(F3&"1"),0,1)),2,99))-1)
value sheetSheet1
value row2
value columnAL=LEFT(MID(CELL("address",OFFSET(INDIRECT(C6&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(C6&"1"),0,1)),2,99))-1)=LEFT(MID(CELL("address",OFFSET(INDIRECT(D6&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(D6&"1"),0,1)),2,99))-1)=LEFT(MID(CELL("address",OFFSET(INDIRECT(E6&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(E6&"1"),0,1)),2,99))-1)=LEFT(MID(CELL("address",OFFSET(INDIRECT(F6&"1"),0,1)),2,99),FIND("$",MID(CELL("address",OFFSET(INDIRECT(F6&"1"),0,1)),2,99))-1)
case sheetSheet1
case row2
case columnB
weight index addressSheet1!$AK$729:$AK$734
weight="INDIRECT(""" & $C$1 &"!" & C3 & """&ROW(" & $C$1 &"!" & $C$3 & "$" & $C$2 &")-1+MATCH(" & $C$7 &"!" & $C$9 & $C$8 &"," & $C$10 &",0))"="INDIRECT(""" & $C$1 &"!" & D3 & """&ROW(" & $C$1 &"!" & $C$3 & "$" & $C$2 &")-1+MATCH(" & $C$7 &"!" & $C$9 & $C$8 &"," & $C$10 &",0))"="INDIRECT(""" & $C$1 &"!" & E3 & """&ROW(" & $C$1 &"!" & $C$3 & "$" & $C$2 &")-1+MATCH(" & $C$7 &"!" & $C$9 & $C$8 &"," & $C$10 &",0))"="INDIRECT(""" & $C$1 &"!" & F3 & """&ROW(" & $C$1 &"!" & $C$3 & "$" & $C$2 &")-1+MATCH(" & $C$7 &"!" & $C$9 & $C$8 &"," & $C$10 &",0))"="INDIRECT(""" & $C$1 &"!" & G3 & """&ROW(" & $C$1 &"!" & $C$3 & "$" & $C$2 &")-1+MATCH(" & $C$7 &"!" & $C$9 & $C$8 &"," & $C$10 &",0))"
value=$C$4&"!" &C6&$C$5=$C$4&"!" &D6&$C$5=$C$4&"!" &E6&$C$5=$C$4&"!" &F6&$C$5=$C$4&"!" &G6&$C$5
weight * AND(value<>0, value<>"N/A")formula 1=C13&"*"&"AND("&C14&"<>0,"&C14&"<>""N/A"")"=D13&"*"&"AND("&D14&"<>0,"&D14&"<>""N/A"")"=E13&"*"&"AND("&E14&"<>0,"&E14&"<>""N/A"")"=F13&"*"&"AND("&F14&"<>0,"&F14&"<>""N/A"")"=G13&"*"&"AND("&G14&"<>0,"&G14&"<>""N/A"")"
previous formula for cell 1 + previous formula for cell 2 + previous formula for cell 3 + previous formula for cell 4 + previous formula for cell 5formula 2=C16&"+"&D16&"+"&E16&"+"&F16&"+"&G16
value * weight / previous formulaformula 3=C14&"*"&C13&"/"&"("&$C17&")"=D14&"*"&D13&"/"&"("&$C17&")"=E14&"*"&E13&"/"&"("&$C17&")"=F14&"*"&F13&"/"&"("&$C17&")"=G14&"*"&G13&"/"&"("&$C17&")"
IF(OR(value = "N/A", value = 0), 0, previous formula)formula 4="IF(OR("&C14&"=""N/A"","&C14&"=0),0,"&C18&")"="IF(OR("&D14&"=""N/A"","&D14&"=0),0,"&D18&")"="IF(OR("&E14&"=""N/A"","&E14&"=0),0,"&E18&")"="IF(OR("&F14&"=""N/A"","&F14&"=0),0,"&F18&")"="IF(OR("&G14&"=""N/A"","&G14&"=0),0,"&G18&")"
previous formula for cell 1 + previous formula for cell 2 + previous formula for cell 3 + previous formula for cell 4 + previous formula for cell 5formula 5=C19&"+"&D19&"+"&E19&"+"&F19&"+"&G19

Crazy formulas calls for crazy way to edit.

我需要在Excel中创建一个有条件的公式,包括相对和非相关条件在内

三岁铭 2025-02-17 09:58:31

NICE DCV Web客户端在Web浏览器中运行时,需要在浏览器中执行NICE DCV SDK。它不能在nodejs中执行。

您想实现什么?

The NICE DCV SDK needs to be executed in a browser as the NICE DCV web client runs in the web browser. It cannot be executed in nodejs.

What are you trying to achieve?

运行AWS NICE DCV使用nodejs释放Web Client SDK

三岁铭 2025-02-16 14:54:35

您可以将全日期存储为单独的密钥(称为日期),并使用预定义的数组为每个月的名称设置单独的函数。这是您要使用的代码:

const monthName = ["January", "February", "March", "April", "May", "June",     
"July", "August", "September", "October", "November", "December"]; // Array representing each month

var chartItems = [
    {
        "date": "2022-06-01T00:00:00+02:00",
        "month": null,
        "total": 4
    },
    {
        "date": "2022-08-01T00:00:00+02:00",
        "month": null,
        "total": 1
    }
];

// Run through each item in the array
function setMonths(arr) {
    arr.forEach(item => {
        const date = new Date(item.date); // Convert date string to Date object
        const monthIndex = date.getMonth(); // Get index of month from the Date
        const month = monthName[monthIndex]; // Convert index into text representing the month

        item.month = month; // Set the month key in the object to the new month
    });
}

setMonths(chartItems); // Call function to set months in the array

作为替代方案,您还可以为阵列中的每个对象制作一个方法,但是每次要获得一个月时,您都需要运行此方法。这是为此的代码:

const monthName = ["January", "February", "March", "April", "May", "June",     
"July", "August", "September", "October", "November", "December"];

var chartItems = [
    {
        "date": "2022-06-01T00:00:00+02:00",
        "month": function() { return monthName[new Date(this.date).getMonth()]; },
        "total": 4
    },
    {
        "date": "2022-08-01T00:00:00+02:00",
        "month": function() { return monthName[new Date(this.date).getMonth()]; },
        "total": 1
    }
];

您会这样得到:

chartItems[0].month(); // "[0]", meaning the first item in the array

You could store the full date as a seperate key (called date), and set the month in a seperate function using a predefined array for the names of each month. Here is the code you would use:

const monthName = ["January", "February", "March", "April", "May", "June",     
"July", "August", "September", "October", "November", "December"]; // Array representing each month

var chartItems = [
    {
        "date": "2022-06-01T00:00:00+02:00",
        "month": null,
        "total": 4
    },
    {
        "date": "2022-08-01T00:00:00+02:00",
        "month": null,
        "total": 1
    }
];

// Run through each item in the array
function setMonths(arr) {
    arr.forEach(item => {
        const date = new Date(item.date); // Convert date string to Date object
        const monthIndex = date.getMonth(); // Get index of month from the Date
        const month = monthName[monthIndex]; // Convert index into text representing the month

        item.month = month; // Set the month key in the object to the new month
    });
}

setMonths(chartItems); // Call function to set months in the array

As an alternative, you could also make a method for each object in the array that gets the month, but you would need to run this everytime you want to get the month. Here is the code for that:

const monthName = ["January", "February", "March", "April", "May", "June",     
"July", "August", "September", "October", "November", "December"];

var chartItems = [
    {
        "date": "2022-06-01T00:00:00+02:00",
        "month": function() { return monthName[new Date(this.date).getMonth()]; },
        "total": 4
    },
    {
        "date": "2022-08-01T00:00:00+02:00",
        "month": function() { return monthName[new Date(this.date).getMonth()]; },
        "total": 1
    }
];

And you would get it like this:

chartItems[0].month(); // "[0]", meaning the first item in the array

更改JS中特定值的对象标签

三岁铭 2025-02-16 07:59:44

这里的大多数答案是关于如何根据其先前的值更新状态的,但我不明白这与问题有关

USESTATE SET方法没有立即反映更改


反应18

USESTATE是异步的:

当触发某个代码,发生某个代码,发生的事件发生时,代码开始运行,当它finshes finshes时,React会检查是否有状态更新,以及它是否存在 usestate挂钩的值已更新,这导致了一个新渲染,其中新值可用。

const [example,setExemple] = useState("")
//...
<button
  onClick={() => {
    const newValue = "new";
    setExample(newValue);
    console.log(example); // output "" and this is normal, because the component didn't rerenderd yet so the new value is not availabe yet
  }}
>
  Update state
</button>

假设我们有一个方案如果我们的状态取决于另一个状态,例如,我们要根据示例的新值每次更新时进行API调用,然后将响应中的数据存储在另一个状态<代码> anotherexample 。
为了实现,我们有两种方法:

1。使用newValue的值:

<button
  onClick={async () => {
    const newValue = "new";
    const response = await axios.get(`http://127.0.0.1:5000/${newValue}`);
    setExample(newValue);
    setAnotherExample(response.data);
  }}
>
  test
</button>

因为您知道示例将接收此值,因此可以直接基于它创建逻辑。

2。触发a useffect 每次运行 示例在其依赖项数组中:

<button
  onClick={() => {
    const newValue = "new";
    setExample(newValue);
  }}
>
  test
</button>
useEffect(() => {
 async function test(){
  const response = await axios.get(`http://127.0.0.1:5000/${example}`);
  setAnotherExample(response.data);
 } 
 test();
}, [example])

因此,当示例使用事件函数更新时渲染一旦完成,useffect将运行,因为示例的值与上次渲染和由于它是一种新的不同渲染,因此在此处可用示例 USESTATE HONK的新值。

注意: 使用效果挂钩在第一个安装座期间都会运行。

哪种方法更好?

  • 虽然第一种方法将使所有工作都在一个渲染中(一种更好的方法)“ react组多个状态更新到单个重新渲染中以获得更好的性能”,第二种方法将做到这一点在两个渲染中,第一个是示例更新时,第二个是anotherexample从内部更新 useffeft useeffect

Most of the answers here are about how to update a state based on its previous value, but I don't understand how that relates to the question

The useState set method is not reflecting a change immediately


React 18

useState is asynchronous:

When an event that triggers a certain code, occurs, the code starts running, and when it finshes, react will check if there was a state update and if it is the case, only then the value of the useState hook is updated and this leads to a new render in which the new value is availabe.

const [example,setExemple] = useState("")
//...
<button
  onClick={() => {
    const newValue = "new";
    setExample(newValue);
    console.log(example); // output "" and this is normal, because the component didn't rerenderd yet so the new value is not availabe yet
  }}
>
  Update state
</button>

Supposing we have a scenario where we have a state which depends on another state, for example we want to make an API call based on the new value of example every time it is updated and then store the data from response in another state anotherExample.
to achieve so we have two ways:

1. use the value of newValue:

<button
  onClick={async () => {
    const newValue = "new";
    const response = await axios.get(`http://127.0.0.1:5000/${newValue}`);
    setExample(newValue);
    setAnotherExample(response.data);
  }}
>
  test
</button>

since you know that example will receive this value, you can create your logic based on it directly.

2. trigger a useEffect to run each time example is updated by including example in its dependency array:

<button
  onClick={() => {
    const newValue = "new";
    setExample(newValue);
  }}
>
  test
</button>
useEffect(() => {
 async function test(){
  const response = await axios.get(`http://127.0.0.1:5000/${example}`);
  setAnotherExample(response.data);
 } 
 test();
}, [example])

so when example is updated with the event function the component rerenders, we are now in a new different render that once finished, useEffect will run because the value of example is different from what is was during the last render, and since it is a new different render, the new value of example useState hook is available here.

Note: the useEffect hook will run anyway during the first mount.

Which approach better?

  • while the first method will make all the work in one render ???? (a better approach) "React groups multiple state updates into a single re-render for better performance" the second method will do it in two renders, the first when example is updated and the second when anotherExample is updated from inside useEffect ????

  • since the component only rerenders when the new value of a useState hook is different from the old one, so when newValue is equal to example the component will not rerender so the useEffect will not run and anotherExample will not be updated ???? (a better approach), however in the first method the API is called anyway and we don't want to do that if there is no need also if this happens anotherExample will be updated (anotherExample will receive the same data it already contains because it is the same REQUEST since newValue is equal to example) but if the response in an object or an array then, Object.is method (that the useState hook utilizezs), cannot detect if the new value is equal to the previous one, therefore, the component will rerender ????

Conclusion:

As it is mentioned above, each one has its advantage, so it depends on the use case.

the second method is more recommended, however the first can be more performant in some cases, for example when you are sure the code will only run when newValue gets a new value using onChange, or maybe when you want to use some other local variables that you will no longer have access to from inside useEffect

USESTATE SET方法不是立即反映更改

三岁铭 2025-02-15 09:27:35

编辑:您可以掩盖LAT,并长时间到真实位置。

import MapKit
import SwiftUI

struct ContentView: View {

let geocoder = CLGeocoder()
@State private var result = "result of lat & long"
@State private var address = ""
@State private var lat = 0.0
@State private var long = 0.0
@State private var country = "country name"
@State private var state = "state name"
@State private var zip = "zip code"

var body: some View {
VStack {
    
    //Enter "Florida"
    TextField("Enter Location", text: $address)
    
    //Press button
    Button {
        geocoder.geocodeAddressString(address, completionHandler: {(placemarks, error) -> Void in
            if((error) != nil){
                print("Error", error ?? "")
            }
            if let placemark = placemarks?.first {
                let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
                print("Lat: \(coordinates.latitude) -- Long: \(coordinates.longitude)")
                //added code
                result = "Lat: \(coordinates.latitude) -- Long: \(coordinates.longitude)"
                lat = coordinates.latitude
                long = coordinates.longitude
            }
        })
    } label: {
        Text("Press For Location")
    }
    
    //result will show "Lat: 29.5449611 -- Long: -81.7627933"
    Text("\(result)")
    
    Spacer()
    
    //Press this button after you pressed the location button
    //it will convert the lat & long to real location
    Button {
        reverseLatLong(lat: lat, long: long)
    } label: {
        Text("Reverse to address")
    }
    Text("\(country)") //United States
    Text("\(state)") //FL
    Text("\(zip)") //32177
}

}
func reverseLatLong(lat:Double, long:Double){
    
    let geoCoder = CLGeocoder()
    let location = CLLocation(latitude: lat, longitude: long)
    
    geoCoder.reverseGeocodeLocation(location, completionHandler: { (sub, e) -> Void in
        
        var l: CLPlacemark!
        l = sub?[0]
        
        if let lcountry = l.country {
            country = lcountry
        }

        if let lstate = l.administrativeArea {
            state = lstate
        }
        
        if let lzip = l.postalCode {
            zip = lzip
        }
    })
}
}

Edited: you can covert the lat and long value to real location.

import MapKit
import SwiftUI

struct ContentView: View {

let geocoder = CLGeocoder()
@State private var result = "result of lat & long"
@State private var address = ""
@State private var lat = 0.0
@State private var long = 0.0
@State private var country = "country name"
@State private var state = "state name"
@State private var zip = "zip code"

var body: some View {
VStack {
    
    //Enter "Florida"
    TextField("Enter Location", text: $address)
    
    //Press button
    Button {
        geocoder.geocodeAddressString(address, completionHandler: {(placemarks, error) -> Void in
            if((error) != nil){
                print("Error", error ?? "")
            }
            if let placemark = placemarks?.first {
                let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
                print("Lat: \(coordinates.latitude) -- Long: \(coordinates.longitude)")
                //added code
                result = "Lat: \(coordinates.latitude) -- Long: \(coordinates.longitude)"
                lat = coordinates.latitude
                long = coordinates.longitude
            }
        })
    } label: {
        Text("Press For Location")
    }
    
    //result will show "Lat: 29.5449611 -- Long: -81.7627933"
    Text("\(result)")
    
    Spacer()
    
    //Press this button after you pressed the location button
    //it will convert the lat & long to real location
    Button {
        reverseLatLong(lat: lat, long: long)
    } label: {
        Text("Reverse to address")
    }
    Text("\(country)") //United States
    Text("\(state)") //FL
    Text("\(zip)") //32177
}

}
func reverseLatLong(lat:Double, long:Double){
    
    let geoCoder = CLGeocoder()
    let location = CLLocation(latitude: lat, longitude: long)
    
    geoCoder.reverseGeocodeLocation(location, completionHandler: { (sub, e) -> Void in
        
        var l: CLPlacemark!
        l = sub?[0]
        
        if let lcountry = l.country {
            country = lcountry
        }

        if let lstate = l.administrativeArea {
            state = lstate
        }
        
        if let lzip = l.postalCode {
            zip = lzip
        }
    })
}
}

如何在程序中的其他地方获取可变输出|斯威夫特

三岁铭 2025-02-14 22:24:24

这是我的尝试。它将消息放在同一文件中的另一张纸上。最后的电子表格看起来像这样:

”产品表“

“消息表”

import os
import pandas as pd

old_data_filename = r"old_data.xlsx"
new_data_filename = r"new_data.xlsx"
new_spreadsheet_filename = r"updated_products.xlsx"

# Load spreadsheets into a dataframe and set their indexes to "Product number"
old_data_df = pd.read_excel(old_data_filename).set_index("Product number")
new_data_df = pd.read_excel(new_data_filename).set_index("Product number")

# Determine which products are new/missing, and store the corresponding 
# messages in a list, which will be written to its own spreadsheet at the end
old_data_products = set(old_data_df.index)
new_data_products = set(new_data_df.index)

new_products = new_data_products - old_data_products
missing_products = old_data_products - new_data_products

messages = [f"Product ID {product} is missing in new data file" for product in missing_products]
messages.extend(f"Product ID {product} is newly added" for product in new_products)
messages = [f"Message {i}) {message}" for i, message in enumerate(messages, start=1)]

# Keep the original product names
new_data_df.update(old_data_df["Name"])

# Old price is the same as new price unless the product is in old_data_df, in which 
# case it is old_data_df["Current price"]
new_data_df["Old price"] = new_data_df["New price"]
new_data_df["Old price"].update(old_data_df["Current price"])

# Rename the columns
new_data_df.reset_index(inplace=True)
new_data_df.rename(columns={"Product number": "Product ID", 
                            "Name": "Name of product"}, inplace=True)

# Remove all other columns except the ones we want
new_data_df = new_data_df[["Product ID", 
                           "Name of product", 
                           "New price", "Old price"]]

# Write the new products and messages to separate sheets in the same file
with pd.ExcelWriter(new_spreadsheet_filename) as writer:
    new_data_df.to_excel(writer, "Products", index=False)
    pd.DataFrame({"Messages": messages}).to_excel(writer, "Messages", index=False)

# Launch the new spreadsheet
os.startfile(new_spreadsheet_filename)

编辑:与实际电子表格一起使用的代码:

import os
import pandas as pd

old_data_filename = r"old_data.xlsx"
new_data_filename = r"new_data.xlsx"
new_spreadsheet_filename = r"updated_products.xlsx"

# Load spreadsheets into a dataframe and set their indexes to "Product number"
old_data_df = pd.read_excel(old_data_filename).set_index("Product ID")
new_data_df = pd.read_excel(new_data_filename).set_index("Product ID")

# Remove duplicated indexes for both the dataframes, keeping only the first occurrence
old_data_df = old_data_df[~old_data_df.index.duplicated()]
new_data_df = new_data_df[~new_data_df.index.duplicated()]

# Determine which products are new/missing, and store the corresponding 
# messages in a list, which will be written to its own spreadsheet at the end
old_data_products = set(old_data_df.index)
new_data_products = set(new_data_df.index)

new_products = new_data_products - old_data_products
missing_products = old_data_products - new_data_products

messages = [f"Product ID {product} is missing in new data file" for product in missing_products]
messages.extend(f"Product ID {product} is newly added" for product in new_products)
messages = [f"Message {i}) {message}" for i, message in enumerate(messages, start=1)]

# Keep the original product names
new_data_df.update(old_data_df["Name"])

# Old price is the same as new price unless the product is in old_data_df, in which 
# case it is old_data_df["Current price"]
new_data_df["Old price"] = new_data_df["New price"]
new_data_df["Old price"].update(old_data_df["Current price"])

# Rename the "Name" column to "Name of product"
new_data_df.rename(columns={"Name": "Name of product"}, inplace=True)

# Remove all other columns except the ones we want
new_data_df.reset_index(inplace=True)
new_data_df = new_data_df[["Product ID", 
                            "Name of product", 
                            "New price", "Old price"]]

# Write the new products and messages to separate sheets in the same file
with pd.ExcelWriter(new_spreadsheet_filename) as writer:
    new_data_df.to_excel(writer, "Products", index=False)
    pd.DataFrame({"Messages": messages}).to_excel(writer, "Messages", index=False)

# Launch the new spreadsheet
os.startfile(new_spreadsheet_filename)

This is my attempt. It puts the messages in another sheet in the same file. The final spreadsheet looks like this:

Products sheet

Messages sheet

import os
import pandas as pd

old_data_filename = r"old_data.xlsx"
new_data_filename = r"new_data.xlsx"
new_spreadsheet_filename = r"updated_products.xlsx"

# Load spreadsheets into a dataframe and set their indexes to "Product number"
old_data_df = pd.read_excel(old_data_filename).set_index("Product number")
new_data_df = pd.read_excel(new_data_filename).set_index("Product number")

# Determine which products are new/missing, and store the corresponding 
# messages in a list, which will be written to its own spreadsheet at the end
old_data_products = set(old_data_df.index)
new_data_products = set(new_data_df.index)

new_products = new_data_products - old_data_products
missing_products = old_data_products - new_data_products

messages = [f"Product ID {product} is missing in new data file" for product in missing_products]
messages.extend(f"Product ID {product} is newly added" for product in new_products)
messages = [f"Message {i}) {message}" for i, message in enumerate(messages, start=1)]

# Keep the original product names
new_data_df.update(old_data_df["Name"])

# Old price is the same as new price unless the product is in old_data_df, in which 
# case it is old_data_df["Current price"]
new_data_df["Old price"] = new_data_df["New price"]
new_data_df["Old price"].update(old_data_df["Current price"])

# Rename the columns
new_data_df.reset_index(inplace=True)
new_data_df.rename(columns={"Product number": "Product ID", 
                            "Name": "Name of product"}, inplace=True)

# Remove all other columns except the ones we want
new_data_df = new_data_df[["Product ID", 
                           "Name of product", 
                           "New price", "Old price"]]

# Write the new products and messages to separate sheets in the same file
with pd.ExcelWriter(new_spreadsheet_filename) as writer:
    new_data_df.to_excel(writer, "Products", index=False)
    pd.DataFrame({"Messages": messages}).to_excel(writer, "Messages", index=False)

# Launch the new spreadsheet
os.startfile(new_spreadsheet_filename)

EDIT: Code that works with the actual spreadsheets:

import os
import pandas as pd

old_data_filename = r"old_data.xlsx"
new_data_filename = r"new_data.xlsx"
new_spreadsheet_filename = r"updated_products.xlsx"

# Load spreadsheets into a dataframe and set their indexes to "Product number"
old_data_df = pd.read_excel(old_data_filename).set_index("Product ID")
new_data_df = pd.read_excel(new_data_filename).set_index("Product ID")

# Remove duplicated indexes for both the dataframes, keeping only the first occurrence
old_data_df = old_data_df[~old_data_df.index.duplicated()]
new_data_df = new_data_df[~new_data_df.index.duplicated()]

# Determine which products are new/missing, and store the corresponding 
# messages in a list, which will be written to its own spreadsheet at the end
old_data_products = set(old_data_df.index)
new_data_products = set(new_data_df.index)

new_products = new_data_products - old_data_products
missing_products = old_data_products - new_data_products

messages = [f"Product ID {product} is missing in new data file" for product in missing_products]
messages.extend(f"Product ID {product} is newly added" for product in new_products)
messages = [f"Message {i}) {message}" for i, message in enumerate(messages, start=1)]

# Keep the original product names
new_data_df.update(old_data_df["Name"])

# Old price is the same as new price unless the product is in old_data_df, in which 
# case it is old_data_df["Current price"]
new_data_df["Old price"] = new_data_df["New price"]
new_data_df["Old price"].update(old_data_df["Current price"])

# Rename the "Name" column to "Name of product"
new_data_df.rename(columns={"Name": "Name of product"}, inplace=True)

# Remove all other columns except the ones we want
new_data_df.reset_index(inplace=True)
new_data_df = new_data_df[["Product ID", 
                            "Name of product", 
                            "New price", "Old price"]]

# Write the new products and messages to separate sheets in the same file
with pd.ExcelWriter(new_spreadsheet_filename) as writer:
    new_data_df.to_excel(writer, "Products", index=False)
    pd.DataFrame({"Messages": messages}).to_excel(writer, "Messages", index=False)

# Launch the new spreadsheet
os.startfile(new_spreadsheet_filename)

如何在两个不同的Excel表中搜索两个列中的相等产品编号,并从匹配行到新表格复制某些单元

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文