Proteggi il file Excel Questo REST API indica i file protect
Excel.
RSET API
Copy
POST http://api.aspose.cloud/v3.0/cells/protect
I parametri della richiesta sono:
Nome del parametro
Tipo
Percorso/Stringa di query/Corpo HTTP
Descrizione
file
file
formData
File da caricare
password
corda
domanda
ILSpecifiche OpenAPI definisce un’interfaccia di programmazione accessibile al pubblico e consente di eseguire interazioni REST direttamente da un browser web.
È possibile utilizzare lo strumento da riga di comando cURL per accedere facilmente ai servizi web Aspose.Cells. L’esempio seguente mostra come effettuare chiamate al Cloud API con cURL.
Famiglia Cloud SDK
Utilizzare un SDK è il modo migliore per accelerare lo sviluppo. Un SDK si occupa dei dettagli di basso livello e ti consente di concentrarti sulle attività del progetto. Dai un’occhiata aRepository GitHub per un elenco completo di Aspose.Cells Cloud SDK.
I seguenti esempi di codice mostrano come effettuare chiamate ai servizi Web Aspose.Cells utilizzando vari SDK:
C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Aspose.Cells.Cloud.SDK.Tests.Api.Example
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Aspose.Cells.Cloud.SDK.Request;
using System.Collections.Generic;
using Aspose.Cells.Cloud.SDK.Api;
using System;
using System.IO;
[TestClass]
public class CellsApiExample
{
string CellsCloudClientId ="....";//get from https://dashboard.aspose.cloud/#/applications
string CellsCloudClientSecret="...";//get from https://dashboard.aspose.cloud/#/applications
string localName = "assemblytest.xlsx";
string localName2 = "datasource.xlsx";
string localPath = "D:/TestData/CellsCloud";
[TestCategory("Cells")]
[TestMethod]
public void GetWorksheetAutoFilter()
{
IDictionary<string, Stream> mapFiles = new Dictionary<string, Stream>();
mapFiles.Add(localName, File.OpenRead(localPath +"/"+ localName));
mapFiles.Add(localName, File.OpenRead(localPath +"/"+ localName2));
var protectWorkbookRequest = new ProtectWorkbookRequest()
{
AwaysOpenReadOnly = true,
EncryptWithPassword = "123456"
};
var request = new PostProtectRequest(
file: mapFiles,
protectWorkbookRequest: protectWorkbookRequest,
password: "123456"
);
cellsApi.PostProtect(request);
}
}
}
Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aspose.cloud.cells.api;
import com.aspose.cloud.cells.client.*;
import com.aspose.cloud.cells.model.*;
import com.aspose.cloud.cells.request.*;
import java.io.IOException;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.io.File;
import java.util.HashMap;
public class Example {
private CellsApi api;
public Example(){
try {
api = new CellsApi(
System.getenv("CellsCloudClientId"),
System.getenv("CellsCloudClientSecret"),
"v3.0",
System.getenv("CellsCloudApiBaseUrl")
);
} catch (ApiException e) {
e.printStackTrace();
}
}
public void Run(){
try{
String assemblyTestXlsx = "assemblytest.xlsx";
String dataSourceXlsx = "datasource.xlsx";
PostProtectRequest request = new PostProtectRequest();
ProtectWorkbookRequest protectWorkbookRequest = new ProtectWorkbookRequest();
protectWorkbookRequest.setAwaysOpenReadOnly(true);
protectWorkbookRequest.setEncryptWithPassword("123456");
request.setProtectWorkbookRequest(protectWorkbookRequest);
request.setPassword("123456");
HashMap<String,File> fileMap = new HashMap<String,File>();
fileMap.put(assemblyTestXlsx ,CellsApiUtil.GetFileHolder(assemblyTestXlsx) );
fileMap.put(dataSourceXlsx ,CellsApiUtil.GetFileHolder(dataSourceXlsx) );
request.setFile(fileMap);
this.api.postProtect(request);
} catch (ApiException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php
require_once('vendor\autoload.php');
use \Aspose\Cells\Cloud\Api\CellsApi;
use \Aspose\Cells\Cloud\Request\PostProtectRequest;
$CellsCloudClientId = "...." ; # get from https://dashboard.aspose.cloud/#/applications
$CellsCloudClientSecret = "...."; # get from https://dashboard.aspose.cloud/#/applications
$cellsApi = new CellsApi($CellsCloudClientId , $CellsCloudClientSecret );
$assemblyTestXlsx = "assemblytest.xlsx";
$dataSourceXlsx = "datasource.xlsx";
$mapFiles = array ();
$protectWorkbookRequest = new \Aspose\Cells\Cloud\Model\ProtectWorkbookRequest();
$protectWorkbookRequest->setAwaysOpenReadOnly('true' );
$protectWorkbookRequest->setEncryptWithPassword("123456" );
$mapFiles[$assemblyTestXlsx] = "TestData/".$assemblyTestXlsx;
$mapFiles[$dataSourceXlsx] = "TestData/".$dataSourceXlsx;;
$request = new PostProtectRequest();
$request->setFile( $mapFiles);
$request->setProtectWorkbookRequest( $protectWorkbookRequest);
$request->setPassword( "123456");
$cellsApi->postProtect($request);
Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl'
require 'bundler'
require 'aspose_cells_cloud'
CellsCloudClientId = "...." # get from https://dashboard.aspose.cloud/#/applications
CellsCloudClientSecret = "...." # get from https://dashboard.aspose.cloud/#/applications
@instance = AsposeCellsCloud::CellsApi.new(CellsCloudClientId, CellsCloudClientSecret)
assembly_test_xlsx = 'assemblytest.xlsx'
data_source_xlsx = 'datasource.xlsx'
mapFiles = { }
protectWorkbookRequest = AsposeCellsCloud::ProtectWorkbookRequest.new(:AwaysOpenReadOnly=>true ,:EncryptWithPassword=>'123456' );
mapFiles[assembly_test_xlsx]= ::File.open(File.expand_path("TestData/"+assembly_test_xlsx),"r")
mapFiles[data_source_xlsx]= ::File.open(File.expand_path("TestData/"+data_source_xlsx),"r")
request = AsposeCellsCloud::PostProtectRequest.new(:File=>mapFiles,:protectWorkbookRequest=>protectWorkbookRequest,:password=>'123456');
@instance.post_protect(request);
Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CellsApi,ProtectWorkbookRequest,PostProtectRequest,UploadFileRequest } from "asposecellscloud";
var fs = require('fs');
var path = require('path');
var process = require('process');
const _ = require('asposecellscloud');
const CellsCloudClientId ="....";//get from https://dashboard.aspose.cloud/#/applications
const CellsCloudClientSecret="...";//get from https://dashboard.aspose.cloud/#/applications
const cellsApi = new CellsApi(CellsCloudClientId, CellsCloudClientSecret);
var remoteFolder = "TestData/In"
var localPath = "TestData/CellsCloud/"
describe('example', function(){
it("should call successfully" , function(){
var assemblyTestXlsx = "assemblytest.xlsx"
var dataSourceXlsx = "datasource.xlsx"
var mapFiles = {};
var protectWorkbookRequest = new ProtectWorkbookRequest();
protectWorkbookRequest.awaysOpenReadOnly = true ;
protectWorkbookRequest.encryptWithPassword = "123456" ;
mapFiles[assemblyTestXlsx]= fs.createReadStream(localPath +assemblyTestXlsx) ;
mapFiles[dataSourceXlsx]= fs.createReadStream(localPath +dataSourceXlsx) ;
var request = new PostProtectRequest();
request.file = mapFiles;
request.protectWorkbookRequest = protectWorkbookRequest;
request.password = "123456";
return cellsApi.postProtect(request)
});
Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os
import sys
from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.models import *
from asposecellscloud.requests import *
CellsCloudClientId ='....' # get from https://dashboard.aspose.cloud/#/applications
CellsCloudClientSecret='....' # get from https://dashboard.aspose.cloud/#/applications
api = CellsApi(CellsCloudClientId,CellsCloudClientSecret)
request = PostProtectRequest( {'assemblytest.xlsx':'assemblytest.xlsx'}, protectWorkbookRequest,password= '123456')
api.post_protect(request)
Perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use lib 'lib';
use strict;
use warnings;
use File::Slurp;
use MIME::Base64;
use AsposeCellsCloud::CellsApi;
my $CellsCloudClientId = "...."; # get from https://dashboard.aspose.cloud/#/applications
my $CellsCloudClientSecret = "...."; # get from https://dashboard.aspose.cloud/#/applications
my $config = AsposeCellsCloud::Configuration->new( client_id => $CellsCloudClientId , client_secret => $CellsCloudClientSecret );
my $instance = AsposeCellsCloud::CellsApi->new(AsposeCellsCloud::ApiClient->new( $config));
my $assemblyTestXlsx = 'assemblytest.xlsx';
my $dataSourceXlsx = 'datasource.xlsx';
my $mapFiles = {};
my $protect_workbook_request = AsposeCellsCloud::Object::ProtectWorkbookRequest->new();
$protect_workbook_request->{aways_open_read_only} = 'true' ;
$protect_workbook_request->{encrypt_with_password} = '123456' ;
$mapFiles->{$assemblyTestXlsx}= "TestData/".$assemblyTestXlsx ;
$mapFiles->{$dataSourceXlsx}= "TestData/".$dataSourceXlsx ;
my $request = AsposeCellsCloud::Request::PostProtectRequest->new();
$request->{file} = $mapFiles;
$request->{protect_workbook_request} = $protect_workbook_request;
$request->{password} = '123456';
$instance->post_protect(request=> $request);
Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main
import (
. "github.com/aspose-cells-cloud/aspose-cells-cloud-go/v25"
)
func main() {
CellsCloudClientId := "...." // get from https://dashboard.aspose.cloud/#/applications
CellsCloudClientSecret := "...." // get from https://dashboard.aspose.cloud/#/applications
instance := NewCellsApiService(CellsCloudClientId, CellsCloudClientSecret)
assemblyTestXlsx := "assemblytest.xlsx"
dataSourceXlsx := "datasource.xlsx"
var mapFiles map[string]string
mapFiles = make(map[string]string)
var protectWorkbookRequest = new(ProtectWorkbookRequest)
protectWorkbookRequest.AwaysOpenReadOnly = true
protectWorkbookRequest.EncryptWithPassword = "123456"
mapFiles[assemblyTestXlsx] = assemblyTestXlsx
mapFiles[dataSourceXlsx] = dataSourceXlsx
request := new(PostProtectRequest)
request.File = mapFiles
request.ProtectWorkbookRequest = protectWorkbookRequest
request.Password = "123456"
_, httpResponse, err := instance.PostProtect(request)
if err != nil {
println(err.Error())
} else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
println("Fail")
}
}