We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Does background image exist

Hi guys,

I have a question for you.

I used the following code to add the background image to the excel file:

Workbook workbook = new Workbook();
FileStream fs = File.OpenRead(@“C:\Temp\watermark.jpg”);

byte[] imageData = new byte[fs.Length];
fs.Read(imageData, 0, imageData.Length);

workbook.Worksheets[0].SetBackground(imageData);
workbook.Save(@“C:\Temp\ExcelWithBackground.xls”);

How can I define that my excel file contains background image that I added? Or may be some metadata/flag exists in the excel file that are not visible for user and I can write or read it programmatically?

For example for word docs I can insert some watermark and find it by Name.

Shape watermark = new Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText);
watermark.Name = string.Format(“WaterMark_{0}”, Guid.NewGuid()); …

if (shape.Name.Contains(“WaterMark”))
shape.Remove();

Thanks,

Alex

Hi Alex,

You can use Worksheet.setBackground(null) method to remove the background image of the worksheet. Following code snippet will help you.

Code snippet:
//Instantiate a new Workbook
Workbook workbook = new Workbook();
//Open an existing excel file
workbook.open("e:\\files\\Book_backimage.xls");
Worksheet sheet = workbook.getWorksheets().getSheet(0);

//Remove the background image for the sheet.
sheet.setBackground(null);

//Save the excel file
workbook.save("e:\\files\\outBackImageSheet.xls");


If you face any issue please feel free to contact us.


Thank you,

Hi guys,

My question was not how to remove background from excel file. My question was how to define if the background with "someName" exist in excel file.

Please read my question in the first post.

Thanks,

Alex

Hi Alex,

We do not support to parse the background image of the template file. We only support preserving them and saving it back to the file. As there is only one background image of the worksheet ,so there is no "name" setting available, you can only replace it.

Thanks,