Preface
When using the npoi plugin for batch import in .net, the image data in excel is obtained and stored in the collection.
Steps to use
1. Define the class PictureData
The code is as follows:
public class PictureData { public byte[] Data { get; set; } }
2. Dataset reference
using ; using ; using ;
The npoi plugin needs to be downloaded by yourself.
3. Define the method to obtain excel image data GetDTWithImg
/// <summary> /// Get image data in excel /// </summary> /// <param name="path">File path</param> /// <returns>list</returns> private List<PictureData> GetDTWithImg(string path) { using (FileStream file = new FileStream(path, , )) { IWorkbook workbook = null; ISheet sheet = null; workbook = (file); sheet = ("Sheet1"); if (sheet == null) { sheet = (0); } // Get the drawing object XSSFDrawing drawing = (XSSFDrawing)(); List<XSSFPicture> picturesInColumnA = new List<XSSFPicture>(); List<XSSFShape> shapes = (); foreach (XSSFShape shape in shapes) { if (shape is XSSFPicture) { XSSFPicture picture = (XSSFPicture)shape; XSSFClientAnchor anchor = (XSSFClientAnchor)(); (picture); } } List<PictureData> pictureDataList = new List<PictureData>(); //Put the image data into the collection foreach (XSSFPicture picture in picturesInColumnA) { byte[] pictureData = ; PictureData data = new PictureData { Data = pictureData }; (data); } return pictureDataList; } }
Summarize
Through this method, you can obtain the pictures in Excel, convert them into byte streams and save them into a collection, so as to facilitate subsequent operations.
This is the article about .NET using NPOI to read excel data with pictures. For more related .NET NPOI to read excel data with pictures, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!