J'ai besoin de déplacer du code Applescript vers Scripting Bridge pour tirer parti de certains hooks Cocoa sans avoir besoin d'Applescript-ObjC.Portage Applescript à Scripting Bridge: impossible d'obtenir la valeur de plage dans Excel 2008
l'aide d'Excel 2008 avec AppleScript, obtenir la valeur d'une plage est facile:
set myList to GetValuesFromColumnRange("A", 1, 100)
on GetValuesFromColumnRange(ColumnLetter, FirstRow, LastRow) -- (string, integer, integer) as list
set theList to {}
tell application "Microsoft Excel"
set theRange to ColumnLetter & FirstRow & ":" & ColumnLetter & LastRow
set AppleScript's text item delimiters to {return}
set theList to (get value of range theRange as list)
set AppleScript's text item delimiters to {""}
end tell
set theList to ConvertItemizedListToValueList(theList) of me -- Note this dependency due to how MSE2008 returns the data
return theList
end GetValuesFromColumnRange
Mais dans Bridge script, je vais avoir un problème à obtenir les cellules d'une feuille de calcul basée sur une plage. Ce qui suit est ce que j'ai jusqu'à présent.
Excel2008Application *excelApp = [SBApplication applicationWithBundleIdentifier:@"com.microsoft.Excel"];
Excel2008Workbook *workbook = excelApp.activeWorkbook;
SBElementArray *sheets = [workbook sheets];
Excel2008Sheet *targetSheet;
int thisSheet = 0;
int lastSheet = [sheets count];
for (thisSheet = 0; thisSheet < lastSheet; thisSheet++) {
Excel2008Sheet *currentSheet = [sheets objectAtIndex:thisSheet];
NSString *currentSheetName = currentSheet.name;
if ([currentSheetName isEqualToString:@"Metadata"]) {
targetSheet = currentSheet;
[targetSheet retain];
}
}
Excel2008Range *range = [[[excelApp classForScriptingClass:@"range"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:@"A1:A10", @"formulaR1c1", nil]];
[[targetSheet ranges] addObject:range];
range = [[targetSheet ranges] lastObject]; // not null; stated class in log: MicrosoftExcelRange
Excel2008Sheet *valueSheet = range.worksheetObject; // supposed to be new worksheet based upon values within the range; not null; stated class in log: MicrosoftExcelSheet
[valueSheet retain];
SBElementArray *valueCells = [valueSheet cells]; // not null, but count is 0
[valueCells retain];
Le problème est livré avec la dernière ligne, quand je reçois effectivement les cellules de valueSheet
, en ce que le retour SBElementArray
est non nul, mais il ne contient pas non plus d'objets. La même chose vaut pour obtenir les cellules dans targetSheet
ainsi.
La documentation pour faire ceci, presque comme je peux dire de toutes mes recherches, n'existe pas et j'ai pris ceci à propos autant que je peux.