gpt4 book ai didi

ios - CSV 上传(转换为电子表格)到 iOS 中的谷歌驱动器?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:43:45 26 4
gpt4 key购买 nike

我已生成 csv 文件以存储在本地目录路径中。我试图将 csv 文件上传到谷歌驱动器,它工作正常。从谷歌驱动器打开一个 csv 文件,在电子表格中不显示预览。所以我想上传 csv 文件(将 csv 转换为电子表格)到谷歌驱动器。如何转换?

提前致谢

来自谷歌驱动器的图片

enter image description here

上传csv文件到驱动的例子供大家引用:

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 属性以解决此问题

    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 上传(转换为电子表格)到 iOS 中的谷歌驱动器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22247341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com