|
| 1 | +--- |
| 2 | +title: Hide Toolbar, Formula Bar, or Sheet Bar in Spreadsheet |
| 3 | +description: Learn how to hide the toolbar, formula bar, and sheet bar in theTelerik Spreadsheet component for Blazor. |
| 4 | +type: how-to |
| 5 | +page_title: How to Change the Visibility of Spreadsheet Parts in Blazor |
| 6 | +slug: spreadsheet-kb-hide-toolbar-formula-sheet-bar |
| 7 | +tags: spreadsheet, blazor, toolbar, formula bar, sheet bar, css, visibility |
| 8 | +res_type: kb |
| 9 | +ticketid: 1676073 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>Spreadsheet for Blazor</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | +## Description |
| 24 | + |
| 25 | +I want to display only the spreadsheet portion and hide the toolbar, formula bar, and sheet bars in the Spreadsheet component. |
| 26 | + |
| 27 | +## Solution |
| 28 | + |
| 29 | +To change the visibility of the toolbar, formula bar, and sheet bar in the Spreadsheet for Blazor, apply conditional CSS classes to hide the respective components. |
| 30 | + |
| 31 | +>caption This approach is applicable only if the app can trust its users not to show back the tools through the browser console. |
| 32 | +
|
| 33 | +````RAZOR |
| 34 | +<style> |
| 35 | + .hide-header .k-spreadsheet-header { |
| 36 | + display: none; |
| 37 | + } |
| 38 | +
|
| 39 | + .hide-action-bar .k-spreadsheet-action-bar { |
| 40 | + display: none; |
| 41 | + } |
| 42 | +
|
| 43 | + .hide-sheets-bar .k-spreadsheet-sheets-bar { |
| 44 | + display: none; |
| 45 | + } |
| 46 | +</style> |
| 47 | +
|
| 48 | +<label for="showHeader"><TelerikCheckBox Id="showHeader" @bind-Value="@ShowHeader" />Show Header</label> |
| 49 | +<label for="showActionBar"><TelerikCheckBox Id="showActionBar" @bind-Value="@ShowActionBar" />Show Action Bar</label> |
| 50 | +<label for="showSheetsBar"><TelerikCheckBox Id="showSheetsBar" @bind-Value="@ShowSheetsBar" />Show Sheets Bar</label> |
| 51 | +
|
| 52 | +<TelerikSpreadsheet Data="@SpreadsheetData" |
| 53 | + Class="@SpreadsheetClass"> |
| 54 | +</TelerikSpreadsheet> |
| 55 | +
|
| 56 | +@code { |
| 57 | + private byte[]? SpreadsheetData { get; set; } |
| 58 | + private bool ShowHeader { get; set; } |
| 59 | + private bool ShowActionBar { get; set; } |
| 60 | + private bool ShowSheetsBar { get; set; } |
| 61 | +
|
| 62 | + // Dynamically generate the class based on the checkbox states |
| 63 | + private string SpreadsheetClass => $"{(ShowHeader ? "" : "hide-header")} " + |
| 64 | + $"{(ShowActionBar ? "" : "hide-action-bar")} " + |
| 65 | + $"{(ShowSheetsBar ? "" : "hide-sheets-bar")}"; |
| 66 | +
|
| 67 | + protected override async Task OnInitializedAsync() |
| 68 | + { |
| 69 | + SpreadsheetData = Convert.FromBase64String(SampleExcelFile); |
| 70 | +
|
| 71 | + // Or, load a file from your file system. |
| 72 | + // Specify the full File namespace or use namespace aliases |
| 73 | + // to avoid ambiguous reference with the Telerik SVG icon File. |
| 74 | + // FileData = System.IO.File.ReadAllBytes("C:\\Documents\\MyWorkbook.xlsx"); |
| 75 | +
|
| 76 | + await base.OnInitializedAsync(); |
| 77 | + } |
| 78 | +
|
| 79 | + private const string SampleExcelFile = ""; |
| 80 | +} |
| 81 | +```` |
| 82 | + |
| 83 | +## See Also |
| 84 | + |
| 85 | +* [Spreadsheet Overview](slug://spreadsheet-overview) |
0 commit comments