After finally figuring out how to pull data from google spreadsheets, I can't understand how to add new entries to the end of file.
Here's what I want to achieve:
My app should send some survey results to a google spreadsheet, here's how the file is supposed to look:
Let's assume that I need to send the next survey results to that spreadsheet. How do I send them and make sure that they appear just under the last survey results?
Thanks
UPDATE
I've found an answer long ago, so decided to update the question for lone rangers like me that couldn't find any info on this topic :)
For this answer I assume that you already know how to get to the spreadsheet's cells feed.
Here's what you need to do after you get the cells feed:
First of all we need to find out the last row number so we can later on write to the row under it.
NSArray * entries = [cellsFeed entries]; // we pull out all the entries from the feed
GDataEntrySpreadsheetCell * lastCell = [entries lastObject]; // then we take just the last one
NSString * title = [[lastCell title] stringValue]; // then we need it's title. The cells title is a combination of the column letter and row number (ex: A20 or B5)
NSString * lastRow = [[title componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:#""]; // then we remove the letters and we're left only with the row number
We can now send some data to the row under the last row like this:
// create a cell object and give it the row number (in our case it's the row under lastRow, so we add + 1), column number (yes, here you should provide a number and not a letter) and the string that you want to appear in the cell
GDataSpreadsheetCell * cell = [GDataSpreadsheetCell cellWithRow:[lastRow intValue] + 1 column:1 inputString:#"some value" numericValue:nil resultString:nil];
// create a cellEntry object that will contain the cell
GDataEntrySpreadsheetCell * cellEntry = [GDataEntrySpreadsheetCell spreadsheetCellEntryWithCell:cell];
// upload the cellEntry to your spreadsheet
[_srv fetchEntryByInsertingEntry:cellEntry
forFeedURL: [[workSheet cellsLink] URL] // make sure that you save the workSheet feed in an instance variable so that you'll be able to reach it in another method. If you pulled data from the spreadsheet that you must already know how to get the worksheet feed
delegate:self
didFinishSelector:nil];
That's it! The data should upload to your spreadsheet.
Let me know if you have any questions, I know the documentation is kinda scarce for this.
Related
I have an array of objects. Each object has property "date" and "title".
I want to populate sectioned UITableView with those items like:
Section 1 - 2012.06.12 (taken from object.date)
Cell 1.1: Title 1 (taken from object.name)
Cell 1.2: Title 2
Cell 1.3: Title 3
...
Section 2 - 2012.06.13
Cell 2.1: Title 1
Cell 2.2: Title 2
..
Section 3 ..
I can do that by manually creating 1..n NSMutableArrays for all date combinations and filling them with object.name values. But the problem is I do not know how many date combinations there are, so it should be done dynamically. Also, the date property can repeat in different objects
My object structure is:
Object
-NSDate - date
-NSString - title
UPD:
I was thinking if it is possible to create NSDictionary, where the key would be my date and the object would be NSArray, which contains all my items for the key-date. But I do not know how to do that dynamically.
I hope I explained my question clearly enough.
Thank you in advance!
You can create arrays based on date.You have array of objects, so iterate through this array of objects to get distinct dates, as follows:
for(int i =0;i<[objectsArr count];i++)
{
if(![newDateArr containsObject:[objectsArr objectAtIndex:i].date])
{
[newDateArr addObject:[objectsArr objectAtIndex:i].date];
}
NSMutableArray *newTitleArray = [newTitleDictionary objectForKey:#"[objectsArr objectAtIndex:i].date"];
if(newTitleArray != nil)
{
[newTitleArray addObject:[objectsArr objectAtIndex:i].title];
}
else
{
newTitleArray = [[[NSMutableArray alloc] init] autorelease];
[newTitleArray addObject:[objectsArr objectAtIndex:i].title];
}
[newTitleDictionary setValue:newTitleArray forKey:#"[objectsArr objectAtIndex:i].date"];
}
where newTitleDictionary and newDateArr are declare outside this method.Now you can use both is newTitleDictionary and newDateArr to populate tableview.
If I understand you correctly, you want to put an object into an array and then use that array to populate a table view?
Just add the date object each time to the NSMutableArray.
[myArray addObject:dateObject];
Then when it comes to populating the table view..
DateObject *newDateObj = [myArray objectAtIndex:index];
I hope this helps and I understood your question
EDIT To answer now I understand a bit more.
Step 1
Check through the existing array of dates and see if there are any that match maybe by iterating through it using a for loop. Search online for how to compare NSDate.
Step 2 If it doesn't match any then insert it into the array as an array with just that date on it's own so the array count will be one. If it does match then insert it into the array along with that one making the array count 2 or more.
Step 3 When it comes to declaring the section amount for the table just return the dateHolderArray count.
Step 4 When declaring the amount of rows in each section, return the array count for the array thats inside the dateHolderArray.
Step 5 Display the content when it comes to populating the cells with information. It becomes just a task of getting the dates from the arrays using the section ids and row ids.
This is how I would do it, there are probably many other methods. Any questions just ask
I am trying to remove objects at array starting at index 5 to the end of the list. I have a for loop to do this, however now I discovered
- (void)removeObject:(id)anObject inRange:(NSRange)aRange
The question is what is the anObject here? I only need range as far as I know
removeObject:inRange: deletes an object within a certain range. This method would be useful if you wanted delete the string #"Hello World" only if it is one of the first 5 elements.
It sounds like what you are trying to do is delete all objects after the 5th element. If that is what you are trying to do, you should use the removeObjectsInRange: method. For example:
NSRange r;
r.location = 5;
r.length = [someArray count]-5;
[someArray removeObjectsInRange:r];
You want
- (void)removeObjectsInRange:(NSRange)aRange
Removes from the array each of the objects within a given range.
I am using the hpple plugin to parse and display html elements in my iphone app.
The problem i'm having is say there is a table on the webpage I am trying to parse, with several rows, (that may change from time to time). How do I go about getting the number of rows in this table, and iterating through each row and getting the different text content on each row. Is this possible with the hpple plugin?
Thanks in advance.
If all that want to do is count the rows in a table with class "tableClass" then you might try something like this
// Count the number of rows in a particular table
NSString *searchString = [NSString stringWithFormat:#"//table[#class='tableClass']/tr;
NSArray *tableRows = [xpathParser search:searchString];
NSInteger rows = [tableRows count];
NSLog(#"There are %d table Rows", rows);
// For loop to step through the rows
for(int j = 1; j <= rows; j++) {
searchString = [NSString stringWithFormat:#"//table[#class='tableClass']/tr[%d]/td", j];
NSArray *tableCells = [xpathParser search:searchString];
}
This should step through the table row by row and each time scrape the individual data cells (I didn't test it so there are no guarantees.) The problem with this is that it will be very slow if your table has more than a few rows.
You are better off just calling the table and scraping all the td cells at once from the table and then deciding how they make up the rows. This way is easy if the number of cells in a row stays constant.
I need to load a data file, test.dat, into Matlab. The contents of data file are like
*a682 1233~0.2
*a2345 233~0.8 345~0.2 4567~0.3
*a3457 345~0.9 34557~1.2 34578~0.2 9809~0.1 2345~2.9 23452~0.9 334557~1.2 234578~0.2 19809~0.1 23452~2.9 3452~0.9 4557~1.2 3578~0.2 92809~0.1 12345~2.9 232452~0.9 33557~1.6 23478~0.6 198099~2.1 234532~2.9 …
How to read this type of file into matlab, and use the terms, such as *2345 to identify a row, which links to corresponding terms, including 233~0.8 345~0.2 4567~0.3
Thanks.
Because each of the rows is a different size, you either have to make a cell array, a structure, or deal with adding NaN or zero to a matrix. I chose to use a cell array, hope it is ok! If someone is better with regexp than me please comment, the output cells are now not perfect (i.e. show 345~ instead of 345~0.9) but I am sure it is a minor fix. Here is the code:
datfile = 'test.dat';
text = fileread(datfile);
row1 = regexp(text,'*[a-z]?\d+','match');
data(:,1) = row1';
row2 = regexp(text,'*[a-z]?\d+','split');
row2 = [row2(:,2:end)'];
for i = 1:size(row2,1)
data{i,2} = regexp(row2{i},'\d+\S\d+\s','split');
end
What this creates is a cell array called data where the first column of every row is your *a682 id and the second column of each row is a cell with your data values. To get them you could use:
data{1}
to show the id
data{1,2}
to show the cell contents
data{1,2}{1}
to show the specific data point
This should work and is relatively simple!
In Contacts I have set up a Date field with a custom label (when editing a contact you select Add Field-> Date -> Anniversary -> Add Custom Label).
This is stored in the ABMultiValue property of ID 'kABPersonDateProperty' with a label of (for example) 'Next Appointment'.
The ABMultiValue API has functions to tell me the label name at an index, read the value at an index and convert between ID/Index.
Please forgive me if I am being thick here but is the quickest way to get the date of the 'Next Appointment' to iterate the Multivalue field looking for the index of a matching label then copy the value of the property at that index? From what I can tell, the index will vary from record to record.
I realise there is a function to get an index from a property ID, but that means that at some point earlier I will have to have discovered the propertyID by going through all the records trying to find one with the 'Next Appointment' field in it to get its propertyid.
I want to view the date in a tableview and sort on it so I need to get the value as efficiently as possible. Has anyone got a method of doing this quickly, preferably with example code or a link for further info?
The approach you describe is correct. You will want to do something similar to Apple's sample code for multivalue properties from the Address Book Programming Guide for iPhone OS:
CFStringRef phoneNumber, phoneNumberLabel;
multi = ABRecordCopyValue(aRecord, kABPersonPhoneProperty);
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) {
phoneNumberLabel = ABMultiValueCopyLabelAtIndex(multi, i);
phoneNumber = ABMultiValueCopyValueAtIndex(multi, i);
/* ... do something with phoneNumberLabel and phoneNumber ... */
CFRelease(phoneNumberLabel);
CFRelease(phoneNumber);
}
CFRelease(aRecord);
CFRelease(multi);