تعيين صورة الخلفية لورقة العمل

تعيين صورة خلفية في ورقة عمل

لتطبيق صورة خلفية على جدول بيانات:

  1. قم بإنشاء مصنف والوصول إلى الورقة التي تريد تطبيق صورة خلفية عليها.
  2. قم بتطبيق صورة الخلفية.
  3. احفظ المصنف.

توضح نماذج التعليمات البرمجية التالية كيفية القيام بذلك أولاً باستخدامVSTO ، باستخدام C# أو Visual Basic ، ثم معAspose.Cells for .NET، مرة أخرى باستخدام إما C# أو Visual Basic.

تُنشئ أمثلة الكود في هذه المقالة ورقة عمل بها صورة خلفية متكررة ، مثل تلك الموجودة في لقطة الشاشة أدناه.

تم تعيين خلفية لورقة العمل.

ما يجب القيام به: image_بديل_نص

ضبط صور الخلفية باستخدام 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();

ضبط صور الخلفية مع 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");