如何使用Xamarin iOS在UIWebView中加载本地xlsx文件

时间:2016-02-01 13:56:56

标签: ios xamarin uiwebview xamarin.ios

您好我正在尝试在UIWebView中加载xlsx文件在Xamarin提供的文档之前,您应该可以使用以下代码加载此文件:

using Foundation;
using System;
using System.CodeDom.Compiler;
using System.IO;
using UIKit;

namespace Justice_Compliance_Monitoring_App
{
    partial class SurveyView : UIViewController
    {
        UIWebView webView;

        public SurveyView (IntPtr handle) : base (handle)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.White;

            webView = new UIWebView(View.Bounds);
            View.AddSubview(webView);

            //string fileName = "Loading a Web Page.pdf";
            //string fileName = "Loading a Web Page.docx";
            string fileName = "servey.xlsx";

            string localDocUrl = Path.Combine(NSBundle.MainBundle.BundlePath, fileName);
            webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));

            // if this is false, page will be 'zoomed in' to normal size
            webView.ScalesPageToFit = true;
        }

        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.
        }
    }
}

然而,当我在模拟器中测试时,我得到一个空白的白色屏幕,文件永远不会加载

我做错了什么?

任何建议都会很棒

提前致谢!

1 个答案:

答案 0 :(得分:0)

感谢Jason的建议将Build Action更改为Content,但该文件是只读的,因此我将不得不考虑在iOS中打开和编辑的另一种方式 再次感谢Jason的帮助!