Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用iOS将.xls文件转换为Web服务的xml_Objective C_Xml_Xls - Fatal编程技术网

Objective c 使用iOS将.xls文件转换为Web服务的xml

Objective c 使用iOS将.xls文件转换为Web服务的xml,objective-c,xml,xls,Objective C,Xml,Xls,嘿,我正在编写一个应用程序,我需要将一个.xls文件转换为xml,以便将其提供给web服务。我所有的谷歌搜索都需要手工转换。我还没有找到任何关于如何通过iOS自动实现这一点的教程,有人知道一个好的教程,甚至是一本包含这一点的书吗 谢谢,威廉你有两个选择;将其转换为.xlsx,大部分工作都已为您完成,或者如果您计划在另一端简单地“解包”.xls,您可以只执行(base64编码文件内容),或类似操作。经过大量搜索,我找到了一个解决方案,将.xls文件作为.xls文件发送,如Flyn1179所建议的那

嘿,我正在编写一个应用程序,我需要将一个.xls文件转换为xml,以便将其提供给web服务。我所有的谷歌搜索都需要手工转换。我还没有找到任何关于如何通过iOS自动实现这一点的教程,有人知道一个好的教程,甚至是一本包含这一点的书吗


谢谢,威廉你有两个选择;将其转换为.xlsx,大部分工作都已为您完成,或者如果您计划在另一端简单地“解包”.xls,您可以只执行
(base64编码文件内容)
,或类似操作。

经过大量搜索,我找到了一个解决方案,将.xls文件作为.xls文件发送,如Flyn1179所建议的那样。我困惑地认为我必须将文件以xml的形式发送到web服务。下面是我使用的代码:

-(void)uploadFile:(NSString*)filename withExtension:(NSString*)extension{
    NSString* path = [[NSBundle mainBundle] pathForResource:filename ofType:extension];

    NSData *data = [NSData dataWithContentsOfFile:path];

    NSString *urlString = @"http://server/path/to/webservice/call";
    NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];
    NSString *boundary = @"---------------------------14737809831466499882746641449";
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
    NSMutableData *postbody = [NSMutableData data];
    [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"%@.%@\"\r\n", filename, extension] dataUsingEncoding:NSUTF8StringEncoding]]; //"uploadedfile" should be substituted for whatever variable the backend script expects the file variable to be
    [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postbody appendData:data];
    [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:postbody];

    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    NSLog(@"returned string: %@", returnString); //Just for display purposes

}

感谢所有人的帮助

感谢您的回复,我对web服务和在web服务之间传输数据是新手。我将如何按文件进行Base64编码?显然取决于您的平台,但以下是.NET中的方法: