문제

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

도움이 되었습니까?

해결책

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();
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top