We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

spreadsheetControl.GridProperties.CurrentExcelGridModel null exception

Hi,

I have this spreadsheetcontrol in the xaml:

<syncfusion:SpreadsheetControl Grid.Row="1" x:Name="spreadsheetControl" FormulaBarVisibility="Visible" />

At my code-behind, I would like to get the string value at the following methods:

 

public IWorkbook Workbook

 

 

{

 

get { return this.spreadsheetControl.ExcelProperties.WorkBook; }

 

}

 

 

 

public IWorksheet Worksheet

 

 

{

 

get { return Workbook.Worksheets[0]; }

 

 

}

 

 

 

public string GetCalculatedValue(string cellName)

 

 

{

var row = this.Worksheet.Range[cellName].Row;

var col = this.Worksheet.Range[cellName].Column;

return this.spreadsheetControl.GridProperties.CurrentExcelGridModel[row, col].FormattedText;

 

 

 

 

}

 

Problem encountered: I got  NullReferenceException on the CurrentExcelGridModel

 

Please help

 


5 Replies

PS Pannir Selvam S Syncfusion Team October 17, 2013 04:51 AM UTC

Hi Ken,

 

Thanks for using Syncfusion products.

 

We have analyzed your query and we won’t get any exception while getting the calculated value of cell using your code snippet. Please refer the attached sample. However we thought that you have tried to access the CurrentExcelGridModel before Workbook loaded. If so, please access the CurrentExcelGridModel after workbook loaded and you can check the Workbook loaded by hooking the WorkbookLoaded event of SpreadsheetControl.

 

Regards,

Pannir



SpreadsheetDemo_WPF_2a131974.zip


KE Ken October 17, 2013 11:47 AM UTC

Hi,

Indeed, it is due to I have accessed CurrentExcelGridModel before workbook loaded.

However, as my business logic need to get the formula from a particular cell before the workbook is loaded. Is there any members/properties which I can use for this scenario?

 

In my business logic, I have a series of code which will insert the formula into the cells, and then I need this formula to do some business logic calculation before the workbook is loaded.

 

Hope to hear from you soon. Thanks.

 



KE Ken October 17, 2013 12:00 PM UTC

Additional Info on my business logic:

#1) spreadsheet.InsertFormula(row, col, string.Format("=BLQty/{0}*2", LaytimeAllowedFactor.HasValue ? LaytimeAllowedFactor.Value : 100));

 

where spreadsheet is the class that contain  the syncfusion:SpreadsheetControl

#1 will insert formula to a particular cell.

The GetCalculatedValue method will get the formula from a particular cell that matches the cellName, here I have used CurrentExcelGridModel to retrieve the formula. However, this required me to hook up the WorkbookLoaded event.

Is there any members/properties of the SpreadSheetControl which I can use to retrieve the formula before the workbook is loaded?

 

public string GetCalculatedValue(string cellName)

 

 

{

       

 

var row = this.Worksheet.Range[cellName].Row;

var col = this.Worksheet.Range[cellName].Column;

return this.spreadsheetControl.GridProperties.CurrentExcelGridModel[row, col].FormattedText;

 

 

}



KE Ken October 17, 2013 02:49 PM UTC

Additional Info on my business logic:

#1) spreadsheet.InsertFormula(row, col, string.Format("=BLQty/{0}*2", LaytimeAllowedFactor.HasValue ? LaytimeAllowedFactor.Value : 100));

 

where spreadsheet is the class that contain  the syncfusion:SpreadsheetControl

 

#1 will insert formula to a particular cell.

 

The InsertFormula method is as follow:

 

public IWorkbook Workbook

 

 

{

 

get { return this.spreadsheetControl.ExcelProperties.WorkBook; }

 

 

}

 

 

public IWorksheet Worksheet

 

 

{

 

get { return Workbook.Worksheets[0]; }

 

 

}

 

 

 

public InsertFormula (int row, int col, string formula)

{

if (formula !=null)

 

this.Worksheet.Range[row,col].Formula = formula;

}

 

 

The GetCalculatedValue method will get the formula calculated value from a particular cell that matches the cellName, here I have used CurrentExcelGridModel to retrieve the formula. However, this required me to hook up the WorkbookLoaded event.

Is there any members/properties of the SpreadSheetControl which I can use to retrieve the formula calculated value before the workbook is loaded?

I want the GetCalculatedValue to return the calculated value of the inserted formula (see #1)

 

 

public string GetCalculatedValue(string cellName)

 

 

{

       

 

var row = this.Worksheet.Range[cellName].Row;

var col = this.Worksheet.Range[cellName].Column;

return this.spreadsheetControl.GridProperties.CurrentExcelGridModel[row, col].FormattedText;

 

 

}

 

 

 

 

 

 

 

 

 

 

 

      



JS Jayapradha S Syncfusion Team October 22, 2013 01:20 PM UTC

Hi Ken,

we have analyzed your query and it is not possible to access the calculated value of cell before Workbook loaded.
So we recommended that you can access the calculated value only after workbook loaded.


Regards,
Jayapradha




Loader.
Live Chat Icon For mobile
Up arrow icon