Copia le forme tra fogli di lavoro con Node.js tramite C++
A volte, hai bisogno di copiare elementi su un foglio di lavoro, ad esempio, immagini, grafici e altri oggetti di disegno, tra fogli di lavoro. Aspose.Cells for Node.js via C++ supporta questa funzione. Grafici, immagini e altri oggetti possono essere copiati con il massimo livello di precisione.
Questo articolo ti fornisce una comprensione dettagliata su come copiare le forme tra i fogli di lavoro.
Copia di un’Immagine da un Foglio di Lavoro a un Altro
Per copiare un’immagine da un foglio di lavoro a un altro, utilizzare il metodo PictureCollection.add(number, number, number, number, Uint8Array) come mostrato nel codice di esempio seguente.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample_picture.xlsx");
// Loads the workbook which contains hidden external links
const workbook = new AsposeCells.Workbook(filePath);
// Get the Picture from the "Picture" worksheet.
const picturesource = workbook.getWorksheets().get("Picture").getPictures().get(0);
// Save Picture to Memory Stream
const ms = picturesource.getData();
// Copy the picture to the Result Worksheet
workbook.getWorksheets().get("Result").getPictures().add(picturesource.getUpperLeftRow(), picturesource.getUpperLeftColumn(), ms, picturesource.getWidthScale(), picturesource.getHeightScale());
// Save the Worksheet
workbook.save(path.join(dataDir, "PictureCopied_out.xlsx"));
Copia di un grafico da un foglio di lavoro a un altro
Il codice seguente dimostra l’uso del metodo ShapeCollection.addCopy(Shape, number, number, number, number) per copiare un grafico da un foglio di lavoro a un altro.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample_chart.xlsx");
// Loads the workbook which contains hidden external links
const workbook = new AsposeCells.Workbook(filePath);
// Get the Chart from the "Chart" worksheet.
const chartsource = workbook.getWorksheets().get("Chart").getCharts().get(0);
const cshape = chartsource.getChartObject();
// Copy the Chart to the Result Worksheet
workbook.getWorksheets().get("Result").getShapes().addCopy(cshape, 20, 0, 2, 0);
// Save the Worksheet
workbook.save(path.join(dataDir, "ChartCopied_out.xlsx"));
Copia controlli e altri oggetti disegnati da un foglio di lavoro a un altro
Per copiare controlli e altri oggetti di disegno, usa il metodo ShapeCollection.addCopy(Shape, number, number, number, number) come mostrato nell’esempio sotto.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample_control.xlsx");
// Open the template file
const workbook = new AsposeCells.Workbook(filePath);
// Get the Shapes from the "Control" worksheet.
const shape = workbook.getWorksheets().get("Control").getShapes();
// Copy the Textbox to the Result Worksheet
workbook.getWorksheets().get("Result").getShapes().addCopy(shape.get(0), 5, 0, 2, 0);
// Copy the Oval Shape to the Result Worksheet
workbook.getWorksheets().get("Result").getShapes().addCopy(shape.get(1), 10, 0, 2, 0);
// Save the Worksheet
workbook.save(path.join(dataDir, "ControlsCopied_out.xlsx"));