如何使用TMS FlexCel Studio在Xamrian iOS应用程序中打开本地excel文件

时间:2016-02-01 16:04:50

标签: c# ios excel xamarin xamarin.ios

您好我有一个本地excel文档,我需要能够在我正在制作的iOS应用程序中打开。我还需要能够从移动应用程序向excel文件添加条目。我使用Xamarin和TMS FlexCel Studio组件是最好的选择。我有一个项目设置,并将excel文件项目添加到项目中,以及将TMS FlexCel Studio组件添加到我的项目中。但我不知道如何加载excel项目这是我现有的代码:

using FlexCel.Core;
using FlexCel.XlsAdapter;
using Foundation;
using System;
using System.CodeDom.Compiler;
using System.IO;
using UIKit;

namespace Justice_Compliance_Monitoring_App
{
    partial class SurveyView : UIViewController
    {

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

        public override void ViewDidLoad()
        {

            XlsFile xls = new XlsFile(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "servey.xlsx"));

            xls.ActiveSheetByName = "Sheet1";  //we'll read sheet1. We could loop over th existing sheets by using xls.SheetCount and xls.ActiveSheet 
            for (int row = 1; row <= xls.RowCount; row++)
            {
                for (int colIndex = 1; colIndex <= xls.ColCountInRow(row); colIndex++) //Don't use xls.ColCount as it is slow: See Performance.Pdf
                {
                    int XF = -1;
                    object cell = xls.GetCellValueIndexed(row, colIndex, ref XF);

                    TCellAddress addr = new TCellAddress(row, xls.ColFromIndex(row, colIndex));
                    Console.Write("Cell " + addr.CellRef + " has ");
                    if (cell is TRichString) Console.WriteLine("a rich string.");
                    else if (cell is string) Console.WriteLine("a string.");
                    else if (cell is Double) Console.WriteLine("a number.");
                    else if (cell is bool) Console.WriteLine("a bool.");
                    else if (cell is TFlxFormulaErrorValue) Console.WriteLine("an error.");
                    else if (cell is TFormula) Console.WriteLine("a formula.");
                    else Console.WriteLine("Error: Unknown cell type");
                }
            }
        }
    }
}

应用程序在模拟器上启动但在启动时崩溃我做错了什么?

提前致谢!

0 个答案:

没有答案