0

截至目前,我有代码:

tell application "Microsoft Excel"

-- put the complete set of data into a list of lists (i.e., 2 dimensions -> columns of rows)
set range1 to range "B2:H7686"
tell active sheet to set myData to value of range1
-- now access a specific cell's data
set myRow to 7
set myCol to 3
set myVal to item {myCol} of item {myRow} of myData

end tell

按行然后按列创建一个包含元素的双精度数组。因此,如果我的 Excel 单元格如下所示:

| A1 | A2 | A3 |

| B1 | B2 | B3 |

我的变量 myVar 将是一个如下所示的数组:

{{“A1”、“A2”、“A3”}、{“B1”、“B2”、“B3”}}

我现在要做的是获取一个现有项目,我们将其称为 example_project,使用现有的 .m 文件,我们将其称为 example_m.m,并将 myVar 中数组的每个元素写入对象的属性.

例如,如果我的数组与前面提到的数组相同,并且我正在使用这些值作为属性初始化一个示例对象,那么它在 Xcode 中应该看起来像这样:

exampleObjectA = [[exampleClass alloc] init];
[exampleObjectA initExampleClass:@"A1" secondAttribute:@"A2" thirdAttribute:@"A3"];

exampleObjectB = [[exampleClass alloc] init];
[exampleObjectB initExampleClass:@"B1" secondAttribute:@"B2" thirdAttribute:@"B3"];

我要的是什么会给我这些确切的代码行,预先写到 Xcode 中。我试图将大约 45000 个单元格的数据放入应用程序中,但出于明显的原因我不想手动执行。

4

1 回答 1

0

您正在使用带有许多属性的 exampleObjectA,这些属性是您在设置时设置的init。我建议您制作一组 KVP 并继续添加它。

当您将 @"A1", @"A2" 作为字符串传递时,您可以创建一个循环并使用

for(NSInteger i=1; i<=myVar.count; i++){
    NSString *cellReference=[NSString stringWithFormat:@"A%ld,i];
    //then call a method to update your exampleObjectA
    //add this to array or KVP
}
于 2013-03-21T03:41:26.093 回答