ワークシート間でシェイプをコピーする
時々、ワークシート上の要素(例えば、画像、グラフ、その他の図形オブジェクト)を他のワークシート間でコピーする必要があります。Aspose.Cells はこの機能をサポートしています。チャート、画像、その他のオブジェクトは高度な精度でコピーすることができます。
この記事では、ワークシート間でシェイプをコピーする方法について詳しく説明します。
ワークシート間での画像のコピー
ワークシート間での画像のコピーには、以下のサンプルコードに示すように Worksheet.Pictures.Add メソッドを使用します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the template file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Get the Picture from the "Picture" worksheet. | |
Aspose.Cells.Drawing.Picture picturesource = workbook.Worksheets["Picture"].Pictures[0]; | |
// Save Picture to Memory Stream | |
MemoryStream ms = new MemoryStream(picturesource.Data); | |
// Copy the picture to the Result Worksheet | |
workbook.Worksheets["Result"].Pictures.Add(picturesource.UpperLeftRow, picturesource.UpperLeftColumn, ms, picturesource.WidthScale, picturesource.HeightScale); | |
// Save the Worksheet | |
workbook.Save(dataDir + "PictureCopied_out.xlsx"); |
ワークシート間でのグラフのコピー
次のコードは、Worksheet.Shapes.AddCopy メソッドを使用して、ワークシート間でのチャートのコピーを示しています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template file | |
Workbook workbook = new Workbook(dataDir + "sample.xlsx"); | |
// Get the Chart from the "Chart" worksheet. | |
Aspose.Cells.Charts.Chart chartsource = workbook.Worksheets["Chart"].Charts[0]; | |
Aspose.Cells.Drawing.ChartShape cshape = chartsource.ChartObject; | |
// Copy the Chart to the Result Worksheet | |
workbook.Worksheets["Result"].Shapes.AddCopy(cshape, 20, 0, 2, 0); | |
// Save the Worksheet | |
workbook.Save(dataDir + "ChartCopied_out.xlsx"); |
ワークシート間でのコントロールおよびその他の図形オブジェクトのコピー
コントロールやその他の図形オブジェクトをコピーするには、次の例に示すように Worksheet.Shapes.AddCopy メソッドを使用します。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template file | |
Workbook workbook = new Workbook(dataDir + "sample2.xlsx"); | |
// Get the Shapes from the "Control" worksheet. | |
Aspose.Cells.Drawing.ShapeCollection shape = workbook.Worksheets["Control"].Shapes; | |
// Copy the Textbox to the Result Worksheet | |
workbook.Worksheets["Result"].Shapes.AddCopy(shape[0], 5, 0, 2, 0); | |
// Copy the Oval Shape to the Result Worksheet | |
workbook.Worksheets["Result"].Shapes.AddCopy(shape[1], 10, 0, 2, 0); | |
// Save the Worksheet | |
workbook.Save(dataDir + "ControlsCopied_out.xlsx"); |