Copia contenidos y formatos de otra hoja de trabajo. Este REST API indica copy a worksheet
y se guarda con un nuevo nombre en el mismo libro.
RSET API
Copy
POST http://api.aspose.cloud/v3.0/cells/{ name} /worksheets/{ sheetName} /copy
Los parámetros de la solicitud son:
Nombre del parámetro
Tipo
Ruta/Cadena de consulta/Cuerpo HTTP
Descripción
nombre
cadena
camino
nombre de la hoja
cadena
camino
fuenteHoja
cadena
consulta
opciones
cuerpo
fuenteLibro de trabajo
cadena
consulta
Carpeta de origen
cadena
consulta
carpeta
cadena
consulta
nombredealmacenamiento
cadena
consulta
nombre del almacenamiento.
ElEspecificación de API abierta define una interfaz de programación de acceso público y le permite realizar interacciones REST directamente desde un navegador web.
Puede utilizar la herramienta de línea de comandos cURL para acceder fácilmente a los servicios web Aspose.Cells. El siguiente ejemplo muestra cómo realizar llamadas a Cloud API con cURL.
Familia de SDK en la nube
Usar un SDK es la mejor manera de acelerar el desarrollo. Un SDK se encarga de los detalles de bajo nivel y le permite concentrarse en las tareas de su proyecto. Por favor revisa elrepositorio de GitHub para obtener una lista completa de Aspose.Cells SDK de nube.
Los siguientes ejemplos de código demuestran cómo realizar llamadas a servicios web Aspose.Cells utilizando varios SDK:
C#
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells-cloud/aspose-cells-cloud-dotnet/
namespace Aspose.Cells.Cloud.SDK.Example
{
using Aspose.Cells.Cloud.SDK.Api;
using Aspose.Cells.Cloud.SDK.Request;
using System;
public partial class CellsApiExample
{
public void PostCopyWorksheetExample()
{
CellsApi cellsApi = new CellsApi(Environment.GetEnvironmentVariable("CellsCloudTestClientId"), Environment.GetEnvironmentVariable("CellsCloudTestClientSecret"));
PostCopyWorksheetRequest request = new PostCopyWorksheetRequest { name = "Book1.xlsx", sheetName = "Sheet1" , sourceWorkbook ="myDocument.xlsx" , sourceSheet="Sheet3", sourceFolder ="TestData/In", folder = "TestData/In" };
cellsApi.PostCopyWorksheet(request);
}
}
}
// Obsolete
//CellsWorksheetsApi instance = new CellsWorksheetsApi(GetConfiguration());
//string name = "NewCopy.xlsx";
//string sheetName = "Sheet5";
//string sourceSheet = "Sheet6";
//CopyOptions options = new CopyOptions();
//options.ColumnCharacterWidth = true;
//string sourceWorkbook = "Book1.xlsx";
//string sourceFolder = null;
//string folder = null;
//UpdateDataFile(folder, name);
//UpdateDataFile(folder, sourceWorkbook);
//var response = instance.CellsWorksheetsPostCopyWorksheet(name, sheetName, sourceSheet, options, sourceWorkbook, sourceFolder, folder);
Java
This file contains 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 remoteFolder = "TestData/In";
String localName = "Book1.xlsx";
String remoteName = "Book1.xlsx";
String name = "NewCopy.xlsx";
UploadFileRequest uploadFileRequest = new UploadFileRequest();
uploadFileRequest.setPath( remoteFolder + "/" + remoteName );
uploadFileRequest.setStorageName( "");
HashMap<String,File> files = new HashMap<String,File>();
files.put( localName , new File(localName ));
uploadFileRequest.setUploadFiles(files);
api.uploadFile(uploadFileRequest);
CopyOptions options = new CopyOptions();
options.setCopyNames(true);
PostCopyWorksheetRequest request = new PostCopyWorksheetRequest();
request.setName(name);
request.setSheetName("sheet1");
request.setSourceSheet("sheet2");
request.setOptions(options);
request.setSourceWorkbook(localName);
request.setSourceFolder(remoteFolder);
request.setFolder(remoteFolder);
request.setStorageName("");
CellsCloudResponse response = api.postCopyWorksheet(request);
} catch (ApiException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
}
}
PHP
This file contains 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
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Cloud
<?php
require_once realpath(__DIR__ . '/..') . '/vendor/autoload.php';
require_once realpath(__DIR__ . '/..') . '/Utils.php';
use Aspose\Cells\CellsApi;
use Aspose\Cells\AsposeApp;
class Worksheet {
public $cells;
public function __construct() {
AsposeApp::$appSID = Utils::appSID;
AsposeApp::$apiKey = Utils::apiKey;
$this->cells = new CellsApi();
}
public function postCopyWorksheet() {
// Upload file to Aspose Cloud Storage
$fileName = "Book1.xlsx";
Utils::uploadFile($fileName);
$body = '{
"CopyOptions": {
"CopyNames": "true"
}
}';
$result = $this->cells->PostCopyWorksheet($name=$fileName, $sheetName="NewSheet", $sourceSheet="Sheet3", $folder = null, $storage = null, $body);
print_r($result);
}
}
$worksheet = new Worksheet();
$worksheet->postCopyWorksheet();
?>
Ruby
This file contains 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
# For complete examples and data files, please go to https://github.com/aspose-cells-cloud/aspose-cells-cloud-ruby
require 'aspose_cells_cloud'
class Worksheet
include AsposeCellsCloud
def initialize
#Get client_id and client_secret from https://cloud.aspose.com
@instance = AsposeCellsCloud::CellsApi.new($client_id,$client_secret,$api_version,$baseurl)
end
# Copy worksheet
def post_copy_worksheet
name = 'NewCopy.xlsx'
sheet_name = $SHEET5
source_sheet = $SHEET6
options = AsposeCellsCloud::CopyOptions.new({:ColumnCharacterWidth=>true})
source_workbook = $BOOK1
source_folder = $TEMPFOLDER
folder = $TEMPFOLDER
result = @instance.upload_file( folder+"/"+name, ::File.open(File.expand_path("data/"+name),"r") {|io| io.read(io.size) })
expect(result.uploaded.size).to be > 0
result = @instance.upload_file( folder+"/"+source_workbook, ::File.open(File.expand_path("data/"+source_workbook),"r") {|io| io.read(io.size) })
expect(result.uploaded.size).to be > 0
result = @instance.cells_worksheets_post_copy_worksheet(name, sheet_name, source_sheet,{ :options=>options, :source_workbook=>source_workbook, :source_folder=>source_folder,:folder=>folder})
expect(result.code).to eql(200)
end
end
worksheet = Worksheet.new()
puts worksheet.post_copy_worksheet
Python
This file contains 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
# For complete examples and data files, please go to https://github.com/aspose-cells-cloud/aspose-cells-cloud-python
import os
from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.models import *
from asposecellscloud.requests import *
api = CellsApi(os.getenv('CellsCloudClientId'),os.getenv('CellsCloudClientSecret'),"v3.0",os.getenv('CellsCloudApiBaseUrl'))
options = CopyOptions(column_character_width= True )
request = PostCopyWorksheetRequest( 'Book1.xlsx', 'Sheet151', 'Sheet6', options ,source_workbook= '',source_folder= '',folder= 'PythonTest',storage_name= '')
api.post_copy_worksheet(request)
Node.js
This file contains 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
const { CellsApi, UploadFileRequest, CellsWorksheets_PostCopyWorksheetRequest, CopyOptions } = require("asposecellscloud");
const clientId = process.env.CellsCloudClientId;
const clientSecret = process.env.CellsCloudClientSecret;
const ApiURL = process.env.CellsCloudApiBaseUrl;
const fs = require('fs');
const path = require('path');
const cellsApi = new CellsApi(clientId, clientSecret,"v3.0",ApiURL);
const localPath = "D:/aspose-cells-cloud-node/TestData/"
const filename = "Book1.xlsx";
const data =fs.createReadStream(path.join(localPath, filename));
const req = new UploadFileRequest({
path: "Temp/" + filename,
file: data
});
cellsApi.uploadFile(req)
.then((result) => {
const req = new CellsWorksheets_PostCopyWorksheetRequest();
req.name = filename1;
req.sheetName = "Sheet5";
req.sourceSheet = "Sheet6";
req.options = new CopyOptions();
req.options.columnCharacterWidth = true;
req.sourceWorkbook = filename;
req.sourceFolder = "Temp";
req.folder = "Temp";
cellsApi.cellsWorksheetsPostCopyWorksheet(req)
.then((result) => {
console.log("successful")
}).catch((error) => {
console.error('Unhandled Promise Rejection:', error);
})
})
Android
Swift
Perl
This file contains 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
# For complete examples and data files, please go to https://github.com/aspose-cells-cloud/aspose-cells-cloud-perl/
use strict;
use warnings;
use utf8;
use File::Slurp;
use MIME::Base64;
use AsposeCellsCloud::CellsApi;
my $config = AsposeCellsCloud::Configuration->new( client_id => $ENV{'ProductClientId'}, client_secret => $ENV{'ProductClientSecret'});
my $instance = AsposeCellsCloud::CellsApi->new(AsposeCellsCloud::ApiClient->new( $config));
my $remoteFolder = 'TestData/In';
my $remoteName = 'Book1.xlsx';
my $options = AsposeCellsCloud::Object::CopyOptions->new();
$options->{column_character_width} = 'true' ;
my $request = AsposeCellsCloud::Request::PostCopyWorksheetRequest->new();
$request->{name} = $remoteName;
$request->{sheet_name} = 'Sheet15';
$request->{source_sheet} = 'Sheet6';
$request->{options} = $options;
$request->{source_workbook} = '';
$request->{source_folder} = '';
$request->{folder} = $remoteFolder;
$request->{storage_name} = '';
my $result = $api->post_copy_worksheet(request=> $request);
Go