open and read excel

Hi,

 

I want to open a excel spreadsheet. Read the first column into and array. The sheet name is “SalesPerson”. Can you please give me an example that will work on an android device.

 

I tried the following

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using Android.App;

using Android.Content;

using Android.OS;

using Android.Runtime;

using Android.Views;

using Android.Widget;

using System.Collections;

using Syncfusion.XlsIO;

 

using NU_CRM;

 

 

namespace NU_CRM

{

    public class GetXdata

    {

        [System.Security.SecuritySafeCritical]

        private ArrayList RepName;

        private ArrayList Speciality;

        private ArrayList DoctorName;

        private ArrayList HospitalName;

        private ArrayList ProductName;

        String xlDocName = @"/storage/emulated/0/nu-data/data.xlsx";

       

        //string ConfigFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "config.xls");

        //================== Get reps ===========================

        public ArrayList RepaddData()

        {

            RepName = new ArrayList();

            var sheetName = "SalesPerson";

            // Existing tab name.

 

            System.IO.MemoryStream mStream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(xlDocName));

 

            using (ExcelEngine excelEngine = new ExcelEngine())

            {

                IWorkbook workbook = excelEngine.Excel.Workbooks.Open(mStream);

                IWorksheet worksheet = workbook.Worksheets[0];

                string cellinfo = worksheet["A1"].Text;

 

               

            }

                return RepName;

        }

 

 

When I put a breakpoint at string cellinfo = worksheet  the value of cell info is "/storage/emulated/0/nu-data/data.xlsx"




5 Replies

PR Padmini Ramamurthy Syncfusion Team October 30, 2017 08:52 AM UTC



SS Sridhar Sukumar Syncfusion Team November 1, 2017 01:33 PM UTC

Hi Johnny, 
 
Thank you for contacting Syncfusion support. 
 
We have prepared a sample to read the worksheet values using XlsIO in Xamarin.Android platform. The sample can be downloaded from the following link. 
 
 
Please let us know if you have any concern. 
 
Regards, 
Sridhar. 



PG Pon Geetha A J Syncfusion Team November 2, 2017 11:11 AM UTC

Hi Sridhar, 
 
The sample you send works perfect. Thanks. If I add the sample code to my project. It compiles and if I run the app I do get the following exception error. 
 
 
 
My file with the code is attached. The function is at line 188 
 
Can you please help 
 
Thanks 
 
Johnny 

SettingsActivity



MM Mathu Mohan Vijayakumar Syncfusion Team November 3, 2017 03:21 PM UTC

Hi Johnny, 
 
The Exception occurs when the Linker behavior is set to None or Link all assemblies. So, we request you to set the following options to resolve the exception. 
 
Go to Project Properties -> Android Options 
  1. Set Linker options to Sdk Assemblies Only
  2. Add Syncfusion.XlsIO.Portable assembly in Skip Linking assemblies
 
Screenshot: 
 
 
For reference we have shared below the KB documentation link. 
 
 
Please let us know if you have any queries. 
 
Regards, 
Mathu Mohan V A 
 



PG Pon Geetha A J Syncfusion Team November 6, 2017 04:29 AM UTC

Hi, 
 
Thank you for the support. It solved my problems 
Regards 
 
Johnny 


Loader.
Up arrow icon