|
書きなおしてみました。
そもそも論になりますが、画像はCellに入れるものではないですよね?
Shapes.AddPicture(@"c:\Penguins.jpg", Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0, 85, 15)
の引数にて、「0,0,85,15」で画像の左右上下の距離を指定してます。
using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
Microsoft.Office.Interop.Excel.Application xApp = null;
Workbook xWb = null;
Worksheet xWs = null;
Range xRg = null;
Shapes xSp = null;
try
{
xApp = new Microsoft.Office.Interop.Excel.Application();
try
{
xWb = xApp.Workbooks.Open(@"c:\testX.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
try
{
xWs = (Worksheet)xWb.ActiveSheet;
try
{
xRg = xWs.get_Range("A1", Type.Missing);
try
{
xSp = xWs.Shapes;
xWs.Shapes.AddPicture(@"c:\Penguins.jpg", Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0, 85, 15);
xApp.Visible = true;
}
finally
{
Marshal.ReleaseComObject(xSp);
}
}
finally
{
Marshal.ReleaseComObject(xRg);
}
}
finally
{
Marshal.ReleaseComObject(xWs);
}
}
finally
{
Marshal.ReleaseComObject(xWb);
}
}
finally
{
Marshal.ReleaseComObject(xApp);
}
|