最近做一个EXCEL 导入的功能,导入一些人员的基本信息,其中一项是人员的照片,经查资料发现在EXCEL中照片和单元格之间并无对应的关系,即使照片在某个单元格内,所以在读取的时候照片那一列读出来的全是空,经研究查找后找到了一种解决的方式,通过计算得出照片在EXCEL 中的单元格,大概过程如下:
一、首先引用NPOI相关的dll
二、在程序中添加NPOI相关的命名空间
三、定义照片信息类
public class PicturesInfo
{
public int MinRow { get; set; }
public int MaxRow { get; set; }
public int MinCol { get; set; }
public int MaxCol { get; set; }
public Byte[] PictureData { get; private set; }
public PicturesInfo(int minRow, int maxRow, int minCol, int maxCol, Byte[] pictureData)
{
this.MinRow = minRow;
this.MaxRow = maxRow;
this.MinCol = minCol;
this.MaxCol = maxCol;
this.PictureData = pictureData;
}
}
四、计算照片的位置类
public static class NpoiExtend
{
public static List<PicturesInfo> GetAllPictureInfos(this ISheet sheet)
{
return sheet.GetAllPictureInfos(null, null, null, null);
}
public static List<PicturesInfo> GetAllPictureInfos(this ISheet sheet, int?