using Microsoft.Office.Interop.Excel;
Application excelApp = new Application();
Workbook workbook = excelApp.Workbooks.Open("example.xlsx");
Worksheet worksheet = workbook.Worksheets[1];
Range range = worksheet.Range["A1"];//取得儲存格的長寬
Bitmap originalImage = new Bitmap(filePath);//取得圖片的長寬
int newWidth = originalImage.Width;
int newHeight = originalImage.Height;
worksheet.Shapes.AddPicture("image.jpg", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, range.Left, range.Top, range.Width, range.Height);//(路徑,MSO,靠左座標,靠上座標,寬,高)
workbook.Save();
workbook.Close();
excelApp.Quit();
沒有留言:
張貼留言