IronXL 操作指南 新增、提取和移除圖片 How to Add, Extract, and Remove Images from Worksheets Chaknith Bin 更新日期:7月 22, 2025 Download IronXL NuGet 下載 DLL 下載 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English 通過添加圖像,使用者可以用相關的圖形或插圖豐富他們的數據。 移除或刪除圖像簡化了內容編輯和組織。 此外,檢索圖像的能力允許在其他文檔或應用程序中重新使用它們,以及更新現有的圖像。 總體而言,這些功能增強了使用者對圖像的控制,改善了整體用戶體驗,並可在 Excel 工作簿中無縫操作圖像。 快速入門:一次性插入、提取和移除圖像 使用 IronXL 的直觀 API 僅需幾行代碼便可從工作表中添加、獲取和刪除圖像。 此範例顯示如何輕鬆插入圖像,通過 Images 集合訪問它,然後將其移除—完全不觸碰 Interop。 Get started making PDFs with NuGet now: Install IronXL with NuGet Package Manager PM > Install-Package IronXL.Excel Copy and run this code snippet. workSheet.InsertImage("logo.png", 1, 1, 3, 3); workSheet.RemoveImage(1); var firstImage = workSheet.Images[0]; Deploy to test on your live environment Start using IronXL in your project today with a free trial Free 30 day Trial class="hsg-featured-snippet"> 最小化工作流(5 步) 下載 C# 庫以便從電子表格中插入、提取和移除圖像 導入現有的 Excel 文件或創建新的文件 使用 InsertImage 方法將圖像插入工作表 訪問 Images 屬性以提取圖像及其資訊 向 RemoveImage 方法提供 ID 以移除圖像 ## 新增圖片範例 To insert an image into a spreadsheet, utilize the InsertImage method, which supports various image types, such as JPG/JPEG, BMP, PNG, GIF, and TIFF. 您必須指定圖像的左上和右下角以確定其尺寸,尺寸是通過減去列和行的數值計算得到的。 例如,您可以嘗試以下方法: - 對於 1x1 的圖像尺寸: - worksheet.InsertImage("image.gif", 5, 1, 6, 2); - 對於 2x2 的圖像尺寸: - worksheet.InsertImage("image.gif", 5, 1, 7, 3); 請注意生成的圖像 ID 遵循 1, 3, 5, 7 等模式。 ```csharp :path=/static-assets/excel/content-code-examples/how-to/add-remove-extract-worksheet-images-insert.cs ``` ### 輸出電子表格 class="content-img-align-center"> class="center-image-wrapper"> ## 提取圖片範例 To extract images from the selected worksheet, simply access the Images property, which provides a list of all the images contained within the sheet. 從該列表中,您可以執行各種操作,如導出、調整大小、檢索位置和獲取每個圖像的字節數據。 值得注意的是,圖片 ID 遵循奇數模式,以 1、3、5、7 等序列遞增。 ```csharp :path=/static-assets/excel/content-code-examples/how-to/add-remove-extract-worksheet-images-extract.cs ``` class="competitors-section__wrapper-even-1"> 已提取的圖像 圖像尺寸 ## 移除圖片範例 Following the extract images example, you can easily remove any inserted image using its corresponding index number. Simply pass the image's ID number to the RemoveImage method to remove it from the worksheet. ```csharp :path=/static-assets/excel/content-code-examples/how-to/add-remove-extract-worksheet-images-remove.cs ``` 常見問題解答 我如何向 Excel 工作表添加圖片? 要使用 IronXL 將圖片插入 Excel 工作表,請使用 InsertImage 方法。此方法允許您通過定義左上角和右下角來指定圖片尺寸。支援的格式包括 JPG、BMP、PNG、GIF 和 TIFF。 在 Excel 中插入圖片時支援哪些圖片格式? IronXL 支援多種圖片格式用於插入進入 Excel 工作表,包括 JPG/JPEG、BMP、PNG、GIF 和 TIFF。 如何從 Excel 工作表中提取圖片? 要使用 IronXL 從 Excel 工作表中提取圖片,請訪問工作表的 Images 屬性。這提供了所有圖片的列表,讓您可以匯出、調整大小並獲取其位置和字節數據。 我可以從 Excel 工作表中移除圖片嗎? 是的,使用 IronXL,您可以透過 RemoveImage 方法從 Excel 工作表中移除圖片。只需將圖片的 ID 傳遞給此方法即可將其移除。 使用 C# 開始在 Excel 中操作圖片需要哪些條件? 要開始使用 IronXL 在 Excel 中操作圖片,請從 NuGet 下載 IronXL C# 庫並載入現有的 Excel 文件或創建一個新文件。 IronXL 中的圖片 ID 是如何生成的? 在 IronXL 中,圖片 ID 按奇數模式生成,例如 1、3、5、7 等。 是否可以匯出從 Excel 工作表中提取的圖片? 是的,一旦使用 IronXL 的 Images 屬性提取了圖片,它們可以使用 Export 方法匯出為 PNG 等格式。 如何在將圖片插入 Excel 工作表時指定圖片大小? 當使用 IronXL 將圖片插入到 Excel 工作表時,透過 InsertImage 方法提供圖片的左上角和右下角來指定大小。 Chaknith Bin 立即與工程團隊聊天 軟體工程師 Chaknith 在 IronXL 和 IronBarcode 上工作。他對 C# 和 .NET 擁有深厚的專業知識,幫助改進了軟體並支持客戶。他從用戶互動中得到的見解有助於改善產品、文檔和整體體驗。 準備好開始了嗎? Nuget 下載 1,686,155 | 版本: 2025.11 剛剛發布 免費 NuGet 下載 總下載量:1,686,155 查看許可證