Hello everybody,
Do you know how to add background image for Excel file by using C#? If you know, please show me you code, OK? I am bothered with this question for a long time. Thanks very much
Excel Background Image C#
Page 1 of 12 Replies - 425 Views - Last Post: 13 September 2012 - 12:23 AM
Replies To: Excel Background Image C#
#2
Re: Excel Background Image C#
Posted 07 September 2012 - 01:22 AM
Look at below code:
using System;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.SetBackgroundPicture("C:\\csharp-xl-picture.JPG");
//add some text
xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";
xlWorkSheet.Cells[2, 1] = "Adding background in Excel File";
xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlApp);
releaseObject(xlWorkBook);
releaseObject(xlWorkSheet);
MessageBox.Show ("File created !");
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
MessageBox.Show("Unable to release the Object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
}
}
#3
Re: Excel Background Image C#
Posted 13 September 2012 - 12:23 AM
Hi Windina,
Thanks very much. You help me a lot.
Thanks very much. You help me a lot.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|