【发布时间】:2020-06-24 11:03:28
【问题描述】:
关于函数调用,我有一个理解问题。 我在“excel”类中的第一个功能是查找名称为“* ID *”的单元格。
public IEnumerable<string> FindID()
{
try
{
while (true)
{
if (ws.Cells[i, j].Value2 == "*ID*")
{
string ID = ws.Cells[i, j].Value2;
yield return ID;
yield break;
}
else
{
i++;
if (ws.Cells[i, j].Value2 == "*MAIN INFO END*")
{
i = 1;
j++;
}
}
}
}
finally
{
}
}
我的第二个函数循环放置在字符串中的列,例如“名称”或“可搜索”以查找列中的所有值并将所有值连接到每行的唯一字符串中。
public IEnumerable<string> AttributeToForm(int i, int j)
{
try
{
while (true)
{
if (ws.Cells[i, j].Value2 != null)
{
FindID();
string label = ID;
string name = ws.Cells[i, j + 1].Value2;
string searchable = ws.Cells[i, j + 3].Value2;
string FormField = "<FormField :span=\"6\" data-bwid =\"" + name + "\" name=\"" + name + "\" label=\"" + label + "\" ";
if (searchable != null) {
FormField += string.Join("", "searchable");
}
if(FormField != null)
{
FormField += string.Join("", "/>" + "\n");
}
else
{
}
yield return label;
i++;
}
else
{
yield break;
}
}
}
finally
{
}
}
但是 ...我真正想要的是在我的“AttributeToForm”函数中使用我的“FindID”函数中包含的字符串“ID”。为了到达那里,我尝试运行“FindID” 函数并检索字符串中的ID。但是结果仍然是我的类字符串 "ID",所以 "nothing"。
class Excel
{
private int i = 1;
private int j = 1;
private string ID = "nothing";...
【问题讨论】:
-
您希望 FindID 函数只返回一个 id 吗?
-
不,我想返回所有列,但从包含“ID”的单元格开始
-
我在这里没有得到你想要的结果。您的
FindID方法将始终只返回字符串*ID*如果它存在,否则将永远运行。在AttributeToForm中,您永远不会使用从FindID返回的值 -
所以我想知道如何在我的 AttributeToForm 函数中使用 FindID 函数获取字符串名称的结果
-
我认为我真正想要的是在我的 'AttributeToForm' 函数中使用我的 'FindID' 函数中包含的字符串 'ID'。有可能吗?
标签: c# arrays excel visual-studio interop