BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
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
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.
Pannir
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.
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;
}
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;
}