【问题标题】:How to load a local xlsx file in a UIWebView using Xamarin iOS如何使用 Xamarin iOS 在 UIWebView 中加载本地 xlsx 文件
【发布时间】:2016-02-01 13:56:55
【问题描述】:

您好,我正在尝试在 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.
        }
    }
}

但是,当我在模拟器中测试时,我得到一个空白屏幕,并且文件永远不会加载

我做错了什么?

任何建议都会很棒

提前致谢!

【问题讨论】:

  • 该文件是否存在于您的项目的根目录中且 Build Action 设置为 Content?
  • Jason 成功了,但文件是只读的,所以我必须寻找另一种在 iOS 中打开和编辑的方法,感谢您的帮助!
  • app bundle 中的所有内容都是只读的。您可以将文件复制到可写文件夹并从那里进行编辑。
  • 好的,我会尝试,所以我只是在项目中创建一个新文件夹并将 xlsx 文件放在那里并更改代码以查看该文件夹?
  • 不,应用程序包中的任何内容都是只读的。您必须在运行时创建一个不在捆绑包中的新文件夹,然后将文件复制到那里。然后您将获得该文件的可写副本。

标签: ios xamarin uiwebview xamarin.ios


【解决方案1】:

感谢 Jason 的建议,将 Build Action 更改为 Content 有效,但该文件是只读的,因此我必须寻找另一种在 iOS 中打开和编辑的方法 再次感谢 Jason 的帮助!

【讨论】:

    猜你喜欢
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 2011-06-06
    相关资源
    最近更新 更多