You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过代码在SpreadsheetGear Workbook Explorer中调出并高亮内置页面设置对话框标签

How to Launch the Built-in Page Setup Dialog with the Page Setup Tab Highlighted in SpreadsheetGear Workbook Explorer

I get it—you’ve seen the official SpreadsheetGear.exe pull off this handy feature, but the sample code doesn’t cover it. Let’s break down exactly how to build this into your project.

Core Concept

The SpreadsheetGear.Windows.Forms.WorkbookView control has a built-in method to launch the Page Setup dialog, and you can specify which tab gets focused by default using the PageSetupDialogTab enumeration. This is exactly how the official app handles it.

Step-by-Step Implementation

  1. Confirm your WorkbookView is set up
    Make sure your form has a WorkbookView instance (we’ll use workbookView1 as an example) linked to a valid workbook.

  2. Call the targeted dialog method
    Use the overload of ShowPageSetupDialog that accepts a PageSetupDialogTab parameter. To highlight the main Page Setup tab directly, pass PageSetupDialogTab.PageSetup.

Here’s a complete C# WinForms code snippet you can adapt:

using SpreadsheetGear.Windows.Forms;

// Trigger this from a button click, menu item, etc.
private void OpenPageSetupToTargetTab()
{
    // Guard clause: Ensure there's an active worksheet to apply settings to
    if (workbookView1.ActiveWorksheet != null)
    {
        // Launch the dialog with the Page Setup tab pre-selected
        workbookView1.ShowPageSetupDialog(PageSetupDialogTab.PageSetup);
    }
}

Quick Extra Tips

  • Other tab options: If you need to focus different tabs later, use values like PageSetupDialogTab.Margins, PageSetupDialogTab.HeaderFooter, or PageSetupDialogTab.Sheets from the same enumeration.
  • Context check: The dialog applies settings to the currently active worksheet, so the null check ensures you don’t run into errors if no sheet is selected.
  • Version compatibility: This works with all modern SpreadsheetGear for .NET versions that include WinForms controls (v8 and later).

That’s all it takes—this will replicate the exact behavior you see in the official SpreadsheetGear.exe, launching the dialog directly to the highlighted Page Setup tab.

内容的提问来源于stack exchange,提问作者Rajendra K Karki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:51:49