C# 如何使用TMS FlexCel Studio在Xamarin iOS应用程序中打开本地excel文件
我有一个本地excel文档,我需要能够在我正在制作的iOS应用程序中打开它。我还需要能够从移动应用程序向excel文件添加条目。我使用的是Xamarin,TMS FlexCel Studio组件是最好的选择。我已设置了一个项目,并已将excel文件项目添加到该项目中,以及将TMS FlexCel Studio组件添加到我的项目中。但我不知道如何加载excel项目这是我当前的代码:C# 如何使用TMS FlexCel Studio在Xamarin iOS应用程序中打开本地excel文件,c#,ios,excel,xamarin,xamarin.ios,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 Founda
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");
}
}
}
}
}
使用FlexCel.Core;
使用FlexCel.XlsAdapter;
使用基础;
使用制度;
使用System.CodeDom.Compiler;
使用System.IO;
使用UIKit;
命名空间公正性\合规性\监控\应用程序
{
分部类SurveyView:UIViewController
{
公共测量视图(IntPtr句柄):基础(句柄)
{
}
公共覆盖无效ViewDidLoad()
{
XlsFile xls=new-XlsFile(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),“servey.xlsx”);
xls.ActiveSheetByName=“Sheet1”//我们将阅读Sheet1。我们可以使用xls.SheetCount和xls.ActiveSheet循环现有的工作表
对于(int row=1;row您不希望将该代码放在静态Main中,除非您正在创建一个.Net cmd行程序,而不是一个基于Xamarin.iOS的程序,并且您删除了对UIApplication.Main
的调用,因此应用程序总是会终止。这种类型的活动应该在应用程序初始化后进行,如基于UIViewController
的对象(即ViewDidLoad
方法内部)。可能从开始,以便您理解基础知识。谢谢您的回复。我现在将它放在类中,而不是main.cs文件中。但是,当我在模拟器上运行它时,出现了此错误。下面是错误:System.IO.FileNotFoundException:找不到文件“/Users/debroc1/Library/Developer/CoreSimulator/Devices/76FB8159-64C5-4BF2-AB9C-9F98E24ACAE6/data/Containers/data/Application/59F0C6D4-3F22-41A1-B790-407F06543378/Documents/servey.xlsx"。此外,我还向问题中添加了更新的代码。仅供参考。错误非常清楚,.xlsx
未在您告诉它加载它的位置找到。例如,它确实存在于环境中。SpecialFolder.MyDocuments
我知道它位于项目的根上。如何更改环境。SpecialFolder.MyDocuments以反映项目的根源?感谢迄今为止的所有帮助!