Définir l'image d'arrière-plan d'une feuille de calcul

Définition d’une image d’arrière-plan sur une feuille de calcul

Pour appliquer une image d’arrière-plan à une feuille de calcul :

  1. Créez un classeur et accédez à la feuille à laquelle vous souhaitez appliquer une image d’arrière-plan.
  2. Appliquez l’image d’arrière-plan.
  3. Enregistrez le classeur.

Les exemples de code qui suivent montrent comment procéder en premier avecVSTO , en utilisant C# ou Visual Basic, puis avecAspose.Cells for .NET, en utilisant à nouveau C# ou Visual Basic.

Les exemples de code de cet article créent une feuille de calcul avec une image d’arrière-plan répétitive, comme celle de la capture d’écran ci-dessous.

Un arrière-plan a été défini pour la feuille de calcul.

tâche : image_autre_texte

Définition des images d’arrière-plan avec VSTO

C#

 .......



using Microsoft.VisualStudio.Tools.Applications.Runtime;

using Excel = Microsoft.Office.Interop.Excel;

using Office = Microsoft.Office.Core;

using System.Reflection;

.......

//Instantiate the Application object.

Excel.ApplicationClass ExcelApp = new Excel.ApplicationClass();

//Add a Workbook.

Excel.Workbook objBook = ExcelApp.Workbooks.Add(System.Reflection.Missing.Value);

//Get the First sheet.

Excel.Worksheet objSheet = (Excel.Worksheet)objBook.Sheets["Sheet1"];

//Set a background picture for the sheet.

objSheet.SetBackgroundPicture("e:\\test\\school.jpg");

//Save the excel file.

objBook.SaveCopyAs("c:\\BackgroundPicBook.xls");

//Quit the Application.

ExcelApp.Quit();

Réglage des images d’arrière-plan avec Aspose.Cells for .NET

C#

 .......

using Aspose.Cells;

.......

//Instantiate a new Workbook.

Workbook workbook = new Workbook();

//Get the first worksheet. 

Worksheet sheet = workbook.Worksheets[0];



//Define a string variable to store the image path.

string ImageUrl = @"e:\test\school.jpg";

//Get the picture into the streams.

FileStream fs = File.OpenRead(ImageUrl);

//Define a byte array.

byte[]imageData = new Byte[fs.Length];

//Obtain the picture into the array of bytes from streams.

fs.Read(imageData, 0, imageData.Length);

//Close the stream.

fs.Close();



//Set the background image for the sheet.

sheet.SetBackground(imageData);



//Save the excel file.

workbook.Save(@"c:\BackgroundPicBook.xls");