Using UI for ASP.NET AJAX Q1 2016, with VS 2013. My situation is below:
1a) Exporting SQL Data to users weekly basis into an Excel File via SSIS Package. Works Fine...
1b) Super User add/edit's some Cell (Not row/column) data elements in that Excel File based on data from a 3rd Party.
Now Super user want to Publish that Excel Data into Web just as read only to other user's.
My intention:
2a) How to hide toolbar, formula bar, Making Cells/Formula's read only and just show export to Excel Button using below Prototype.
2b) Possible when exporting to Excel, instead of Save/Save as (in #2a), allow open/save/cancel like below RadGrid Demo. 99% of the time, user will prefer to open the file prior to save it.
Thanks a lot.
gc_0620
8 Answers, 1 is accepted
You can hide the ToolBar and the formula bar on the client with jQuery:
$telerik.$(
".rssToolbarWrapper"
).hide();
$telerik.$(
".rssFormulaBar"
).hide();
You can prevent the user from editing a cell (or a range of cells) through the SpreadsheetRange object's set_enabled(false) method.
As for the Open file option when using the RadClientExportManager to export the Spreadsheet, it is available in Chrome and Firefox and it is not available in IE11.
Regards,
Ivan Danchev
Telerik
Thanks Ivan,
Appreciate for your solution. I have some other issues that I need some help:
1) Disallow users to Delete any Column or Rows. Currently I can do it via right mouse click.
2) Disallow users to add new sheet or delete existing sheet or sheet's.
3) Possible to expand the column length like one can do it in regular excel file (via dragging its header)?
As per Super user (creator of the original file), regular users must not perform above tasks outlined in item #1 and #2.
If regular user's want to manipulate data, they should export existing file into Excel and make changes there.
Please refer to attached for my intention.
Thanks again
gc_0620
Ivan, if you think disallow/disable user's to perform both options (i.e. Hide/Delete) in any columns or rows (item #1 in previous post), that is fine.
gc_0620
1. Preventing the user from deleting rows and columns can be done by canceling the ContextMenu's OnClientItemClicking event:
<
telerik:RadSpreadsheet
runat
=
"server"
ID
=
"RadSpreadsheet1"
>
<
ContextMenus
>
<
RowHeaderContextMenu
OnClientItemClicking
=
"OnClientItemClicking"
>
</
RowHeaderContextMenu
>
<
ColumnHeaderContextMenu
OnClientItemClicking
=
"OnClientItemClicking"
>
</
ColumnHeaderContextMenu
>
</
ContextMenus
>
</
telerik:RadSpreadsheet
>
function
OnClientItemClicking(sender, eventArgs) {
var
selectedItemValue = eventArgs.get_item().get_value();
if
(selectedItemValue ===
"CommandDeleteRow"
|| selectedItemValue ===
"CommandDeleteColumn"
) {
eventArgs.set_cancel(
true
);
}
}
3. Dragging to resize a column is supported.
Regards,
Ivan Danchev
Telerik
Thanks Ivan,
Your solution works. But I am seeing attached error message in Visual Studio. What I am doing wrong? Am I missing something? But the result set works based on your suggestions as well as there are no error's after rebuilding the solution.
Codes are below. Please advice.
Thanks
gc_-620
---------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<
html
xmlns
=
'http://www.w3.org/1999/xhtml'
>
<
head
runat
=
"server"
>
<
title
>Telerik ASP.NET Example</
title
>
<
script
type
=
"text/javascript"
src
=
"scripts.js"
></
script
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager1"
/>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function exportFile() {
var spreadsheet = $find("<%= RadSpreadsheet1.ClientID %>");
spreadsheet.saveAsExcel();
}
function OnClientItemClicking(sender, eventArgs) {
var selectedItemValue = eventArgs.get_item().get_value();
if (selectedItemValue === "CommandDeleteRow" || selectedItemValue === "CommandDeleteColumn") {
alert("Prohibited !!!");
eventArgs.set_cancel(true);
}
}
</
script
>
</
telerik:RadCodeBlock
>
<
div
>
<
telerik:RadButton
runat
=
"server"
ID
=
"btnExport"
AutoPostBack
=
"false"
OnClientClicked
=
"exportFile"
Text
=
"Export to Excel File"
></
telerik:RadButton
>
<
br
/>
<
telerik:RadSpreadsheet
runat
=
"server"
ID
=
"RadSpreadsheet1"
>
<
ContextMenus
>
<
RowHeaderContextMenu
OnClientItemClicking
=
"OnClientItemClicking"
>
</
RowHeaderContextMenu
>
<
ColumnHeaderContextMenu
OnClientItemClicking
=
"OnClientItemClicking"
>
</
ColumnHeaderContextMenu
>
</
ContextMenus
>
<
Toolbar
>
<
telerik:SpreadsheetToolbarTab
Text
=
"Home"
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"Undo"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"Redo"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"Paste"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"Cut"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"Copy"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"Bold"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"Italic"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"Underline"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"FontFamily"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"FontSize"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"BackgroundColor"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"TextColor"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"BorderType"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"BorderColor"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"HorizontalAlignment"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"VerticalAlignment"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetToolbarGroup
>
<
telerik:SpreadsheetTool
Name
=
"TextWrap"
ShowLabel
=
"false"
/>
<
telerik:SpreadsheetTool
Name
=
"MergeCells"
ShowLabel
=
"false"
/>
</
telerik:SpreadsheetToolbarGroup
>
</
telerik:SpreadsheetToolbarTab
>
</
Toolbar
>
</
telerik:RadSpreadsheet
>
</
div
>
</
form
>
</
body
>
</
html
>
________
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
public
partial
class
_Default : System.Web.UI.Page
{
private
const
string
ProviderSessionKey =
"Telerik.Web.Examples.SpreadSheet.ContextMenu.DefaultCS"
;
protected
void
Page_Init(
object
sender, EventArgs e)
{
SpreadsheetDocumentProvider provider;
if
((Session[ProviderSessionKey] ==
null
) || (!IsPostBack))
{
provider =
new
SpreadsheetDocumentProvider(Server.MapPath(
"~/App_Data/Spreadsheet-ToolbarDemo.xlsx"
));
Session[ProviderSessionKey] = provider;
}
else
{
provider = (SpreadsheetDocumentProvider)Session[ProviderSessionKey];
}
RadSpreadsheet1.Provider = provider;
}
}
We can confirm that the error in the Designer when ContextMenus are declared is a bug. We logged it and will fix it in one of our next releases.
You can track the bug's status on our Feedback Portal and vote/rate it.
As a token of gratitude for reporting the bug I updated your Telerik points.
Regards,
Ivan Danchev
Telerik
Thanks Ivan, appreciate for your help. Please keep us posted when this issue is resolved.
Best Regards
gc_0620
We will let you know when the bug is fixed and this will also be reflected in its item in the Feedback Portal.
Regards,
Ivan Danchev
Telerik