This technical tip shows how developers can protect MS Excel workbooks using Aspose.Cells for Cloud API inside their own cloud applications. When a worksheet is protected, user's actions are restricted. For example, you cannot input data. Moreover, you can't insert or delete rows or columns etc. There are mostly 3 protection options in MS Excel, such as protecting Contents, Objects or Scenarios. Protected worksheet doesn't hide or protect sensitive data, so it's different from file encryption. Generally, worksheet protection is suitable for presentation purposes. It prevents the end users from modifying the data, content and formatting in the worksheet. Developers can use Aspose REST API with any language for their choice such as .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
Please take a look over the following code snippet for Protecting Excel Workbooks
string strURI = "http://api.aspose.com/v1.1/cells/input.xls/protection"
string signedURI = Sign(strURI);
//serialize the JSON request content
Protection protection = new Protection();
protection.ProtectionType = protectionType;
protection.Password = password;
string strJSON = JsonConvert.SerializeObject(protection);
Stream responseStream = ProcessCommand(signedURI, "POST", strJSON);
StreamReader reader = new StreamReader(responseStream);
string strResponse = reader.ReadToEnd();
//Parse the json string to JObject
JObject pJSON = JObject.Parse(strResponse);
//Here is the Protection Class used above
public class Protection
{
public Protection()
{
}
public ProtectionType ProtectionType { get; set;}
public string Password { get; set;}
}
/// <summary>
/// Represents Protection Types
/// </summary>
public enum ProtectionType
{
All,
Structure,
Windows,
None
}
AsposeApp.setAppSID("77******-1***-4***-a***-8***********");
AsposeApp.setAppKey("89******************************");
//build URI to Protect Workbook
string strURI = "http://api.aspose.com/v1.1/cells/input.xls/protection";
//sign URI
string signedURI = Sign(strURI);
//serialize the JSON request content
Protection protection = new Protection();
protection.setProtectionType(ProtectionType.All);
protection.setPassword("password");
String strJSON = "";
Gson gson = new Gson();
strJSON = gson.toJson(encryption, Encryption.class);
InputStream responseStream = ProcessCommand(signedURI, "POST", strJSON);
String strResponse = StreamToString(responseStream);
//Following is the Protection Class used above
public class Protection
{
public Protection()
{
}
private ProtectionType ProtectionType;
private String Password;
public ProtectionType getProtectionType(){return ProtectionType;}
public String getPassword(){return Password;}
public void setProtectionType(ProtectionType ProtectionType){ this.ProtectionType=ProtectionType;}
public void setPassword(String Password ){ this.Password=Password;}
}
/// <summary>
/// Represents Protection Types
/// </summary>
public enum ProtectionType
{
All,
Structure,
Windows,
None
}
[PHP Code]
AsposeApp::$appSID = "77******-1***-4***-a***-80**********";
AsposeApp::$appKey = "********************************";
AsposeApp::$outPutLocation = getcwd() . "/Output/";
//build URI to protect workbook
$strURI = 'http://api.aspose.com/v1.1/cells/Sample.xlsx/protection';
//Build JSON to post
$fieldsArray["ProtectionType"] = "all";
$fieldsArray["Password"] = "abc";
$json = json_encode($fieldsArray);
$signedURI = Utils::sign($strURI);
$responseStream = Utils::processCommand($signedURI, "POST", "json", $json);
//Download output file
$strURI = "http://api.aspose.com/v1.1/storage/file/Sample.xlsx";
$signedURI = Utils::sign($strURI);
$responseStream = Utils::processCommand($signedURI, "GET", "", "");
Utils::saveFile($responseStream, AsposeApp::$outPutLocation . "Sample.xlsx");
Overview: Aspose for Cloud
Aspose for Cloud is a cloud-based document generation, conversion and automation platform for developers that offer a unique suite of APIs to work with Word documents, Excel spreadsheets, PowerPoint presentations, PDFs, and email formats and protocols. It supports all features for file processing, document scanning, barcodes creation and recognition, and allows extracting text or images too. You can also work with SaaSpose APIs using REST SDKs that can be called from .NET, Java, PHP and Ruby etc.
Please take a look over the following code snippet for Protecting Excel Workbooks
[C#]
//build URIstring strURI = "http://api.aspose.com/v1.1/cells/input.xls/protection"
string signedURI = Sign(strURI);
//serialize the JSON request content
Protection protection = new Protection();
protection.ProtectionType = protectionType;
protection.Password = password;
string strJSON = JsonConvert.SerializeObject(protection);
Stream responseStream = ProcessCommand(signedURI, "POST", strJSON);
StreamReader reader = new StreamReader(responseStream);
string strResponse = reader.ReadToEnd();
//Parse the json string to JObject
JObject pJSON = JObject.Parse(strResponse);
//Here is the Protection Class used above
public class Protection
{
public Protection()
{
}
public ProtectionType ProtectionType { get; set;}
public string Password { get; set;}
}
/// <summary>
/// Represents Protection Types
/// </summary>
public enum ProtectionType
{
All,
Structure,
Windows,
None
}
[Java Code]
AsposeApp.setAppSID("77******-1***-4***-a***-8***********");
AsposeApp.setAppKey("89******************************");
//build URI to Protect Workbook
string strURI = "http://api.aspose.com/v1.1/cells/input.xls/protection";
//sign URI
string signedURI = Sign(strURI);
//serialize the JSON request content
Protection protection = new Protection();
protection.setProtectionType(ProtectionType.All);
protection.setPassword("password");
String strJSON = "";
Gson gson = new Gson();
strJSON = gson.toJson(encryption, Encryption.class);
InputStream responseStream = ProcessCommand(signedURI, "POST", strJSON);
String strResponse = StreamToString(responseStream);
//Following is the Protection Class used above
public class Protection
{
public Protection()
{
}
private ProtectionType ProtectionType;
private String Password;
public ProtectionType getProtectionType(){return ProtectionType;}
public String getPassword(){return Password;}
public void setProtectionType(ProtectionType ProtectionType){ this.ProtectionType=ProtectionType;}
public void setPassword(String Password ){ this.Password=Password;}
}
/// <summary>
/// Represents Protection Types
/// </summary>
public enum ProtectionType
{
All,
Structure,
Windows,
None
}
[PHP Code]
AsposeApp::$appSID = "77******-1***-4***-a***-80**********";
AsposeApp::$appKey = "********************************";
AsposeApp::$outPutLocation = getcwd() . "/Output/";
//build URI to protect workbook
$strURI = 'http://api.aspose.com/v1.1/cells/Sample.xlsx/protection';
//Build JSON to post
$fieldsArray["ProtectionType"] = "all";
$fieldsArray["Password"] = "abc";
$json = json_encode($fieldsArray);
$signedURI = Utils::sign($strURI);
$responseStream = Utils::processCommand($signedURI, "POST", "json", $json);
//Download output file
$strURI = "http://api.aspose.com/v1.1/storage/file/Sample.xlsx";
$signedURI = Utils::sign($strURI);
$responseStream = Utils::processCommand($signedURI, "GET", "", "");
Utils::saveFile($responseStream, AsposeApp::$outPutLocation . "Sample.xlsx");
Overview: Aspose for Cloud
Aspose for Cloud is a cloud-based document generation, conversion and automation platform for developers that offer a unique suite of APIs to work with Word documents, Excel spreadsheets, PowerPoint presentations, PDFs, and email formats and protocols. It supports all features for file processing, document scanning, barcodes creation and recognition, and allows extracting text or images too. You can also work with SaaSpose APIs using REST SDKs that can be called from .NET, Java, PHP and Ruby etc.
- Homepage of Aspose.Cells for Cloud
- Download Aspose.Cells for Cloud SDKs