2013-08-22 55 views
-1

任務:我們需要發送有一個Excel附件的電子郵件:從C#應用程序打開Excel(.xls)文件

問題Statemet(前filename.xls):無法打開Excel從C#應用程序發送的iPhone附件。

錯誤:無法查看文檔。文件格式無效。

數據從報告服務器呈現並使用下面的代碼被寫入到Excel文件:

byte[] bytes = rptAffirmativeTradeReportViewer.ServerReport.Render(format, null, out mimetype, out encoding,out filenameExtension, out streamids, out warnings); 
string sfilename = filename.xls 
     try 
     { 
      FileStream fs = File.Create(sFileName); 
      fs.Write(bytes, 0, bytes.Length); 
      fs.Close(); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 

上述代碼geneates具有名稱filename.xls一個文件和包含的數據。

該文件將被附加到Outlook併發送給用戶。

使用iPhone的用戶無法打開excel並出現錯誤。 使用Android的用戶可以打開excel文件。

請幫助我們知道需要做什麼才能在iPhone中打開此文件。

+2

有一個問題在那裏? – Kevin

回答

2
UIWebView *webView = (UIWebView*)self.view; 
self.actualFilePath = filePath; 

NSLog(@"File Path %@",filePath); 

NSString *mimeType = @""; 
if ([fileType caseInsensitiveCompare:@"PDF"]==NSOrderedSame){ 
mimeType = @"application/pdf"; 
} else if ([fileType caseInsensitiveCompare:@"DOC"]==NSOrderedSame){ 
mimeType = @"application/msword"; 
} else if ([fileType caseInsensitiveCompare:@"XLS"]==NSOrderedSame){ 
mimeType = @"application/vnd.ms-excel"; 
} 

[webView loadData:[NSData dataWithContentsOfFile:filePath] MIMEType:mimeType textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://www.google.com"]]; 

希望它有幫助

+0

嗨Huy Nghia - 坦率地說,我不明白答案。 –