我正在尝试编写一个代码(请参见下文),该代码将从选定范围内提取公式并将其粘贴到用户定义的另一个范围内,而无需更改引用。
我在将项目从数组写入工作表时遇到麻烦。它只是粘贴了第一项...我已经阅读了一些帖子,并应用了各种代码,但这些都不起作用...您能提供一些建议来解决此问题吗?预先感谢。
pd.testing.assert_frame_equal
编辑:
对于任何有兴趣的人,这就是我最终想出的:
from unittest.mock import Mock
import pandas as pd
import my_code
...
score_function_mocked = Mock()
my_code.score_function = score_function_mocked
my_code.run_scoring
pd.testing.assert_frame_equal(
# [0] = *args, [0][1] = second positional arg to my function
score_function_mocked.call_args[0][1],
pd.DataFrame({
'new_york': [1, 0],
'chicago': [0, 1],
'austin': [0, 0]
})
)
希望您对此主题提供任何反馈。
答案 0 :(得分:1)
好的,因此可以通过以下更简单的方式解决此任务。虽然,我会很困惑如何使用第一个问题中提到的代码来完成它……
Sub copy_formulas_2()
Dim y As Variant
Dim rg_row As Integer, rg_column As Integer
Dim i As Long
With Selection
y = .FormulaLocal
rg_row = .Rows.Count
rg_column = .Columns.Count
End With
Set output = Application.InputBox("Select Range", "Range for pasting formulas", Type:=8)
output.Resize(rg_row, rg_column).FormulaLocal = y
End Sub