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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

spreadsheetControl.GridProperties.CurrentExcelGridModel null exception

Thread ID:

Created:

Updated:

Platform:

Replies:

113869 Oct 14,2013 08:06 AM UTC Oct 22,2013 01:20 PM UTC WPF 5
loading
Tags: SpreadsheetControl(Classic)
Ken
Asked On October 14, 2013 08:06 AM UTC

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

 


Pannir Selvam S [Syncfusion]
Replied On 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

Ken
Replied On 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.

 


Ken
Replied On 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;

 

 

}


Ken
Replied On 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;

 

 

}

 

 

 

 

 

 

 

 

 

 

 

      


Jayapradha S [Syncfusion]
Replied On 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




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;