在iOS中将CSV上传(转换为电子表格)到Google云端硬盘? [英] CSV upload (convert to spreadsheet) to google drive in iOS?
本文介绍了在iOS中将CSV上传(转换为电子表格)到Google云端硬盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有生成csv文件存储在本地目录路径。我试图上传csv文件到谷歌驱动器,它工作正常。从Google驱动器打开csv文件,不在电子表格中显示预览。所以我想上传csv文件(将csv转换为电子表格)到谷歌驱动器。
如何转换?
I have generate csv file to store inside local directory path. i have tried to upload csv file to google drive, it working fine. open a csv file from google drive not showing preview in spreadsheet. so i want to upload csv file (convert csv to spreadsheet) to google drive. How to convert this?
感谢提前
来自Google Drive的图片
Images from google drive
>
上传csv文件以供您参考的示例:
Example for upload csv file to drive for your reference:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *root = [documentsDir stringByAppendingPathComponent:@"Report.csv"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:root];
if(fileExists == YES)
{
GTLUploadParameters *uploadParameters = nil;
self.driveFile = [[GTLDriveFile alloc]init];
NSData *dat = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:root]];
uploadParameters =
[GTLUploadParameters uploadParametersWithData:dat MIMEType:@"text/csv"];
self.driveFile.title = @"Report.csv";
GTLQueryDrive *query = nil;
if (self.driveFile.identifier == nil || self.driveFile.identifier.length == 0)
{
query = [GTLQueryDrive queryForFilesInsertWithObject:self.driveFile
uploadParameters:uploadParameters];
}
else
{
query = [GTLQueryDrive queryForFilesUpdateWithObject:self.driveFile
fileId:self.driveFile.identifier
uploadParameters:uploadParameters];
}
UIAlertView *alert = [DrEditUtilities showLoadingMessageWithTitle:@"While data is uploading..."
delegate:self];
[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error)
{
appDel.File_Id = updatedFile.identifier;
[alert dismissWithClickedButtonIndex:0 animated:YES];
if (error == nil)
{
self.driveFile = updatedFile;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Feel Fix" message:@"Successfully Uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
}
else
{
NSLog(@"An error occurred: %@", error);
[DrEditUtilities showErrorMessageWithTitle:@"Unable to save file"
message:[error description]
delegate:self];
}
}];
推荐答案
插入Convert属性以修复此问题
Insert Convert property to fix this issue
GTLUploadParameters *uploadParameters = nil;
self.driveFile = [[GTLDriveFile alloc]init];
NSData *dat = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:root]];
uploadParameters =
[GTLUploadParameters uploadParametersWithData:dat MIMEType:@"text/csv"];
self.driveFile.title = @"Report.csv";
GTLQueryDrive *query = nil;
if (self.driveFile.identifier == nil || self.driveFile.identifier.length == 0)
{
query = [GTLQueryDrive queryForFilesInsertWithObject:self.driveFile
uploadParameters:uploadParameters];
query.convert = YES; // Convert file format to spread sheet
}
else
{
query = [GTLQueryDrive queryForFilesUpdateWithObject:self.driveFile
fileId:self.driveFile.identifier
uploadParameters:uploadParameters];
}
UIAlertView *alert = [DrEditUtilities showLoadingMessageWithTitle:@"While data is uploading..."
delegate:self];
[self.driveService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error)
{
appDel.File_Id = updatedFile.identifier;
[alert dismissWithClickedButtonIndex:0 animated:YES];
if (error == nil)
{
self.driveFile = updatedFile;
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Feel Fix" message:@"Successfully Uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
}
else
{
NSLog(@"An error occurred: %@", error);
[DrEditUtilities showErrorMessageWithTitle:@"Unable to save file"
message:[error description]
delegate:self];
}
}];
这篇关于在iOS中将CSV上传(转换为电子表格)到Google云端硬盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文