0

I am able to show the range explorer and also the numberformat category of it in my windows app using its default constructor, but really dont know how to retrieve the selected number format and pass it to the form's textbox. I am very new to spreadsheetGear. Can anyone help in using the range explorer. Thanks in Advance

nray
  • 5
  • 4

1 Answers1

0

Short answer: After the range explorer is closed, set the the Text property of the text box to the NumberFormat property of one of the cells within the range used in the range used in the RangeExplorer constructor.

textbox1.Text = worksheet.Cells["A1"].NumberFormat;

Longer answer: You can set up the range explorer like the code below.

// Select a range of cells.
workbookView.ActiveWorksheet.Cells["A1:C3"].Select();

// Get the active workbook set.
SpreadsheetGear.IWorkbookSet workbookSet = workbookView.ActiveWorkbookSet;

// Create the Range Explorer which operates on the current range selection.
SpreadsheetGear.Windows.Forms.RangeExplorer explorer 
  = new SpreadsheetGear.Windows.Forms.RangeExplorer(workbookSet);

// Set up some FormClosed event handler.
explorer.FormClosed 
  += new System.Windows.Forms.FormClosedEventHandler(rangeExplorer_FormClosed);

// Display the Range Explorer to the user.
explorer.Show(workbookView);

In the FormClosed event handler, you can get the NumberFormat for anywhere inside the range used in the RangeExplorer constructor. If your text box is called textbox1, it would look like this.

private void rangeExplorer_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
{
    workbookView.GetLock();
    try
    {
      SpreadsheetGear.IWorksheet worksheet = workbookView.ActiveWorksheet;
      textbox1.Text = worksheet.Cells["A1"].NumberFormat;
    }
    finally
    {
      workbookView.ReleaseLock();
    }
}
Daniel
  • 5,602
  • 4
  • 33
  • 36
  • Thanks a lot Daniel... Can you also share the some link where I can read more about SpreadSheetGear.. Thanks Again.... – nray Feb 10 '14 at 06:24
  • The SpreadsheetGear site is useful. This is a link to documentation: http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.7.0/. The SpreadsheetGear sample solution, which you should have if you have SSG installed, is helpful for looking at sample code. Otherwise, you can see the samples in SilverLight from this page: http://www.spreadsheetgear.com/support/samples/windowsforms.aspx. – Daniel Feb 10 '14 at 14:02
  • Of course, there is also http://stackoverflow.com/questions/tagged/spreadsheetgear. – Daniel Feb 10 '14 at 14:04