Reading a specific cell in an Excel file

I’m just getting my feet wet with GemBox, and I’m looking at the Reading example. Is there a way just to read a specific cell in an excel file I.E. (E,10)? The example shows it reading in the whole file.

Thanks

Hi Larry,

Yes, you can read any specific cell like the following:

ExcelFile workbook = ExcelFile.Load("input.xlsx");
ExcelWorksheet worksheet = workbook.Worksheets["Sheet1"];
ExcelCell cell = worksheet.Cells["E10"]
Console.WriteLine(cell.Value);

Or the following:

ExcelFile workbook = ExcelFile.Load("input.xlsx");
ExcelWorksheet worksheet = workbook.Worksheets[0];
ExcelCell cell = worksheet.Cells[9, 4];
Console.WriteLine(cell.Value);

Or you could check the Cell Referencing example which shows additional ways how you can retrieve the desired cell or cells, like using column name “E” and row index 9.

I hope this helps.

Regards,
Mario

Using your code, I have modified it to suit what I need to do, see below.

SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
var workbook = ExcelFile.Load("/Users/lawrenceriehl/Documents/CRJ200#3WPM.xlsm");
ExcelWorksheet worksheet = workbook.Worksheets["Sheet1"];
ExcelCell cell = worksheet.Cells["H6"];
Variables.CellValue = (cell.Value.ToString());

The code compiles fine in Visual Studio for Mac, but when I try to execute the app in the Simulator, I get the following error on the Main.cs file.

SystemTypeInitializationException has been thrown
The type initializer for ‘Gembox.Spreadsheet.CalculationEngine.Functions.TextFunctions’
threw an exception

Thanks

Hi,

What version of GemBox.Spreadsheet are you using (check SpreadsheetInfo.FullVersion)?

Also, what do you mean by “Simulator”?

Also, can you send us the stack trace of the exception?

Last, can you send us the Visual Studio project that reproduces this issue so that we can investigate it?

Regards,
Mario

Thanks for the fast reply!

The version the best I can tell is 47.0.1000 says it is the latest.

The Simulator is a utility that allows the app to run on different devices, Cell phone, iPad which is what I am using it for. This makes it easier to test the app out without having to transfer the app to the device.

The Stack Trace is:

Stack Trace

at GemBox.Spreadsheet.CalculationEngine.SpreadsheetExpressionParser…ctor (System.Globalization.CultureInfo culture) [0x00031] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.ExcelFile.get_ExpressionParser () [0x0000e] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.CalculationEngine.SpreadsheetExpressionContext…ctor (GemBox.Spreadsheet.ExcelCell cell) [0x00022] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.GetFormulaWithExternalReferences (GemBox.Spreadsheet.ExcelCell cell, System.String formula) [0x00008] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.ReadCellFormula (GemBox.OpenXml.Xml.XElement element, GemBox.Spreadsheet.ExcelCell cell) [0x0014d] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.ReadSheetCell (GemBox.OpenXml.Xml.XElement element, GemBox.Spreadsheet.ExcelRow row, System.Int32& columnIndex) [0x0017d] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.ReadSheetRow (GemBox.OpenXml.Xml.XElement element) [0x000e8] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.ReadSheetData (GemBox.OpenXml.Xml.XElement element) [0x0003d] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.ReadWorksheet (GemBox.OpenXml.Xml.XElement element) [0x0048a] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.ReadRootElement (GemBox.OpenXml.Xml.XElement root) [0x000b9] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.OpenXml.Xml.XElement.Root (GemBox.OpenXml.Xml.XReader reader, System.Action1[T] action) [0x0000d] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.OpenXml.Xml.XElement.Root (System.IO.Stream stream, System.Action1[T] action) [0x00007] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.OpenXmlPartReader.ReadPart (System.Func`2[T,TResult] readerCreator) [0x00048] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.OpenXmlPartReader.ReadPart () [0x00000] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.WorksheetReader.Read (System.String worksheetPartPath, GemBox.Spreadsheet.OpenXml.ReadContext packageContext, GemBox.Spreadsheet.ExcelWorksheet worksheet) [0x00008] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.XlsxReadDirector.ReadWorksheets () [0x00045] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.OpenXml.XlsxReadDirector.Construct () [0x0001a] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.XlsxLoadOptions.LoadInternal (GemBox.Spreadsheet.ExcelFile excelFile, GemBox.Spreadsheet.PackageBuilderBase builder, System.Boolean preserveTemplate) [0x00009] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.XlsxLoadOptions.LoadInternal (GemBox.Spreadsheet.ExcelFile excelFile, System.IO.Stream stream, System.String path) [0x0009c] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.XlsxLoadOptions.LoadCore (GemBox.Spreadsheet.ExcelFile excelFile, System.IO.Stream stream, System.String path) [0x00000] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.LoadOptions.LoadCoreWithoutLimitations (GemBox.Spreadsheet.ExcelFile excelFile, System.IO.Stream stream, System.String path) [0x00007] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.LoadOptions.Load (GemBox.Spreadsheet.ExcelFile excelFile, System.IO.Stream stream, System.String path, System.Boolean reset) [0x00033] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.LoadOptions.Load (System.String path) [0x00014] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.ExcelFile.Load (System.String path, GemBox.Spreadsheet.LoadOptions options) [0x0000e] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at GemBox.Spreadsheet.ExcelFile.Load (System.String path) [0x00007] in <08a1ba98ad1e48bdaf4b37627885ccdb>:0 \n at PM_APP.Page6Xaml…ctor () [0x0001a] in /Users/lawrenceriehl/Projects/PM_APP/PM_APP/Page6.Xaml.xaml.cs:20 \n at PM_APP.Page4Xaml.Weekly_Clicked (System.Object sender, System.EventArgs e) [0x0001a] in /Users/lawrenceriehl/Projects/PM_APP/PM_APP/Page4Xaml.xaml.cs:30 \n at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 \n at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSAction.cs:178 \n at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)\n at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:86 \n at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:65 \n at PM_APP.iOS.Application.Main (System.String[] args) [0x00001] in /Users/lawrenceriehl/Projects/PM_APP/PM_APP.iOS/Main.cs:17

I would have to get permission to send the whole project, so at this time I could not send the project.

Thanks
Larry